Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigSimpleState |
|
| 1.1176470588235294;1.118 |
1 | /* $Id: FigSimpleState.java 17862 2010-01-12 20:06:14Z 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.state.ui; | |
40 | ||
41 | import java.awt.Color; | |
42 | import java.awt.Dimension; | |
43 | import java.awt.Rectangle; | |
44 | import java.util.Iterator; | |
45 | ||
46 | import org.argouml.uml.diagram.DiagramSettings; | |
47 | import org.tigris.gef.presentation.FigLine; | |
48 | import org.tigris.gef.presentation.FigRRect; | |
49 | import org.tigris.gef.presentation.FigRect; | |
50 | import org.tigris.gef.presentation.FigText; | |
51 | ||
52 | /** | |
53 | * Class to display graphics for a UML MState in a diagram. | |
54 | * | |
55 | * @author ics 125b silverbullet team | |
56 | */ | |
57 | public class FigSimpleState extends FigState { | |
58 | ||
59 | private FigRect cover; | |
60 | private FigLine divider; | |
61 | ||
62 | /** | |
63 | * Constructor used by PGML parser. | |
64 | * | |
65 | * @param owner the owning UML element | |
66 | * @param bounds rectangle describing bounds | |
67 | * @param settings rendering settings | |
68 | */ | |
69 | public FigSimpleState(Object owner, Rectangle bounds, | |
70 | DiagramSettings settings) { | |
71 | 0 | super(owner, bounds, settings); |
72 | 0 | initializeSimpleState(); |
73 | 0 | } |
74 | ||
75 | private void initializeSimpleState() { | |
76 | 0 | cover = |
77 | new FigRRect(getInitialX(), getInitialY(), | |
78 | getInitialWidth(), getInitialHeight(), | |
79 | LINE_COLOR, FILL_COLOR); | |
80 | ||
81 | 0 | getBigPort().setLineWidth(0); |
82 | ||
83 | 0 | divider = |
84 | new FigLine(getInitialX(), | |
85 | getInitialY() + 2 + getNameFig().getBounds().height + 1, | |
86 | getInitialWidth() - 1, | |
87 | getInitialY() + 2 + getNameFig().getBounds().height + 1, | |
88 | LINE_COLOR); | |
89 | ||
90 | // add Figs to the FigNode in back-to-front order | |
91 | 0 | addFig(getBigPort()); |
92 | 0 | addFig(cover); |
93 | 0 | addFig(getNameFig()); |
94 | 0 | addFig(divider); |
95 | 0 | addFig(getInternal()); |
96 | ||
97 | //setBlinkPorts(false); //make port invisble unless mouse enters | |
98 | 0 | Rectangle r = getBounds(); |
99 | 0 | setBounds(r.x, r.y, r.width, r.height); |
100 | 0 | } |
101 | ||
102 | @Override | |
103 | public Object clone() { | |
104 | 0 | FigSimpleState figClone = (FigSimpleState) super.clone(); |
105 | 0 | Iterator it = figClone.getFigs().iterator(); |
106 | 0 | figClone.setBigPort((FigRRect) it.next()); |
107 | 0 | figClone.cover = (FigRect) it.next(); |
108 | 0 | figClone.setNameFig((FigText) it.next()); |
109 | 0 | figClone.divider = (FigLine) it.next(); |
110 | 0 | figClone.setInternal((FigText) it.next()); |
111 | 0 | return figClone; |
112 | } | |
113 | ||
114 | /* | |
115 | * @see org.tigris.gef.presentation.Fig#getMinimumSize() | |
116 | */ | |
117 | @Override | |
118 | public Dimension getMinimumSize() { | |
119 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
120 | 0 | Dimension internalDim = getInternal().getMinimumSize(); |
121 | ||
122 | 0 | int h = SPACE_TOP + nameDim.height |
123 | + SPACE_MIDDLE + internalDim.height | |
124 | + SPACE_BOTTOM; | |
125 | 0 | int w = Math.max(nameDim.width + 2 * MARGIN, |
126 | internalDim.width + 2 * MARGIN); | |
127 | 0 | return new Dimension(w, h); |
128 | } | |
129 | ||
130 | /** | |
131 | * Override setBounds to keep shapes looking right. | |
132 | * {@inheritDoc} | |
133 | */ | |
134 | @Override | |
135 | protected void setStandardBounds(int x, int y, int w, int h) { | |
136 | 0 | if (getNameFig() == null) { |
137 | 0 | return; |
138 | } | |
139 | 0 | Rectangle oldBounds = getBounds(); |
140 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
141 | ||
142 | 0 | getNameFig().setBounds(x + MARGIN, |
143 | y + SPACE_TOP, | |
144 | w - 2 * MARGIN, | |
145 | nameDim.height); | |
146 | 0 | divider.setShape(x, |
147 | y + DIVIDER_Y + nameDim.height, | |
148 | x + w - 1, | |
149 | y + DIVIDER_Y + nameDim.height); | |
150 | ||
151 | 0 | getInternal().setBounds( |
152 | x + MARGIN, | |
153 | y + SPACE_TOP + nameDim.height + SPACE_MIDDLE, | |
154 | w - 2 * MARGIN, | |
155 | h - SPACE_TOP - nameDim.height - SPACE_MIDDLE - SPACE_BOTTOM); | |
156 | ||
157 | 0 | getBigPort().setBounds(x, y, w, h); |
158 | 0 | cover.setBounds(x, y, w, h); |
159 | ||
160 | 0 | calcBounds(); //_x = x; _y = y; _w = w; _h = h; |
161 | 0 | updateEdges(); |
162 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
163 | 0 | } |
164 | ||
165 | /* | |
166 | * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color) | |
167 | */ | |
168 | @Override | |
169 | public void setLineColor(Color col) { | |
170 | 0 | cover.setLineColor(col); |
171 | 0 | divider.setLineColor(col); |
172 | 0 | } |
173 | ||
174 | /* | |
175 | * @see org.tigris.gef.presentation.Fig#getLineColor() | |
176 | */ | |
177 | @Override | |
178 | public Color getLineColor() { | |
179 | 0 | return cover.getLineColor(); |
180 | } | |
181 | ||
182 | /* | |
183 | * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color) | |
184 | */ | |
185 | @Override | |
186 | public void setFillColor(Color col) { | |
187 | 0 | cover.setFillColor(col); |
188 | 0 | } |
189 | ||
190 | /* | |
191 | * @see org.tigris.gef.presentation.Fig#getFillColor() | |
192 | */ | |
193 | @Override | |
194 | public Color getFillColor() { | |
195 | 0 | return cover.getFillColor(); |
196 | } | |
197 | ||
198 | /* | |
199 | * @see org.tigris.gef.presentation.Fig#setFilled(boolean) | |
200 | */ | |
201 | @Override | |
202 | public void setFilled(boolean f) { | |
203 | 0 | cover.setFilled(f); |
204 | 0 | getBigPort().setFilled(f); |
205 | 0 | } |
206 | ||
207 | ||
208 | @Override | |
209 | public boolean isFilled() { | |
210 | 0 | return cover.isFilled(); |
211 | } | |
212 | ||
213 | /* | |
214 | * @see org.tigris.gef.presentation.Fig#setLineWidth(int) | |
215 | */ | |
216 | @Override | |
217 | public void setLineWidth(int w) { | |
218 | 0 | cover.setLineWidth(w); |
219 | 0 | divider.setLineWidth(w); |
220 | 0 | } |
221 | ||
222 | /* | |
223 | * @see org.tigris.gef.presentation.Fig#getLineWidth() | |
224 | */ | |
225 | @Override | |
226 | public int getLineWidth() { | |
227 | 0 | return cover.getLineWidth(); |
228 | } | |
229 | ||
230 | /* | |
231 | * @see org.argouml.uml.diagram.state.ui.FigState#getInitialHeight() | |
232 | */ | |
233 | @Override | |
234 | protected int getInitialHeight() { | |
235 | 0 | return 40; |
236 | } | |
237 | ||
238 | /* | |
239 | * @see org.argouml.uml.diagram.state.ui.FigState#getInitialWidth() | |
240 | */ | |
241 | @Override | |
242 | protected int getInitialWidth() { | |
243 | 0 | return 70; |
244 | } | |
245 | ||
246 | /* | |
247 | * @see org.argouml.uml.diagram.state.ui.FigState#getInitialX() | |
248 | */ | |
249 | @Override | |
250 | protected int getInitialX() { | |
251 | 0 | return 0; |
252 | } | |
253 | ||
254 | /* | |
255 | * @see org.argouml.uml.diagram.state.ui.FigState#getInitialY() | |
256 | */ | |
257 | @Override | |
258 | protected int getInitialY() { | |
259 | 0 | return 0; |
260 | } | |
261 | ||
262 | } |