Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigStereotypeDeclaration |
|
| 2.0;2 |
1 | /* $Id: FigStereotypeDeclaration.java 17735 2010-01-04 14:49:32Z bobtarling $ | |
2 | ******************************************************************************* | |
3 | * Copyright (c) 2010 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Tom Morris | |
11 | * Bob Tarling | |
12 | ******************************************************************************* | |
13 | * | |
14 | * Some portions of this file was previously release using the BSD License: | |
15 | */ | |
16 | ||
17 | // $Id: FigStereotypeDeclaration.java 17735 2010-01-04 14:49:32Z bobtarling $ | |
18 | // Copyright (c) 1996-2009 The Regents of the University of California. All | |
19 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
20 | // software and its documentation without fee, and without a written | |
21 | // agreement is hereby granted, provided that the above copyright notice | |
22 | // and this paragraph appear in all copies. This software program and | |
23 | // documentation are copyrighted by The Regents of the University of | |
24 | // California. The software program and documentation are supplied "AS | |
25 | // IS", without any accompanying services from The Regents. The Regents | |
26 | // does not warrant that the operation of the program will be | |
27 | // uninterrupted or error-free. The end-user understands that the program | |
28 | // was developed for research purposes and is advised not to rely | |
29 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
30 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
31 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
32 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
33 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
34 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
35 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
36 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
37 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
38 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
39 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
40 | ||
41 | package org.argouml.uml.diagram.static_structure.ui; | |
42 | ||
43 | import java.awt.Rectangle; | |
44 | import java.awt.event.MouseEvent; | |
45 | import java.util.HashSet; | |
46 | import java.util.Set; | |
47 | import java.util.Vector; | |
48 | ||
49 | import javax.swing.Action; | |
50 | ||
51 | import org.argouml.model.Model; | |
52 | import org.argouml.ui.ArgoJMenu; | |
53 | import org.argouml.uml.diagram.DiagramSettings; | |
54 | import org.argouml.uml.diagram.ui.ActionAddNote; | |
55 | import org.argouml.uml.diagram.ui.ActionCompartmentDisplay; | |
56 | import org.argouml.uml.diagram.ui.ActionEdgesDisplay; | |
57 | import org.argouml.uml.diagram.ui.CompartmentFigText; | |
58 | import org.argouml.uml.diagram.ui.FigCompartmentBox; | |
59 | import org.argouml.uml.ui.foundation.extension_mechanisms.ActionNewTagDefinition; | |
60 | import org.tigris.gef.base.Selection; | |
61 | ||
62 | /** | |
63 | * Class to display a Stereotype declaration figure using | |
64 | * Classifier box notation.<p> | |
65 | * | |
66 | * TODO: This is just a place-holder right now! - tfm | |
67 | * This needs to show tags and constraints. | |
68 | */ | |
69 | public class FigStereotypeDeclaration extends FigCompartmentBox { | |
70 | ||
71 | private void constructFigs(Rectangle bounds) { | |
72 | // Put all the bits together, suppressing bounds calculations until | |
73 | // we're all done for efficiency. | |
74 | 0 | enableSizeChecking(false); |
75 | 0 | setSuppressCalcBounds(true); |
76 | ||
77 | 0 | getStereotypeFig().setKeyword("stereotype"); |
78 | 0 | getStereotypeFig().setVisible(true); |
79 | /* The next line is needed so that we have the right dimension | |
80 | * when drawing this Fig on the diagram by pressing down | |
81 | * the mouse button, even before releasing the mouse button: */ | |
82 | 0 | getNameFig().setTopMargin( |
83 | getStereotypeFig().getMinimumSize().height); | |
84 | ||
85 | 0 | addFig(getBigPort()); |
86 | 0 | addFig(getNameFig()); |
87 | // stereotype fig covers the name fig: | |
88 | 0 | addFig(getStereotypeFig()); |
89 | ||
90 | // TODO: Need named Tags and Constraints compartments here | |
91 | // addFig(tagsFig); | |
92 | // addFig(constraintsFig); | |
93 | ||
94 | // Make all the parts match the main fig | |
95 | 0 | setFilled(true); |
96 | 0 | setFillColor(FILL_COLOR); |
97 | 0 | setLineColor(LINE_COLOR); |
98 | 0 | setLineWidth(LINE_WIDTH); |
99 | ||
100 | /* Set the drop location in the case of D&D: */ | |
101 | 0 | if (bounds != null) { |
102 | 0 | setLocation(bounds.x, bounds.y); |
103 | } | |
104 | ||
105 | 0 | setSuppressCalcBounds(false); |
106 | 0 | setBounds(getBounds()); |
107 | 0 | } |
108 | ||
109 | /** | |
110 | * Construct a Fig for a Stereotype on a diagram. | |
111 | * | |
112 | * @param owner owning stereotype | |
113 | * @param bounds position and size | |
114 | * @param settings render settings | |
115 | */ | |
116 | public FigStereotypeDeclaration(Object owner, Rectangle bounds, | |
117 | DiagramSettings settings) { | |
118 | 0 | super(owner, bounds, settings); |
119 | 0 | constructFigs(bounds); |
120 | 0 | enableSizeChecking(true); |
121 | 0 | } |
122 | ||
123 | @Override | |
124 | public Selection makeSelection() { | |
125 | 0 | return new SelectionStereotype(this); |
126 | } | |
127 | ||
128 | /** | |
129 | * Build a collection of menu items relevant for a right-click | |
130 | * pop-up menu on a Stereotype. | |
131 | * {@inheritDoc} | |
132 | */ | |
133 | @Override | |
134 | public Vector getPopUpActions(MouseEvent me) { | |
135 | 0 | Vector popUpActions = super.getPopUpActions(me); |
136 | ||
137 | // Add... | |
138 | 0 | ArgoJMenu addMenu = new ArgoJMenu("menu.popup.add"); |
139 | // TODO: Add Tags & Constraints | |
140 | // addMenu.add(TargetManager.getInstance().getAddAttributeAction()); | |
141 | // addMenu.add(TargetManager.getInstance().getAddOperationAction()); | |
142 | 0 | addMenu.add(new ActionAddNote()); |
143 | 0 | addMenu.add(new ActionNewTagDefinition()); |
144 | 0 | addMenu.add(ActionEdgesDisplay.getShowEdges()); |
145 | 0 | addMenu.add(ActionEdgesDisplay.getHideEdges()); |
146 | 0 | popUpActions.add(popUpActions.size() - getPopupAddOffset(), addMenu); |
147 | ||
148 | // Show ... | |
149 | 0 | ArgoJMenu showMenu = new ArgoJMenu("menu.popup.show"); |
150 | 0 | for (Action action : ActionCompartmentDisplay.getActions()) { |
151 | 0 | showMenu.add(action); |
152 | } | |
153 | 0 | if (showMenu.getComponentCount() > 0) { |
154 | 0 | popUpActions.add(popUpActions.size() - getPopupAddOffset(), |
155 | showMenu); | |
156 | } | |
157 | ||
158 | // Modifiers ... | |
159 | 0 | popUpActions.add(popUpActions.size() - getPopupAddOffset(), |
160 | buildModifierPopUp(ABSTRACT | LEAF | ROOT)); | |
161 | ||
162 | // Visibility ... | |
163 | 0 | popUpActions.add(popUpActions.size() - getPopupAddOffset(), |
164 | buildVisibilityPopUp()); | |
165 | ||
166 | 0 | return popUpActions; |
167 | } | |
168 | ||
169 | @Override | |
170 | protected CompartmentFigText unhighlight() { | |
171 | 0 | CompartmentFigText fc = super.unhighlight(); |
172 | 0 | if (fc == null) { |
173 | // TODO: Try unhighlighting our child compartments | |
174 | // fc = unhighlight(getAttributesFig()); | |
175 | } | |
176 | 0 | return fc; |
177 | } | |
178 | ||
179 | @Override | |
180 | protected void updateListeners(Object oldOwner, Object newOwner) { | |
181 | ||
182 | 0 | Set<Object[]> listeners = new HashSet<Object[]>(); |
183 | 0 | if (newOwner != null) { |
184 | 0 | listeners.add(new Object[] {newOwner, null}); |
185 | // register for tagDefinitions: | |
186 | 0 | for (Object td : Model.getFacade().getTagDefinitions(newOwner)) { |
187 | 0 | listeners.add(new Object[] {td, |
188 | new String[] {"name", "tagType", "multiplicity"}}); | |
189 | } | |
190 | /* TODO: constraints, ... */ | |
191 | } | |
192 | 0 | updateElementListeners(listeners); |
193 | 0 | } |
194 | } |