1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.uml.diagram.activity.ui; |
40 | |
|
41 | |
import java.awt.Color; |
42 | |
import java.awt.Dimension; |
43 | |
import java.awt.Rectangle; |
44 | |
import java.beans.PropertyChangeEvent; |
45 | |
import java.util.HashSet; |
46 | |
import java.util.Iterator; |
47 | |
import java.util.Set; |
48 | |
|
49 | |
import org.argouml.model.AssociationChangeEvent; |
50 | |
import org.argouml.model.AttributeChangeEvent; |
51 | |
import org.argouml.model.Model; |
52 | |
import org.argouml.uml.diagram.DiagramSettings; |
53 | |
import org.argouml.uml.diagram.state.ui.FigStateVertex; |
54 | |
import org.tigris.gef.presentation.Fig; |
55 | |
import org.tigris.gef.presentation.FigLine; |
56 | |
import org.tigris.gef.presentation.FigRRect; |
57 | |
import org.tigris.gef.presentation.FigText; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public class FigSubactivityState extends FigStateVertex { |
66 | |
|
67 | |
private static final int PADDING = 8; |
68 | |
|
69 | |
private static final int X = X0; |
70 | |
private static final int Y = Y0; |
71 | |
private static final int W = 90; |
72 | |
private static final int H = 25; |
73 | |
|
74 | |
private static final int SX = 3; |
75 | |
private static final int SY = 3; |
76 | |
private static final int SW = 9; |
77 | |
private static final int SH = 5; |
78 | |
|
79 | |
|
80 | |
private FigRRect cover; |
81 | |
|
82 | |
private FigRRect s1; |
83 | |
private FigRRect s2; |
84 | |
private FigLine s3; |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public FigSubactivityState(Object owner, Rectangle bounds, |
95 | |
DiagramSettings settings) { |
96 | 0 | super(owner, bounds, settings); |
97 | 0 | initFigs(); |
98 | 0 | } |
99 | |
|
100 | |
@Override |
101 | |
protected Fig createBigPortFig() { |
102 | 0 | FigRRect frr = new FigRRect(X, Y, W, H, DEBUG_COLOR, DEBUG_COLOR); |
103 | 0 | frr.setCornerRadius(frr.getHeight() / 2); |
104 | 0 | frr.setLineWidth(0); |
105 | 0 | return frr; |
106 | |
} |
107 | |
|
108 | |
private void initFigs() { |
109 | 0 | cover = new FigRRect(X, Y, W, H, LINE_COLOR, FILL_COLOR); |
110 | 0 | cover.setCornerRadius(getHeight() / 2); |
111 | |
|
112 | 0 | getNameFig().setLineWidth(0); |
113 | 0 | getNameFig().setBounds(10 + PADDING, 10, 90 - PADDING * 2, 25); |
114 | 0 | getNameFig().setFilled(false); |
115 | 0 | getNameFig().setReturnAction(FigText.INSERT); |
116 | 0 | getNameFig().setEditable(false); |
117 | |
|
118 | |
|
119 | 0 | addFig(getBigPort()); |
120 | 0 | addFig(cover); |
121 | 0 | addFig(getNameFig()); |
122 | |
|
123 | 0 | makeSubStatesIcon(X + W, Y); |
124 | |
|
125 | 0 | setBounds(getBounds()); |
126 | 0 | } |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
private void makeSubStatesIcon(int x, int y) { |
133 | 0 | s1 = new FigRRect(x - 22, y + 3, 8, 6, LINE_COLOR, FILL_COLOR); |
134 | 0 | s2 = new FigRRect(x - 11, y + 9, 8, 6, LINE_COLOR, FILL_COLOR); |
135 | 0 | s1.setFilled(true); |
136 | 0 | s2.setFilled(true); |
137 | 0 | s1.setLineWidth(LINE_WIDTH); |
138 | 0 | s2.setLineWidth(LINE_WIDTH); |
139 | 0 | s1.setCornerRadius(SH); |
140 | 0 | s2.setCornerRadius(SH); |
141 | 0 | s3 = new FigLine(x - 18, y + 6, x - 7, y + 12, LINE_COLOR); |
142 | |
|
143 | 0 | addFig(s3); |
144 | 0 | addFig(s1); |
145 | 0 | addFig(s2); |
146 | 0 | } |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
@Override |
152 | |
public Object clone() { |
153 | 0 | FigSubactivityState figClone = (FigSubactivityState) super.clone(); |
154 | 0 | Iterator it = figClone.getFigs().iterator(); |
155 | 0 | figClone.setBigPort((FigRRect) it.next()); |
156 | 0 | figClone.cover = (FigRRect) it.next(); |
157 | 0 | figClone.setNameFig((FigText) it.next()); |
158 | 0 | return figClone; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
@Override |
166 | |
public Dimension getMinimumSize() { |
167 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
168 | 0 | int w = nameDim.width + PADDING * 2; |
169 | 0 | int h = nameDim.height + PADDING; |
170 | 0 | return new Dimension(Math.max(w, W / 2), Math.max(h, H / 2)); |
171 | |
} |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
@Override |
179 | |
protected void setStandardBounds(int x, int y, int w, int h) { |
180 | 0 | if (getNameFig() == null) { |
181 | 0 | return; |
182 | |
} |
183 | 0 | Rectangle oldBounds = getBounds(); |
184 | |
|
185 | 0 | getNameFig().setBounds(x + PADDING, y, w - PADDING * 2, h - PADDING); |
186 | 0 | getBigPort().setBounds(x, y, w, h); |
187 | 0 | cover.setBounds(x, y, w, h); |
188 | 0 | ((FigRRect) getBigPort()).setCornerRadius(h); |
189 | 0 | cover.setCornerRadius(h); |
190 | |
|
191 | 0 | s1.setBounds(x + w - 2 * (SX + SW), y + h - 1 * (SY + SH), SW, SH); |
192 | 0 | s2.setBounds(x + w - 1 * (SX + SW), y + h - 2 * (SY + SH), SW, SH); |
193 | 0 | s3.setShape(x + w - (SX * 2 + SW + SW / 2), y + h - (SY + SH / 2), |
194 | |
x + w - (SX + SW / 2), y + h - (SY * 2 + SH + SH / 2)); |
195 | |
|
196 | 0 | calcBounds(); |
197 | 0 | updateEdges(); |
198 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
199 | 0 | } |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
@Override |
205 | |
public void setLineColor(Color col) { |
206 | 0 | cover.setLineColor(col); |
207 | 0 | } |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
public Color getLineColor() { |
213 | 0 | return cover.getLineColor(); |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
public void setFillColor(Color col) { |
220 | 0 | cover.setFillColor(col); |
221 | 0 | } |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public Color getFillColor() { |
227 | 0 | return cover.getFillColor(); |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
@Override |
234 | |
public void setFilled(boolean f) { |
235 | 0 | cover.setFilled(f); |
236 | 0 | } |
237 | |
|
238 | |
@Override |
239 | |
public boolean isFilled() { |
240 | 0 | return cover.isFilled(); |
241 | |
} |
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
@Override |
247 | |
public void setLineWidth(int w) { |
248 | 0 | cover.setLineWidth(w); |
249 | 0 | } |
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
@Override |
255 | |
public int getLineWidth() { |
256 | 0 | return cover.getLineWidth(); |
257 | |
} |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
@Override |
263 | |
protected void modelChanged(PropertyChangeEvent mee) { |
264 | |
|
265 | 0 | super.modelChanged(mee); |
266 | 0 | if (mee instanceof AssociationChangeEvent |
267 | |
|| mee instanceof AttributeChangeEvent) { |
268 | |
|
269 | |
|
270 | |
|
271 | 0 | if (!Model.getFacade().isATransition(mee.getNewValue())) { |
272 | 0 | renderingChanged(); |
273 | 0 | updateListeners(getOwner(), getOwner()); |
274 | |
} |
275 | |
} |
276 | 0 | } |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
@Override |
282 | |
protected void updateListeners(Object oldOwner, Object newOwner) { |
283 | 0 | Set<Object[]> l = new HashSet<Object[]>(); |
284 | 0 | if (newOwner != null) { |
285 | |
|
286 | 0 | l.add(new Object[] {newOwner, null}); |
287 | |
|
288 | 0 | Object machine = Model.getFacade().getSubmachine(newOwner); |
289 | 0 | if (machine != null) { |
290 | 0 | l.add(new Object[] {machine, null}); |
291 | |
} |
292 | |
} |
293 | 0 | updateElementListeners(l); |
294 | 0 | } |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
@Override |
300 | |
protected void updateNameText() { |
301 | 0 | String s = ""; |
302 | 0 | if (getOwner() != null) { |
303 | 0 | Object machine = Model.getFacade().getSubmachine(getOwner()); |
304 | 0 | if (machine != null) { |
305 | 0 | s = Model.getFacade().getName(machine); |
306 | |
} |
307 | |
} |
308 | 0 | if (s == null) { |
309 | 0 | s = ""; |
310 | |
} |
311 | 0 | getNameFig().setText(s); |
312 | 0 | } |
313 | |
|
314 | |
} |