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.deployment.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.Collection; |
46 | |
import java.util.Iterator; |
47 | |
|
48 | |
import org.argouml.model.AssociationChangeEvent; |
49 | |
import org.argouml.model.AttributeChangeEvent; |
50 | |
import org.argouml.model.Model; |
51 | |
import org.argouml.uml.diagram.DiagramSettings; |
52 | |
import org.argouml.uml.diagram.ui.FigNodeModelElement; |
53 | |
import org.tigris.gef.presentation.FigRect; |
54 | |
import org.tigris.gef.presentation.FigText; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public abstract class AbstractFigComponent extends FigNodeModelElement { |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
private static final int BX = 10; |
72 | |
private static final int FINGER_HEIGHT = BX; |
73 | |
private static final int FINGER_WIDTH = BX * 2; |
74 | |
private static final int OVERLAP = 0; |
75 | |
private static final int DEFAULT_WIDTH = 120; |
76 | |
private static final int DEFAULT_HEIGHT = 80; |
77 | |
private FigRect cover; |
78 | |
private FigRect upperRect; |
79 | |
private FigRect lowerRect; |
80 | |
|
81 | |
private void initFigs() { |
82 | 0 | cover = new FigRect(BX, 10, DEFAULT_WIDTH, DEFAULT_HEIGHT, LINE_COLOR, |
83 | |
FILL_COLOR); |
84 | 0 | upperRect = new FigRect(0, 2 * FINGER_HEIGHT, |
85 | |
FINGER_WIDTH, FINGER_HEIGHT, |
86 | |
LINE_COLOR, FILL_COLOR); |
87 | 0 | lowerRect = new FigRect(0, 5 * FINGER_HEIGHT, |
88 | |
FINGER_WIDTH, FINGER_HEIGHT, |
89 | |
LINE_COLOR, FILL_COLOR); |
90 | |
|
91 | 0 | getNameFig().setLineWidth(0); |
92 | 0 | getNameFig().setFilled(false); |
93 | 0 | getNameFig().setText(placeString()); |
94 | |
|
95 | 0 | addFig(getBigPort()); |
96 | 0 | addFig(cover); |
97 | 0 | addFig(getStereotypeFig()); |
98 | 0 | addFig(getNameFig()); |
99 | 0 | addFig(upperRect); |
100 | 0 | addFig(lowerRect); |
101 | 0 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
public AbstractFigComponent(Object owner, Rectangle bounds, |
111 | |
DiagramSettings settings) { |
112 | 0 | super(owner, bounds, settings); |
113 | 0 | initFigs(); |
114 | 0 | } |
115 | |
|
116 | |
@Override |
117 | |
public Object clone() { |
118 | 0 | AbstractFigComponent figClone = (AbstractFigComponent) super.clone(); |
119 | 0 | Iterator it = figClone.getFigs().iterator(); |
120 | 0 | figClone.setBigPort((FigRect) it.next()); |
121 | 0 | figClone.cover = (FigRect) it.next(); |
122 | 0 | it.next(); |
123 | 0 | figClone.setNameFig((FigText) it.next()); |
124 | 0 | figClone.upperRect = (FigRect) it.next(); |
125 | 0 | figClone.lowerRect = (FigRect) it.next(); |
126 | |
|
127 | 0 | return figClone; |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
protected void modelChanged(PropertyChangeEvent mee) { |
132 | 0 | super.modelChanged(mee); |
133 | 0 | if (mee instanceof AssociationChangeEvent |
134 | |
|| mee instanceof AttributeChangeEvent) { |
135 | 0 | renderingChanged(); |
136 | 0 | updateListeners(getOwner(), getOwner()); |
137 | 0 | damage(); |
138 | |
} |
139 | 0 | } |
140 | |
|
141 | |
@Override |
142 | |
protected void updateListeners(Object oldOwner, Object newOwner) { |
143 | 0 | super.updateListeners(oldOwner, newOwner); |
144 | 0 | if (newOwner != null) { |
145 | 0 | Collection c = Model.getFacade().getStereotypes(newOwner); |
146 | 0 | Iterator i = c.iterator(); |
147 | 0 | while (i.hasNext()) { |
148 | 0 | Object st = i.next(); |
149 | 0 | addElementListener(st, "name"); |
150 | 0 | } |
151 | |
} |
152 | 0 | } |
153 | |
|
154 | |
@Override |
155 | |
public void setLineColor(Color c) { |
156 | 0 | cover.setLineColor(c); |
157 | 0 | getStereotypeFig().setFilled(false); |
158 | 0 | getStereotypeFig().setLineWidth(0); |
159 | 0 | getNameFig().setFilled(false); |
160 | 0 | getNameFig().setLineWidth(0); |
161 | 0 | upperRect.setLineColor(c); |
162 | 0 | lowerRect.setLineColor(c); |
163 | 0 | } |
164 | |
|
165 | |
@Override |
166 | |
public Dimension getMinimumSize() { |
167 | 0 | Dimension stereoDim = getStereotypeFig().getMinimumSize(); |
168 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
169 | |
|
170 | 0 | int h = Math.max(stereoDim.height + nameDim.height - OVERLAP, |
171 | |
4 * FINGER_HEIGHT); |
172 | 0 | int w = Math.max(stereoDim.width, nameDim.width) + FINGER_WIDTH; |
173 | |
|
174 | 0 | return new Dimension(w, h); |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
protected void setStandardBounds(int x, int y, int w, |
179 | |
int h) { |
180 | 0 | if (getNameFig() == null) { |
181 | 0 | return; |
182 | |
} |
183 | |
|
184 | 0 | Rectangle oldBounds = getBounds(); |
185 | 0 | getBigPort().setBounds(x + BX, y, w - BX, h); |
186 | 0 | cover.setBounds(x + BX, y, w - BX, h); |
187 | |
|
188 | 0 | Dimension stereoDim = getStereotypeFig().getMinimumSize(); |
189 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
190 | |
|
191 | 0 | int halfHeight = FINGER_HEIGHT / 2; |
192 | 0 | upperRect.setBounds(x, y + h / 3 - halfHeight, FINGER_WIDTH, |
193 | |
FINGER_HEIGHT); |
194 | 0 | lowerRect.setBounds(x, y + 2 * h / 3 - halfHeight, FINGER_WIDTH, |
195 | |
FINGER_HEIGHT); |
196 | |
|
197 | 0 | getStereotypeFig().setBounds(x + FINGER_WIDTH + 1, |
198 | |
y + 1, |
199 | |
w - FINGER_WIDTH - 2, |
200 | |
stereoDim.height); |
201 | 0 | getNameFig().setBounds(x + FINGER_WIDTH + 1, |
202 | |
y + stereoDim.height - OVERLAP + 1, |
203 | |
w - FINGER_WIDTH - 2, |
204 | |
nameDim.height); |
205 | 0 | _x = x; |
206 | 0 | _y = y; |
207 | 0 | _w = w; |
208 | 0 | _h = h; |
209 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
210 | 0 | updateEdges(); |
211 | 0 | } |
212 | |
|
213 | |
|
214 | |
@Override |
215 | |
public boolean getUseTrapRect() { |
216 | 0 | return true; |
217 | |
} |
218 | |
|
219 | |
@Override |
220 | |
public Rectangle getHandleBox() { |
221 | 0 | Rectangle r = getBounds(); |
222 | 0 | return new Rectangle(r.x + BX, r.y, r.width - BX, r.height); |
223 | |
} |
224 | |
|
225 | |
@Override |
226 | |
public void setHandleBox(int x, int y, int w, int h) { |
227 | 0 | setBounds(x - BX, y, w + BX, h); |
228 | 0 | } |
229 | |
|
230 | |
} |