Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigSynchState |
|
| 1.3529411764705883;1.353 |
1 | /* $Id: FigSynchState.java 18728 2010-09-10 09:29:47Z mvw $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009-2010 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 | * Michiel van der Wulp | |
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.state.ui; | |
40 | ||
41 | import java.awt.Color; | |
42 | import java.awt.Font; | |
43 | import java.awt.Rectangle; | |
44 | import java.awt.event.MouseEvent; | |
45 | import java.beans.PropertyChangeEvent; | |
46 | import java.util.Iterator; | |
47 | ||
48 | import org.argouml.model.Model; | |
49 | import org.argouml.uml.diagram.DiagramSettings; | |
50 | import org.tigris.gef.presentation.Fig; | |
51 | import org.tigris.gef.presentation.FigCircle; | |
52 | import org.tigris.gef.presentation.FigRect; | |
53 | import org.tigris.gef.presentation.FigText; | |
54 | ||
55 | /** | |
56 | * Class to display graphics for a UML SynchState in a diagram. <p> | |
57 | * | |
58 | * TODO: If the font increases, the circle should grow, too. | |
59 | * | |
60 | * @author pepargouml@yahoo.es | |
61 | */ | |
62 | public class FigSynchState extends FigStateVertex { | |
63 | ||
64 | private static final int X = X0; | |
65 | private static final int Y = Y0; | |
66 | private static final int WIDTH = 25; | |
67 | private static final int HEIGHT = 25; | |
68 | ||
69 | private FigText bound; | |
70 | private FigCircle head; | |
71 | ||
72 | /** | |
73 | * Construct a new FigSynchState. | |
74 | * | |
75 | * @param owner owning UML element | |
76 | * @param bounds position and size | |
77 | * @param settings rendering settings | |
78 | */ | |
79 | public FigSynchState(Object owner, Rectangle bounds, | |
80 | DiagramSettings settings) { | |
81 | 0 | super(owner, bounds, settings); |
82 | 0 | initFigs(); |
83 | 0 | } |
84 | ||
85 | @Override | |
86 | protected Fig createBigPortFig() { | |
87 | 0 | return new FigCircle(X, Y, WIDTH, HEIGHT, DEBUG_COLOR, |
88 | DEBUG_COLOR); | |
89 | } | |
90 | ||
91 | private void initFigs() { | |
92 | 0 | setEditable(false); |
93 | ||
94 | 0 | head = new FigCircle(X, Y, WIDTH, HEIGHT, LINE_COLOR, FILL_COLOR); |
95 | ||
96 | 0 | bound = new FigText(X - 2, Y + 2, 0, 0, true); |
97 | 0 | bound.setFilled(false); |
98 | 0 | bound.setLineWidth(0); |
99 | 0 | bound.setTextColor(TEXT_COLOR); |
100 | 0 | bound.setReturnAction(FigText.END_EDITING); |
101 | 0 | bound.setTabAction(FigText.END_EDITING); |
102 | 0 | bound.setJustification(FigText.JUSTIFY_CENTER); |
103 | 0 | bound.setEditable(false); |
104 | 0 | bound.setText("*"); |
105 | ||
106 | 0 | addFig(getBigPort()); |
107 | 0 | addFig(head); |
108 | 0 | addFig(bound); |
109 | ||
110 | 0 | setBlinkPorts(false); //make port invisible unless mouse enters |
111 | 0 | } |
112 | ||
113 | /** | |
114 | * Override setStandardBounds to keep shapes looking right. | |
115 | * {@inheritDoc} | |
116 | */ | |
117 | @Override | |
118 | protected void setStandardBounds(int x, int y, int w, int h) { | |
119 | 0 | if (getNameFig() == null) { |
120 | 0 | return; |
121 | } | |
122 | 0 | Rectangle oldBounds = getBounds(); |
123 | ||
124 | 0 | getBigPort().setBounds(x, y, WIDTH, HEIGHT); |
125 | 0 | head.setBounds(x, y, WIDTH, HEIGHT); |
126 | ||
127 | 0 | bound.setBounds(x - 2, y + 2, 0, 0); |
128 | 0 | bound.calcBounds(); |
129 | 0 | calcBounds(); |
130 | 0 | updateEdges(); |
131 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
132 | 0 | } |
133 | ||
134 | ||
135 | /* | |
136 | * @see java.lang.Object#clone() | |
137 | */ | |
138 | @Override | |
139 | public Object clone() { | |
140 | 0 | FigSynchState figClone = (FigSynchState) super.clone(); |
141 | 0 | Iterator it = figClone.getFigs().iterator(); |
142 | 0 | figClone.setBigPort((FigRect) it.next()); |
143 | 0 | figClone.head = (FigCircle) it.next(); |
144 | 0 | figClone.bound = (FigText) it.next(); |
145 | 0 | return figClone; |
146 | } | |
147 | ||
148 | ||
149 | /** | |
150 | * Synch states are fixed size. | |
151 | * | |
152 | * @return false | |
153 | */ | |
154 | @Override | |
155 | public boolean isResizable() { | |
156 | 0 | return false; |
157 | } | |
158 | ||
159 | /* | |
160 | * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color) | |
161 | */ | |
162 | @Override | |
163 | public void setLineColor(Color col) { | |
164 | 0 | head.setLineColor(col); |
165 | 0 | } |
166 | ||
167 | /* | |
168 | * @see org.tigris.gef.presentation.Fig#getLineColor() | |
169 | */ | |
170 | @Override | |
171 | public Color getLineColor() { | |
172 | 0 | return head.getLineColor(); |
173 | } | |
174 | ||
175 | /* | |
176 | * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color) | |
177 | */ | |
178 | @Override | |
179 | public void setFillColor(Color col) { | |
180 | 0 | head.setFillColor(col); |
181 | 0 | } |
182 | ||
183 | /* | |
184 | * @see org.tigris.gef.presentation.Fig#getFillColor() | |
185 | */ | |
186 | @Override | |
187 | public Color getFillColor() { | |
188 | 0 | return head.getFillColor(); |
189 | } | |
190 | ||
191 | /* | |
192 | * @see org.tigris.gef.presentation.Fig#setFilled(boolean) | |
193 | */ | |
194 | @Override | |
195 | public void setFilled(boolean f) { | |
196 | // ignored | |
197 | 0 | } |
198 | ||
199 | @Override | |
200 | public boolean isFilled() { | |
201 | 0 | return true; |
202 | } | |
203 | ||
204 | /* | |
205 | * @see org.tigris.gef.presentation.Fig#setLineWidth(int) | |
206 | */ | |
207 | @Override | |
208 | public void setLineWidth(int w) { | |
209 | 0 | head.setLineWidth(w); |
210 | 0 | } |
211 | ||
212 | /* | |
213 | * @see org.tigris.gef.presentation.Fig#getLineWidth() | |
214 | */ | |
215 | @Override | |
216 | public int getLineWidth() { | |
217 | 0 | return head.getLineWidth(); |
218 | } | |
219 | ||
220 | /* | |
221 | * @see org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent) | |
222 | */ | |
223 | @Override | |
224 | protected void modelChanged(PropertyChangeEvent mee) { | |
225 | 0 | super.modelChanged(mee); |
226 | 0 | if (mee.getPropertyName().equals("bound")) { |
227 | 0 | if (getOwner() == null) { |
228 | 0 | return; |
229 | } | |
230 | 0 | int b = Model.getFacade().getBound(getOwner()); |
231 | String aux; | |
232 | 0 | if (b <= 0) { |
233 | 0 | aux = "*"; |
234 | } else { | |
235 | 0 | aux = String.valueOf(b); |
236 | } | |
237 | 0 | bound.setText(aux); |
238 | 0 | updateBounds(); |
239 | 0 | damage(); |
240 | } | |
241 | 0 | } |
242 | ||
243 | /* | |
244 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) | |
245 | */ | |
246 | @Override | |
247 | public void mouseClicked(MouseEvent me) { | |
248 | 0 | } |
249 | ||
250 | /** | |
251 | * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateFont() | |
252 | */ | |
253 | @Override | |
254 | protected void updateFont() { | |
255 | 0 | super.updateFont(); |
256 | 0 | Font f = getSettings().getFontPlain(); |
257 | 0 | bound.setFont(f); |
258 | 0 | } |
259 | ||
260 | } |