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 | |
|
40 | |
package org.argouml.uml.diagram.deployment.ui; |
41 | |
|
42 | |
import java.awt.Color; |
43 | |
import java.awt.Dimension; |
44 | |
import java.awt.Point; |
45 | |
import java.awt.Rectangle; |
46 | |
import java.awt.event.MouseEvent; |
47 | |
import java.beans.PropertyChangeEvent; |
48 | |
import java.util.ArrayList; |
49 | |
import java.util.Collection; |
50 | |
import java.util.HashSet; |
51 | |
import java.util.Iterator; |
52 | |
import java.util.Set; |
53 | |
|
54 | |
import org.argouml.model.AssociationChangeEvent; |
55 | |
import org.argouml.model.AttributeChangeEvent; |
56 | |
import org.argouml.model.Model; |
57 | |
import org.argouml.uml.diagram.DiagramSettings; |
58 | |
import org.argouml.uml.diagram.ui.FigEdgeModelElement; |
59 | |
import org.argouml.uml.diagram.ui.FigNodeModelElement; |
60 | |
import org.tigris.gef.base.Geometry; |
61 | |
import org.tigris.gef.base.Selection; |
62 | |
import org.tigris.gef.presentation.Fig; |
63 | |
import org.tigris.gef.presentation.FigCube; |
64 | |
import org.tigris.gef.presentation.FigRect; |
65 | |
import org.tigris.gef.presentation.FigText; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public abstract class AbstractFigNode extends FigNodeModelElement { |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
protected static final int DEPTH = 20; |
83 | |
private FigCube cover; |
84 | |
private static final int DEFAULT_X = 10; |
85 | |
private static final int DEFAULT_Y = 10; |
86 | |
private static final int DEFAULT_WIDTH = 200; |
87 | |
private static final int DEFAULT_HEIGHT = 180; |
88 | |
|
89 | |
@Override |
90 | |
protected Fig createBigPortFig() { |
91 | 0 | Fig cpfr = new CubePortFigRect(DEFAULT_X, DEFAULT_Y - DEPTH, |
92 | |
DEFAULT_WIDTH + DEPTH, |
93 | |
DEFAULT_HEIGHT + DEPTH, DEPTH); |
94 | 0 | cpfr.setFilled(false); |
95 | 0 | cpfr.setLineWidth(0); |
96 | 0 | return cpfr; |
97 | |
} |
98 | |
|
99 | |
private void initFigs() { |
100 | 0 | cover = new FigCube(DEFAULT_X, DEFAULT_Y, DEFAULT_WIDTH, |
101 | |
DEFAULT_HEIGHT, LINE_COLOR, FILL_COLOR); |
102 | |
|
103 | 0 | getNameFig().setLineWidth(0); |
104 | 0 | getNameFig().setFilled(false); |
105 | 0 | getNameFig().setJustification(0); |
106 | |
|
107 | 0 | addFig(getBigPort()); |
108 | 0 | addFig(cover); |
109 | 0 | addFig(getStereotypeFig()); |
110 | 0 | addFig(getNameFig()); |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public AbstractFigNode(Object owner, Rectangle bounds, |
121 | |
DiagramSettings settings) { |
122 | 0 | super(owner, bounds, settings); |
123 | 0 | initFigs(); |
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public Object clone() { |
128 | 0 | AbstractFigNode figClone = (AbstractFigNode) super.clone(); |
129 | 0 | Iterator it = figClone.getFigs().iterator(); |
130 | 0 | figClone.setBigPort((FigRect) it.next()); |
131 | 0 | figClone.cover = (FigCube) it.next(); |
132 | 0 | it.next(); |
133 | 0 | figClone.setNameFig((FigText) it.next()); |
134 | 0 | return figClone; |
135 | |
} |
136 | |
|
137 | |
@Override |
138 | |
public void setLineColor(Color c) { |
139 | 0 | cover.setLineColor(c); |
140 | 0 | } |
141 | |
|
142 | |
@Override |
143 | |
public void setLineWidth(int w) { |
144 | 0 | cover.setLineWidth(w); |
145 | 0 | } |
146 | |
|
147 | |
|
148 | |
@Override |
149 | |
public boolean isFilled() { |
150 | 0 | return cover.isFilled(); |
151 | |
} |
152 | |
|
153 | |
@Override |
154 | |
public void setFilled(boolean f) { |
155 | 0 | cover.setFilled(f); |
156 | 0 | } |
157 | |
|
158 | |
@Override |
159 | |
public Selection makeSelection() { |
160 | 0 | return new SelectionNode(this); |
161 | |
} |
162 | |
|
163 | |
@Override |
164 | |
public Dimension getMinimumSize() { |
165 | 0 | Dimension stereoDim = getStereotypeFig().getMinimumSize(); |
166 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
167 | |
|
168 | 0 | int w = Math.max(stereoDim.width, nameDim.width + 1) + DEPTH; |
169 | 0 | int h = stereoDim.height + nameDim.height + DEPTH; |
170 | |
|
171 | 0 | w = Math.max(3 * DEPTH, w); |
172 | 0 | h = Math.max(3 * DEPTH, h); |
173 | 0 | return new Dimension(w, h); |
174 | |
} |
175 | |
|
176 | |
@Override |
177 | |
protected void setStandardBounds(int x, int y, int w, int h) { |
178 | 0 | if (getNameFig() == null) { |
179 | 0 | return; |
180 | |
} |
181 | 0 | Rectangle oldBounds = getBounds(); |
182 | 0 | getBigPort().setBounds(x, y, w, h); |
183 | 0 | cover.setBounds(x, y + DEPTH, w - DEPTH, h - DEPTH); |
184 | |
|
185 | 0 | Dimension stereoDim = getStereotypeFig().getMinimumSize(); |
186 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
187 | 0 | getNameFig().setBounds( |
188 | |
x + 4, y + DEPTH + stereoDim.height + 1, |
189 | |
w - DEPTH - 8, nameDim.height); |
190 | 0 | getStereotypeFig().setBounds(x + 1, y + DEPTH + 1, |
191 | |
w - DEPTH - 2, stereoDim.height); |
192 | 0 | _x = x; |
193 | 0 | _y = y; |
194 | 0 | _w = w; |
195 | 0 | _h = h; |
196 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
197 | 0 | updateEdges(); |
198 | 0 | } |
199 | |
|
200 | |
@Override |
201 | |
public void mouseClicked(MouseEvent me) { |
202 | 0 | super.mouseClicked(me); |
203 | 0 | setLineColor(LINE_COLOR); |
204 | 0 | } |
205 | |
|
206 | |
@Override |
207 | |
public void setEnclosingFig(Fig encloser) { |
208 | 0 | if (encloser == null |
209 | |
|| (encloser != null |
210 | |
&& Model.getFacade().isANode(encloser.getOwner()))) { |
211 | 0 | super.setEnclosingFig(encloser); |
212 | |
} |
213 | |
|
214 | 0 | if (getLayer() != null) { |
215 | |
|
216 | 0 | Collection contents = getLayer().getContents(); |
217 | 0 | Collection<FigEdgeModelElement> bringToFrontList = |
218 | |
new ArrayList<FigEdgeModelElement>(); |
219 | 0 | for (Object o : contents) { |
220 | 0 | if (o instanceof FigEdgeModelElement) { |
221 | 0 | bringToFrontList.add((FigEdgeModelElement) o); |
222 | |
} |
223 | |
} |
224 | 0 | for (FigEdgeModelElement figEdge : bringToFrontList) { |
225 | 0 | figEdge.getLayer().bringToFront(figEdge); |
226 | |
} |
227 | |
} |
228 | 0 | } |
229 | |
|
230 | |
@Override |
231 | |
public boolean getUseTrapRect() { |
232 | 0 | return true; |
233 | |
} |
234 | |
|
235 | |
@Override |
236 | |
protected void modelChanged(PropertyChangeEvent mee) { |
237 | 0 | super.modelChanged(mee); |
238 | 0 | if (mee instanceof AssociationChangeEvent |
239 | |
|| mee instanceof AttributeChangeEvent) { |
240 | 0 | renderingChanged(); |
241 | 0 | updateListeners(getOwner(), getOwner()); |
242 | 0 | damage(); |
243 | |
} |
244 | 0 | } |
245 | |
|
246 | |
@Override |
247 | |
protected void updateListeners(Object oldOwner, Object newOwner) { |
248 | 0 | Set<Object[]> l = new HashSet<Object[]>(); |
249 | 0 | if (newOwner != null) { |
250 | |
|
251 | 0 | l.add(new Object[] {newOwner, null}); |
252 | |
|
253 | 0 | Collection c = Model.getFacade().getStereotypes(newOwner); |
254 | 0 | Iterator i = c.iterator(); |
255 | 0 | while (i.hasNext()) { |
256 | 0 | Object st = i.next(); |
257 | 0 | l.add(new Object[] {st, "name"}); |
258 | 0 | } |
259 | |
} |
260 | 0 | updateElementListeners(l); |
261 | 0 | } |
262 | |
|
263 | |
@Override |
264 | |
public Point getClosestPoint(Point anotherPt) { |
265 | 0 | Rectangle r = getBounds(); |
266 | 0 | int[] xs = { |
267 | |
r.x, |
268 | |
r.x + DEPTH, |
269 | |
r.x + r.width, |
270 | |
r.x + r.width, |
271 | |
r.x + r.width - DEPTH, |
272 | |
r.x, |
273 | |
r.x, |
274 | |
}; |
275 | 0 | int[] ys = { |
276 | |
r.y + DEPTH, |
277 | |
r.y, |
278 | |
r.y, |
279 | |
r.y + r.height - DEPTH, |
280 | |
r.y + r.height, |
281 | |
r.y + r.height, |
282 | |
r.y + DEPTH, |
283 | |
}; |
284 | 0 | Point p = Geometry.ptClosestTo(xs, ys, 7, anotherPt); |
285 | 0 | return p; |
286 | |
} |
287 | |
|
288 | |
} |