root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / RotateCADToolContext.java @ 4365
History | View | Annotate | Download (8.38 KB)
1 | 3883 | caballero | |
---|---|---|---|
2 | //
|
||
3 | // Vicente Caballero Navarro
|
||
4 | |||
5 | |||
6 | package com.iver.cit.gvsig.gui.cad.tools.smc; |
||
7 | |||
8 | import com.iver.cit.gvsig.gui.cad.tools.RotateCADTool; |
||
9 | 4324 | caballero | import java.awt.event.InputEvent; |
10 | 3883 | caballero | |
11 | public final class RotateCADToolContext |
||
12 | extends statemap.FSMContext
|
||
13 | { |
||
14 | //---------------------------------------------------------------
|
||
15 | // Member methods.
|
||
16 | //
|
||
17 | |||
18 | public RotateCADToolContext(RotateCADTool owner)
|
||
19 | { |
||
20 | super();
|
||
21 | |||
22 | _owner = owner; |
||
23 | 3978 | caballero | setState(Rotate.PointMain); |
24 | Rotate.PointMain.Entry(this);
|
||
25 | 3883 | caballero | } |
26 | |||
27 | public void addOption(String s) |
||
28 | { |
||
29 | _transition = "addOption";
|
||
30 | getState().addOption(this, s);
|
||
31 | _transition = "";
|
||
32 | return;
|
||
33 | } |
||
34 | |||
35 | 4324 | caballero | public void addPoint(double pointX, double pointY, InputEvent event) |
36 | 3883 | caballero | { |
37 | _transition = "addPoint";
|
||
38 | 4324 | caballero | getState().addPoint(this, pointX, pointY, event);
|
39 | 3883 | caballero | _transition = "";
|
40 | return;
|
||
41 | } |
||
42 | |||
43 | public void addValue(double d) |
||
44 | { |
||
45 | _transition = "addValue";
|
||
46 | getState().addValue(this, d);
|
||
47 | _transition = "";
|
||
48 | return;
|
||
49 | } |
||
50 | |||
51 | public RotateCADToolState getState()
|
||
52 | throws statemap.StateUndefinedException
|
||
53 | { |
||
54 | if (_state == null) |
||
55 | { |
||
56 | throw(
|
||
57 | new statemap.StateUndefinedException());
|
||
58 | } |
||
59 | |||
60 | return ((RotateCADToolState) _state);
|
||
61 | } |
||
62 | |||
63 | protected RotateCADTool getOwner()
|
||
64 | { |
||
65 | return (_owner);
|
||
66 | } |
||
67 | |||
68 | //---------------------------------------------------------------
|
||
69 | // Member data.
|
||
70 | //
|
||
71 | |||
72 | transient private RotateCADTool _owner; |
||
73 | |||
74 | //---------------------------------------------------------------
|
||
75 | // Inner classes.
|
||
76 | //
|
||
77 | |||
78 | public static abstract class RotateCADToolState |
||
79 | extends statemap.State
|
||
80 | { |
||
81 | //-----------------------------------------------------------
|
||
82 | // Member methods.
|
||
83 | //
|
||
84 | |||
85 | protected RotateCADToolState(String name, int id) |
||
86 | { |
||
87 | super (name, id);
|
||
88 | } |
||
89 | |||
90 | protected void Entry(RotateCADToolContext context) {} |
||
91 | protected void Exit(RotateCADToolContext context) {} |
||
92 | |||
93 | protected void addOption(RotateCADToolContext context, String s) |
||
94 | { |
||
95 | Default(context); |
||
96 | } |
||
97 | |||
98 | 4324 | caballero | protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event) |
99 | 3883 | caballero | { |
100 | Default(context); |
||
101 | } |
||
102 | |||
103 | protected void addValue(RotateCADToolContext context, double d) |
||
104 | { |
||
105 | Default(context); |
||
106 | } |
||
107 | |||
108 | protected void Default(RotateCADToolContext context) |
||
109 | { |
||
110 | throw (
|
||
111 | new statemap.TransitionUndefinedException(
|
||
112 | "State: " +
|
||
113 | context.getState().getName() + |
||
114 | ", Transition: " +
|
||
115 | context.getTransition())); |
||
116 | } |
||
117 | |||
118 | //-----------------------------------------------------------
|
||
119 | // Member data.
|
||
120 | //
|
||
121 | } |
||
122 | |||
123 | 3978 | caballero | /* package */ static abstract class Rotate |
124 | 3883 | caballero | { |
125 | //-----------------------------------------------------------
|
||
126 | // Member methods.
|
||
127 | //
|
||
128 | |||
129 | //-----------------------------------------------------------
|
||
130 | // Member data.
|
||
131 | //
|
||
132 | |||
133 | //-------------------------------------------------------
|
||
134 | // Statics.
|
||
135 | //
|
||
136 | 3978 | caballero | /* package */ static Rotate_Default.Rotate_PointMain PointMain; |
137 | /* package */ static Rotate_Default.Rotate_AngleOrPoint AngleOrPoint; |
||
138 | private static Rotate_Default Default; |
||
139 | 3883 | caballero | |
140 | static
|
||
141 | { |
||
142 | 3978 | caballero | PointMain = new Rotate_Default.Rotate_PointMain("Rotate.PointMain", 0); |
143 | AngleOrPoint = new Rotate_Default.Rotate_AngleOrPoint("Rotate.AngleOrPoint", 1); |
||
144 | Default = new Rotate_Default("Rotate.Default", -1); |
||
145 | 3883 | caballero | } |
146 | |||
147 | } |
||
148 | |||
149 | 3978 | caballero | protected static class Rotate_Default |
150 | 3883 | caballero | extends RotateCADToolState
|
151 | { |
||
152 | //-----------------------------------------------------------
|
||
153 | // Member methods.
|
||
154 | //
|
||
155 | |||
156 | 3978 | caballero | protected Rotate_Default(String name, int id) |
157 | 3883 | caballero | { |
158 | super (name, id);
|
||
159 | } |
||
160 | |||
161 | protected void addOption(RotateCADToolContext context, String s) |
||
162 | { |
||
163 | RotateCADTool ctxt = context.getOwner(); |
||
164 | |||
165 | if (s.equals("Cancelar")) |
||
166 | { |
||
167 | boolean loopbackFlag =
|
||
168 | context.getState().getName().equals( |
||
169 | 3978 | caballero | Rotate.PointMain.getName()); |
170 | 3883 | caballero | |
171 | if (loopbackFlag == false) |
||
172 | { |
||
173 | (context.getState()).Exit(context); |
||
174 | } |
||
175 | |||
176 | context.clearState(); |
||
177 | try
|
||
178 | { |
||
179 | ctxt.end(); |
||
180 | } |
||
181 | finally
|
||
182 | { |
||
183 | 3978 | caballero | context.setState(Rotate.PointMain); |
184 | 3883 | caballero | |
185 | if (loopbackFlag == false) |
||
186 | { |
||
187 | (context.getState()).Entry(context); |
||
188 | } |
||
189 | |||
190 | } |
||
191 | } |
||
192 | else
|
||
193 | { |
||
194 | super.addOption(context, s);
|
||
195 | } |
||
196 | |||
197 | return;
|
||
198 | } |
||
199 | |||
200 | //-----------------------------------------------------------
|
||
201 | // Inner classse.
|
||
202 | //
|
||
203 | |||
204 | |||
205 | 3978 | caballero | private static final class Rotate_PointMain |
206 | extends Rotate_Default
|
||
207 | 3883 | caballero | { |
208 | //-------------------------------------------------------
|
||
209 | // Member methods.
|
||
210 | //
|
||
211 | |||
212 | 3978 | caballero | private Rotate_PointMain(String name, int id) |
213 | 3883 | caballero | { |
214 | super (name, id);
|
||
215 | } |
||
216 | |||
217 | protected void Entry(RotateCADToolContext context) |
||
218 | { |
||
219 | RotateCADTool ctxt = context.getOwner(); |
||
220 | |||
221 | ctxt.selection(); |
||
222 | ctxt.setQuestion("ROTAR" + "\n" + |
||
223 | "Precise punto base");
|
||
224 | ctxt.setDescription(new String[]{"Cancelar"}); |
||
225 | return;
|
||
226 | } |
||
227 | |||
228 | 4324 | caballero | protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event) |
229 | 3883 | caballero | { |
230 | RotateCADTool ctxt = context.getOwner(); |
||
231 | |||
232 | |||
233 | (context.getState()).Exit(context); |
||
234 | context.clearState(); |
||
235 | try
|
||
236 | { |
||
237 | ctxt.setQuestion("Precise angulo de rotacion");
|
||
238 | ctxt.setDescription(new String[]{"Cancelar"}); |
||
239 | 4365 | caballero | ctxt.addPoint(pointX, pointY, event); |
240 | 3883 | caballero | } |
241 | finally
|
||
242 | { |
||
243 | 3978 | caballero | context.setState(Rotate.AngleOrPoint); |
244 | 3883 | caballero | (context.getState()).Entry(context); |
245 | } |
||
246 | return;
|
||
247 | } |
||
248 | |||
249 | //-------------------------------------------------------
|
||
250 | // Member data.
|
||
251 | //
|
||
252 | } |
||
253 | |||
254 | 3978 | caballero | private static final class Rotate_AngleOrPoint |
255 | extends Rotate_Default
|
||
256 | 3883 | caballero | { |
257 | //-------------------------------------------------------
|
||
258 | // Member methods.
|
||
259 | //
|
||
260 | |||
261 | 3978 | caballero | private Rotate_AngleOrPoint(String name, int id) |
262 | 3883 | caballero | { |
263 | super (name, id);
|
||
264 | } |
||
265 | |||
266 | 4324 | caballero | protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event) |
267 | 3883 | caballero | { |
268 | RotateCADTool ctxt = context.getOwner(); |
||
269 | |||
270 | |||
271 | (context.getState()).Exit(context); |
||
272 | context.clearState(); |
||
273 | try
|
||
274 | { |
||
275 | ctxt.setDescription(new String[]{"Cancelar"}); |
||
276 | 4365 | caballero | ctxt.addPoint(pointX, pointY, event); |
277 | 3883 | caballero | ctxt.end(); |
278 | ctxt.refresh(); |
||
279 | } |
||
280 | finally
|
||
281 | { |
||
282 | 3978 | caballero | context.setState(Rotate.PointMain); |
283 | 3883 | caballero | (context.getState()).Entry(context); |
284 | } |
||
285 | return;
|
||
286 | } |
||
287 | |||
288 | protected void addValue(RotateCADToolContext context, double d) |
||
289 | { |
||
290 | RotateCADTool ctxt = context.getOwner(); |
||
291 | |||
292 | |||
293 | (context.getState()).Exit(context); |
||
294 | context.clearState(); |
||
295 | try
|
||
296 | { |
||
297 | ctxt.setDescription(new String[]{"Cancelar"}); |
||
298 | ctxt.addValue(d); |
||
299 | ctxt.end(); |
||
300 | ctxt.refresh(); |
||
301 | } |
||
302 | finally
|
||
303 | { |
||
304 | 3978 | caballero | context.setState(Rotate.PointMain); |
305 | 3883 | caballero | (context.getState()).Entry(context); |
306 | } |
||
307 | return;
|
||
308 | } |
||
309 | |||
310 | //-------------------------------------------------------
|
||
311 | // Member data.
|
||
312 | //
|
||
313 | } |
||
314 | |||
315 | //-----------------------------------------------------------
|
||
316 | // Member data.
|
||
317 | //
|
||
318 | } |
||
319 | } |