Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigEnumeration |
|
| 1.6923076923076923;1.692 |
1 | /* $Id: FigEnumeration.java 17864 2010-01-12 20:11:26Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 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 | * bobtarling | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2009 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.uml.diagram.static_structure.ui; | |
40 | ||
41 | import java.awt.Rectangle; | |
42 | import java.util.HashSet; | |
43 | import java.util.Set; | |
44 | ||
45 | import javax.swing.Action; | |
46 | ||
47 | import org.argouml.model.Model; | |
48 | import org.argouml.ui.ArgoJMenu; | |
49 | import org.argouml.uml.diagram.DiagramSettings; | |
50 | import org.argouml.uml.diagram.ui.EnumLiteralsCompartmentContainer; | |
51 | import org.argouml.uml.diagram.ui.FigEnumLiteralsCompartment; | |
52 | import org.argouml.uml.ui.foundation.core.ActionAddEnumerationLiteral; | |
53 | import org.tigris.gef.base.Selection; | |
54 | ||
55 | /** | |
56 | * Class to display graphics for a UML Enumeration in a diagram. | |
57 | * It depends on FigDataType for most of its behavior.<p> | |
58 | * | |
59 | * The Fig for an Enumeration has a compartment for Literals | |
60 | * above the Operations compartment. | |
61 | */ | |
62 | public class FigEnumeration extends FigDataType | |
63 | implements EnumLiteralsCompartmentContainer { | |
64 | ||
65 | /** | |
66 | * The Fig that represents the literals compartment. | |
67 | */ | |
68 | private FigEnumLiteralsCompartment literalsCompartment; | |
69 | ||
70 | /** | |
71 | * Constructor. | |
72 | * | |
73 | * @param owner owning UML element | |
74 | * @param bounds position and size | |
75 | * @param settings render settings | |
76 | */ | |
77 | public FigEnumeration(Object owner, Rectangle bounds, | |
78 | DiagramSettings settings) { | |
79 | 0 | super(owner, bounds, settings); |
80 | ||
81 | 0 | } |
82 | ||
83 | @Override | |
84 | protected String getKeyword() { | |
85 | 0 | return "enumeration"; |
86 | } | |
87 | ||
88 | @Override | |
89 | protected void addExtraCompartments() { | |
90 | // This creates the compartment. | |
91 | 0 | addFig(getLiteralsCompartment()); |
92 | 0 | setEnumLiteralsVisible(true); |
93 | 0 | literalsCompartment.populate(); |
94 | 0 | } |
95 | ||
96 | @Override | |
97 | public Selection makeSelection() { | |
98 | 0 | return new SelectionEnumeration(this); |
99 | } | |
100 | ||
101 | @Override | |
102 | public Object clone() { | |
103 | 0 | FigEnumeration clone = (FigEnumeration) super.clone(); |
104 | 0 | clone.literalsCompartment = |
105 | (FigEnumLiteralsCompartment) literalsCompartment.clone(); | |
106 | 0 | return clone; |
107 | } | |
108 | ||
109 | @Override | |
110 | public void renderingChanged() { | |
111 | 0 | super.renderingChanged(); |
112 | 0 | if (getOwner() != null) { |
113 | 0 | updateEnumLiterals(); |
114 | } | |
115 | 0 | } |
116 | ||
117 | @Override | |
118 | protected void updateListeners(Object oldOwner, Object newOwner) { | |
119 | 0 | Set<Object[]> l = new HashSet<Object[]>(); |
120 | 0 | if (newOwner != null) { |
121 | // add the listeners to the newOwner | |
122 | 0 | l.add(new Object[] {newOwner, null}); |
123 | // and its stereotypes | |
124 | 0 | for (Object stereo : Model.getFacade().getStereotypes(newOwner)) { |
125 | 0 | l.add(new Object[] {stereo, null}); |
126 | } | |
127 | // and its features | |
128 | 0 | for (Object feat : Model.getFacade().getFeatures(newOwner)) { |
129 | 0 | l.add(new Object[] {feat, null}); |
130 | // and the stereotypes of its features | |
131 | 0 | for (Object stereo : Model.getFacade().getStereotypes(feat)) { |
132 | 0 | l.add(new Object[] {stereo, null}); |
133 | } | |
134 | } | |
135 | // and its enumerationLiterals | |
136 | 0 | for (Object literal : Model.getFacade().getEnumerationLiterals( |
137 | newOwner)) { | |
138 | 0 | l.add(new Object[] {literal, null}); |
139 | } | |
140 | } | |
141 | // And now add listeners to them all: | |
142 | 0 | updateElementListeners(l); |
143 | ||
144 | 0 | } |
145 | ||
146 | /** | |
147 | * Update (i.e. redraw) the compartment with the literals. | |
148 | */ | |
149 | protected void updateEnumLiterals() { | |
150 | 0 | if (!literalsCompartment.isVisible()) { |
151 | 0 | return; |
152 | } | |
153 | 0 | literalsCompartment.populate(); |
154 | ||
155 | // TODO: make setBounds, calcBounds and updateBounds consistent | |
156 | 0 | setBounds(getBounds()); |
157 | 0 | } |
158 | ||
159 | /** | |
160 | * @return the Fig for the EnumerationLiterals compartment | |
161 | */ | |
162 | public FigEnumLiteralsCompartment getLiteralsCompartment() { | |
163 | // Set bounds will be called from our superclass constructor before | |
164 | // our constructor has run, so make sure this gets set up if needed. | |
165 | 0 | if (literalsCompartment == null) { |
166 | 0 | literalsCompartment = new FigEnumLiteralsCompartment(getOwner(), |
167 | DEFAULT_COMPARTMENT_BOUNDS, getSettings()); | |
168 | } | |
169 | 0 | return literalsCompartment; |
170 | } | |
171 | ||
172 | /** | |
173 | * @return true if the literals compartment is visible | |
174 | */ | |
175 | public boolean isEnumLiteralsVisible() { | |
176 | 0 | return literalsCompartment.isVisible(); |
177 | } | |
178 | ||
179 | /** | |
180 | * @param isVisible true will show the enumeration literal compartment | |
181 | */ | |
182 | public void setEnumLiteralsVisible(boolean isVisible) { | |
183 | 0 | setCompartmentVisible(literalsCompartment, isVisible); |
184 | 0 | } |
185 | ||
186 | /** | |
187 | * @return the bounds of the EnumerationLiterals compartment | |
188 | */ | |
189 | public Rectangle getEnumLiteralsBounds() { | |
190 | 0 | return literalsCompartment.getBounds(); |
191 | } | |
192 | ||
193 | /** | |
194 | * USED BY PGML.tee. | |
195 | * @return the class name and bounds together with compartment | |
196 | * visibility. | |
197 | */ | |
198 | @Override | |
199 | public String classNameAndBounds() { | |
200 | 0 | return super.classNameAndBounds() |
201 | + "enumerationLiteralsVisible=" + isEnumLiteralsVisible(); | |
202 | } | |
203 | } |