Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigStateVertex |
|
| 4.8;4.8 |
1 | /* $Id: FigStateVertex.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.Point; | |
42 | import java.awt.Rectangle; | |
43 | import java.util.ArrayList; | |
44 | import java.util.Iterator; | |
45 | import java.util.List; | |
46 | ||
47 | import org.argouml.model.Model; | |
48 | import org.argouml.uml.diagram.DiagramSettings; | |
49 | import org.argouml.uml.diagram.activity.ui.SelectionActionState; | |
50 | import org.argouml.uml.diagram.ui.FigNodeModelElement; | |
51 | import org.tigris.gef.base.Editor; | |
52 | import org.tigris.gef.base.Globals; | |
53 | import org.tigris.gef.base.LayerDiagram; | |
54 | import org.tigris.gef.base.LayerPerspective; | |
55 | import org.tigris.gef.base.Selection; | |
56 | import org.tigris.gef.presentation.Fig; | |
57 | import org.tigris.gef.presentation.FigEdge; | |
58 | import org.tigris.gef.presentation.FigNode; | |
59 | ||
60 | /** | |
61 | * Abstract class for a State Vertex | |
62 | * which has behavior for nestable nodes in UML Statechart diagrams. | |
63 | */ | |
64 | public abstract class FigStateVertex extends FigNodeModelElement { | |
65 | ||
66 | /** | |
67 | * Constructor used by PGML parser. | |
68 | * | |
69 | * @param owner the owning UML element | |
70 | * @param bounds rectangle describing bounds | |
71 | * @param settings rendering settings | |
72 | */ | |
73 | public FigStateVertex(Object owner, Rectangle bounds, DiagramSettings settings) { | |
74 | 0 | super(owner, bounds, settings); |
75 | 0 | this.allowRemoveFromDiagram(false); |
76 | 0 | } |
77 | ||
78 | /* | |
79 | * Overridden to make it possible to include a stateVertex in a composite | |
80 | * state. | |
81 | * @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig) | |
82 | */ | |
83 | @Override | |
84 | public void setEnclosingFig(Fig encloser) { | |
85 | 0 | LayerPerspective layer = (LayerPerspective) getLayer(); |
86 | ||
87 | // If the layer is null, then most likely we are being deleted. | |
88 | 0 | if (layer == null) { |
89 | 0 | return; |
90 | } | |
91 | ||
92 | 0 | super.setEnclosingFig(encloser); |
93 | ||
94 | 0 | if (!(Model.getFacade().isAStateVertex(getOwner()))) { |
95 | 0 | return; |
96 | } | |
97 | 0 | Object stateVertex = getOwner(); |
98 | 0 | Object compositeState = null; |
99 | 0 | if (encloser != null |
100 | && (Model.getFacade().isACompositeState(encloser.getOwner()))) { | |
101 | 0 | compositeState = encloser.getOwner(); |
102 | 0 | ((FigStateVertex) encloser).redrawEnclosedFigs(); |
103 | } else { | |
104 | 0 | compositeState = Model.getStateMachinesHelper().getTop( |
105 | Model.getStateMachinesHelper() | |
106 | .getStateMachine(stateVertex)); | |
107 | } | |
108 | 0 | if (compositeState != null) { |
109 | /* Do not change the model unless needed - avoids issue 4446: */ | |
110 | 0 | if (Model.getFacade().getContainer(stateVertex) != compositeState) { |
111 | 0 | Model.getStateMachinesHelper().setContainer(stateVertex, |
112 | compositeState); | |
113 | } | |
114 | } | |
115 | 0 | } |
116 | ||
117 | /** | |
118 | * Method to draw a StateVertex Fig's enclosed figs. | |
119 | */ | |
120 | public void redrawEnclosedFigs() { | |
121 | 0 | Editor editor = Globals.curEditor(); |
122 | 0 | if (editor != null && !getEnclosedFigs().isEmpty()) { |
123 | 0 | LayerDiagram lay = |
124 | ((LayerDiagram) editor.getLayerManager().getActiveLayer()); | |
125 | 0 | for (Fig f : getEnclosedFigs()) { |
126 | 0 | lay.bringInFrontOf(f, this); |
127 | 0 | if (f instanceof FigNode) { |
128 | 0 | FigNode fn = (FigNode) f; |
129 | 0 | Iterator it = fn.getFigEdges().iterator(); |
130 | 0 | while (it.hasNext()) { |
131 | 0 | lay.bringInFrontOf(((FigEdge) it.next()), this); |
132 | } | |
133 | 0 | if (fn instanceof FigStateVertex) { |
134 | 0 | ((FigStateVertex) fn).redrawEnclosedFigs(); |
135 | } | |
136 | 0 | } |
137 | } | |
138 | } | |
139 | 0 | } |
140 | ||
141 | /** | |
142 | * return selectors, depending whether we deal with activity or state | |
143 | * diagrams. | |
144 | * | |
145 | * {@inheritDoc} | |
146 | */ | |
147 | @Override | |
148 | public Selection makeSelection() { | |
149 | 0 | Object pstate = getOwner(); |
150 | ||
151 | 0 | if (pstate != null) { |
152 | ||
153 | 0 | if (Model.getFacade().isAActivityGraph( |
154 | Model.getFacade().getStateMachine( | |
155 | Model.getFacade().getContainer(pstate)))) { | |
156 | 0 | return new SelectionActionState(this); |
157 | } | |
158 | 0 | return new SelectionState(this); |
159 | } | |
160 | 0 | return null; |
161 | } | |
162 | ||
163 | /** | |
164 | * Number of points to compute for gravity point circle. | |
165 | */ | |
166 | private static final int CIRCLE_POINTS = 32; | |
167 | ||
168 | /** | |
169 | * Return a list of gravity points around circle which is enclosed | |
170 | * in the bounding box. Convenience method for use by FigInitialState | |
171 | * and FigFinalState. | |
172 | * TODO: As this method is not required by all sub classes, | |
173 | * it would seem sensible to extend FigStateVertex with FigCircleVertex | |
174 | * and only have the relevant concrete Figs extend that and gain this | |
175 | * functionality. | |
176 | * @return a List of Points | |
177 | */ | |
178 | List<Point> getCircleGravityPoints() { | |
179 | 0 | List<Point> ret = new ArrayList<Point>(); |
180 | 0 | int cx = getBigPort().getCenter().x; |
181 | 0 | int cy = getBigPort().getCenter().y; |
182 | 0 | double radius = getBigPort().getWidth() / 2 + 1; |
183 | 0 | final double pi2 = Math.PI * 2; |
184 | 0 | for (int i = 0; i < CIRCLE_POINTS; i++) { |
185 | 0 | int x = (int) (cx + Math.cos(pi2 * i / CIRCLE_POINTS) * radius); |
186 | 0 | int y = (int) (cy + Math.sin(pi2 * i / CIRCLE_POINTS) * radius); |
187 | 0 | ret.add(new Point(x, y)); |
188 | } | |
189 | 0 | return ret; |
190 | } | |
191 | ||
192 | } |