Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigExtend |
|
| 1.7272727272727273;1.727 |
1 | /* $Id: FigExtend.java 17867 2010-01-12 20:47:04Z 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 | * mvw | |
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.use_case.ui; | |
40 | ||
41 | import java.awt.Graphics; | |
42 | import java.awt.Rectangle; | |
43 | import java.beans.PropertyChangeEvent; | |
44 | import java.util.HashSet; | |
45 | import java.util.Set; | |
46 | ||
47 | import org.argouml.model.Model; | |
48 | import org.argouml.notation.providers.uml.NotationUtilityUml; | |
49 | import org.argouml.uml.diagram.DiagramSettings; | |
50 | import org.argouml.uml.diagram.ui.ArgoFigText; | |
51 | import org.argouml.uml.diagram.ui.FigEdgeModelElement; | |
52 | import org.argouml.uml.diagram.ui.FigTextGroup; | |
53 | import org.argouml.uml.diagram.ui.PathItemPlacement; | |
54 | import org.tigris.gef.presentation.ArrowHeadGreater; | |
55 | import org.tigris.gef.presentation.Fig; | |
56 | ||
57 | /** | |
58 | * A fig for use with extend relationships on use case diagrams.<p> | |
59 | * | |
60 | * Realised as a dotted line with an open arrow head and the label | |
61 | * «extend» together with any condition alongside.<p> | |
62 | * | |
63 | * @author mail@jeremybennett.com | |
64 | */ | |
65 | public class FigExtend extends FigEdgeModelElement { | |
66 | ||
67 | private static final int DEFAULT_WIDTH = 90; | |
68 | ||
69 | /** | |
70 | * Serialization ID - generated by Eclipse for rev. 1.22 | |
71 | */ | |
72 | private static final long serialVersionUID = -8026008987096598742L; | |
73 | ||
74 | /** | |
75 | * The «extend» label.<p> | |
76 | */ | |
77 | private ArgoFigText label; | |
78 | ||
79 | /** | |
80 | * The condition expression.<p> | |
81 | */ | |
82 | private ArgoFigText condition; | |
83 | ||
84 | /** | |
85 | * The group of label and condition.<p> | |
86 | */ | |
87 | private FigTextGroup fg; | |
88 | ||
89 | ||
90 | 0 | private ArrowHeadGreater endArrow = new ArrowHeadGreater(); |
91 | ||
92 | private void initialize(Object owner) { | |
93 | // The <<extend>> label. | |
94 | // It's not a true stereotype, so don't use the stereotype support | |
95 | //int y = getNameFig().getBounds().height; | |
96 | 0 | int y = Y0 + STEREOHEIGHT; |
97 | 0 | label = new ArgoFigText(owner, |
98 | new Rectangle(X0, y, DEFAULT_WIDTH, STEREOHEIGHT), | |
99 | getSettings(), false); | |
100 | 0 | y = y + STEREOHEIGHT; |
101 | 0 | label.setFilled(false); |
102 | 0 | label.setLineWidth(0); |
103 | 0 | label.setEditable(false); |
104 | 0 | label.setText(getLabel()); |
105 | 0 | label.calcBounds(); |
106 | ||
107 | // Set up FigText to hold the condition. | |
108 | 0 | condition = new ArgoFigText(owner, |
109 | new Rectangle(X0, y, DEFAULT_WIDTH, STEREOHEIGHT), | |
110 | getSettings(), false); | |
111 | 0 | y = y + STEREOHEIGHT; |
112 | 0 | condition.setFilled(false); |
113 | 0 | condition.setLineWidth(0); |
114 | ||
115 | // Join all into a group | |
116 | ||
117 | 0 | fg = new FigTextGroup(owner, getSettings()); |
118 | ||
119 | // UML spec for Extend doesn't call for name nor stereotype | |
120 | 0 | fg.addFig(label); |
121 | 0 | fg.addFig(condition); |
122 | 0 | fg.calcBounds(); |
123 | ||
124 | // Place in the middle of the line and ensure the line is dashed. Add | |
125 | // an arrow with an open arrow head. Remember that for an extends | |
126 | // relationship, the arrow points to the base use case, but because of | |
127 | // the way we draw it, that is still the destination end. | |
128 | ||
129 | 0 | addPathItem(fg, new PathItemPlacement(this, fg, 50, 10)); |
130 | ||
131 | 0 | setDashed(true); |
132 | ||
133 | 0 | setDestArrowHead(endArrow); |
134 | ||
135 | // Make the edge go between nearest points | |
136 | ||
137 | 0 | setBetweenNearestPoints(true); |
138 | 0 | } |
139 | ||
140 | /** | |
141 | * Construct an Extend fig. | |
142 | * | |
143 | * @param owner uml element | |
144 | * @param settings rendering settings | |
145 | */ | |
146 | public FigExtend(Object owner, DiagramSettings settings) { | |
147 | 0 | super(owner, settings); |
148 | 0 | initialize(owner); |
149 | 0 | } |
150 | ||
151 | /** | |
152 | * Set a new fig to represent this edge.<p> | |
153 | * | |
154 | * We invoke the superclass accessor. Then change aspects of the | |
155 | * new fig that are not as we want. In this case to use dashed | |
156 | * lines.<p> | |
157 | * | |
158 | * @param f The fig to use. | |
159 | */ | |
160 | @Override | |
161 | public void setFig(Fig f) { | |
162 | 0 | super.setFig(f); |
163 | ||
164 | // Make sure the line is dashed | |
165 | ||
166 | 0 | setDashed(true); |
167 | 0 | } |
168 | ||
169 | /** | |
170 | * Define whether the given fig can be edited (it can't).<p> | |
171 | * | |
172 | * @param f The fig about which the enquiry is being made. Ignored in this | |
173 | * implementation. | |
174 | * | |
175 | * @return <code>false</code> under all circumstances. | |
176 | */ | |
177 | @Override | |
178 | protected boolean canEdit(Fig f) { | |
179 | 0 | return false; |
180 | } | |
181 | ||
182 | /* | |
183 | * @see org.tigris.gef.presentation.Fig#paint(java.awt.Graphics) | |
184 | */ | |
185 | @Override | |
186 | public void paint(Graphics g) { | |
187 | 0 | endArrow.setLineColor(getLineColor()); |
188 | 0 | super.paint(g); |
189 | 0 | } |
190 | ||
191 | /* | |
192 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#updateListeners(java.lang.Object, java.lang.Object) | |
193 | */ | |
194 | @Override | |
195 | protected void updateListeners(Object oldOwner, Object newOwner) { | |
196 | 0 | Set<Object[]> listeners = new HashSet<Object[]>(); |
197 | 0 | if (newOwner != null) { |
198 | 0 | listeners.add( |
199 | new Object[] {newOwner, | |
200 | new String[] {"condition", "remove"} | |
201 | }); | |
202 | } | |
203 | 0 | updateElementListeners(listeners); |
204 | 0 | } |
205 | ||
206 | ||
207 | /* | |
208 | * The only thing we need to deal with is updating is the condition text. | |
209 | * | |
210 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#modelChanged(java.beans.PropertyChangeEvent) | |
211 | */ | |
212 | @Override | |
213 | protected void modelChanged(PropertyChangeEvent e) { | |
214 | 0 | Object extend = getOwner(); |
215 | 0 | if (extend == null) { |
216 | 0 | return; |
217 | } | |
218 | 0 | super.modelChanged(e); |
219 | ||
220 | 0 | if ("condition".equals(e.getPropertyName())) { |
221 | 0 | renderingChanged(); |
222 | } | |
223 | 0 | } |
224 | ||
225 | @Override | |
226 | public void renderingChanged() { | |
227 | 0 | super.renderingChanged(); |
228 | 0 | updateConditionText(); |
229 | 0 | updateLabel(); |
230 | 0 | } |
231 | ||
232 | /** | |
233 | * Now sort out the condition text. Use the null string if there is | |
234 | * no condition set. The condition is a BooleanExpression, | |
235 | * so we show the "body" of it, and ignore the "language". | |
236 | */ | |
237 | protected void updateConditionText() { | |
238 | 0 | if (getOwner() == null) { |
239 | 0 | return; |
240 | } | |
241 | ||
242 | 0 | Object c = Model.getFacade().getCondition(getOwner()); |
243 | 0 | if (c == null) { |
244 | 0 | condition.setText(""); |
245 | } else { | |
246 | 0 | Object expr = Model.getFacade().getBody(c); |
247 | 0 | if (expr == null) { |
248 | 0 | condition.setText(""); |
249 | } else { | |
250 | 0 | condition.setText((String) expr); |
251 | } | |
252 | } | |
253 | // Let the group recalculate its bounds and then tell GEF we've | |
254 | // finished. | |
255 | 0 | fg.calcBounds(); |
256 | 0 | endTrans(); |
257 | 0 | } |
258 | ||
259 | protected void updateLabel() { | |
260 | 0 | label.setText(getLabel()); |
261 | 0 | } |
262 | ||
263 | private String getLabel() { | |
264 | 0 | return NotationUtilityUml.formatStereotype( |
265 | "extend", | |
266 | getNotationSettings().isUseGuillemets()); | |
267 | } | |
268 | ||
269 | } |