svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / RotateCADToolContext.java @ 10626
History | View | Annotate | Download (10.8 KB)
1 |
|
---|---|
2 |
//
|
3 |
// Vicente Caballero Navarro
|
4 |
|
5 |
|
6 |
package com.iver.cit.gvsig.gui.cad.tools.smc; |
7 |
|
8 |
import java.awt.event.InputEvent; |
9 |
|
10 |
import com.iver.andami.PluginServices; |
11 |
import com.iver.cit.gvsig.gui.cad.tools.RotateCADTool; |
12 |
|
13 |
public final class RotateCADToolContext |
14 |
extends statemap.FSMContext
|
15 |
{ |
16 |
//---------------------------------------------------------------
|
17 |
// Member methods.
|
18 |
//
|
19 |
|
20 |
public RotateCADToolContext(RotateCADTool owner)
|
21 |
{ |
22 |
super();
|
23 |
|
24 |
_owner = owner; |
25 |
setState(Rotate.PointMain); |
26 |
Rotate.PointMain.Entry(this);
|
27 |
} |
28 |
|
29 |
public void addOption(String s) |
30 |
{ |
31 |
_transition = "addOption";
|
32 |
getState().addOption(this, s);
|
33 |
_transition = "";
|
34 |
return;
|
35 |
} |
36 |
|
37 |
public void addPoint(double pointX, double pointY, InputEvent event) |
38 |
{ |
39 |
_transition = "addPoint";
|
40 |
getState().addPoint(this, pointX, pointY, event);
|
41 |
_transition = "";
|
42 |
return;
|
43 |
} |
44 |
|
45 |
public void addValue(double d) |
46 |
{ |
47 |
_transition = "addValue";
|
48 |
getState().addValue(this, d);
|
49 |
_transition = "";
|
50 |
return;
|
51 |
} |
52 |
|
53 |
public RotateCADToolState getState()
|
54 |
throws statemap.StateUndefinedException
|
55 |
{ |
56 |
if (_state == null) |
57 |
{ |
58 |
throw(
|
59 |
new statemap.StateUndefinedException());
|
60 |
} |
61 |
|
62 |
return ((RotateCADToolState) _state);
|
63 |
} |
64 |
|
65 |
protected RotateCADTool getOwner()
|
66 |
{ |
67 |
return (_owner);
|
68 |
} |
69 |
|
70 |
//---------------------------------------------------------------
|
71 |
// Member data.
|
72 |
//
|
73 |
|
74 |
transient private RotateCADTool _owner; |
75 |
|
76 |
//---------------------------------------------------------------
|
77 |
// Inner classes.
|
78 |
//
|
79 |
|
80 |
public static abstract class RotateCADToolState |
81 |
extends statemap.State
|
82 |
{ |
83 |
//-----------------------------------------------------------
|
84 |
// Member methods.
|
85 |
//
|
86 |
|
87 |
protected RotateCADToolState(String name, int id) |
88 |
{ |
89 |
super (name, id);
|
90 |
} |
91 |
|
92 |
protected void Entry(RotateCADToolContext context) {} |
93 |
protected void Exit(RotateCADToolContext context) {} |
94 |
|
95 |
protected void addOption(RotateCADToolContext context, String s) |
96 |
{ |
97 |
Default(context); |
98 |
} |
99 |
|
100 |
protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event) |
101 |
{ |
102 |
Default(context); |
103 |
} |
104 |
|
105 |
protected void addValue(RotateCADToolContext context, double d) |
106 |
{ |
107 |
Default(context); |
108 |
} |
109 |
|
110 |
protected void Default(RotateCADToolContext context) |
111 |
{ |
112 |
throw (
|
113 |
new statemap.TransitionUndefinedException(
|
114 |
"State: " +
|
115 |
context.getState().getName() + |
116 |
", Transition: " +
|
117 |
context.getTransition())); |
118 |
} |
119 |
|
120 |
//-----------------------------------------------------------
|
121 |
// Member data.
|
122 |
//
|
123 |
} |
124 |
|
125 |
/* package */ static abstract class Rotate |
126 |
{ |
127 |
//-----------------------------------------------------------
|
128 |
// Member methods.
|
129 |
//
|
130 |
|
131 |
//-----------------------------------------------------------
|
132 |
// Member data.
|
133 |
//
|
134 |
|
135 |
//-------------------------------------------------------
|
136 |
// Statics.
|
137 |
//
|
138 |
/* package */ static Rotate_Default.Rotate_PointMain PointMain; |
139 |
/* package */ static Rotate_Default.Rotate_AngleOrPoint AngleOrPoint; |
140 |
private static Rotate_Default Default; |
141 |
|
142 |
static
|
143 |
{ |
144 |
PointMain = new Rotate_Default.Rotate_PointMain("Rotate.PointMain", 0); |
145 |
AngleOrPoint = new Rotate_Default.Rotate_AngleOrPoint("Rotate.AngleOrPoint", 1); |
146 |
Default = new Rotate_Default("Rotate.Default", -1); |
147 |
} |
148 |
|
149 |
} |
150 |
|
151 |
protected static class Rotate_Default |
152 |
extends RotateCADToolState
|
153 |
{ |
154 |
//-----------------------------------------------------------
|
155 |
// Member methods.
|
156 |
//
|
157 |
|
158 |
protected Rotate_Default(String name, int id) |
159 |
{ |
160 |
super (name, id);
|
161 |
} |
162 |
|
163 |
protected void addOption(RotateCADToolContext context, String s) |
164 |
{ |
165 |
RotateCADTool ctxt = context.getOwner(); |
166 |
|
167 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
168 |
{ |
169 |
boolean loopbackFlag =
|
170 |
context.getState().getName().equals( |
171 |
Rotate.PointMain.getName()); |
172 |
|
173 |
if (loopbackFlag == false) |
174 |
{ |
175 |
(context.getState()).Exit(context); |
176 |
} |
177 |
|
178 |
context.clearState(); |
179 |
try
|
180 |
{ |
181 |
ctxt.end(); |
182 |
} |
183 |
finally
|
184 |
{ |
185 |
context.setState(Rotate.PointMain); |
186 |
|
187 |
if (loopbackFlag == false) |
188 |
{ |
189 |
(context.getState()).Entry(context); |
190 |
} |
191 |
|
192 |
} |
193 |
} |
194 |
else
|
195 |
{ |
196 |
boolean loopbackFlag =
|
197 |
context.getState().getName().equals( |
198 |
Rotate.PointMain.getName()); |
199 |
|
200 |
if (loopbackFlag == false) |
201 |
{ |
202 |
(context.getState()).Exit(context); |
203 |
} |
204 |
|
205 |
context.clearState(); |
206 |
try
|
207 |
{ |
208 |
ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
209 |
} |
210 |
finally
|
211 |
{ |
212 |
context.setState(Rotate.PointMain); |
213 |
|
214 |
if (loopbackFlag == false) |
215 |
{ |
216 |
(context.getState()).Entry(context); |
217 |
} |
218 |
|
219 |
} |
220 |
} |
221 |
|
222 |
return;
|
223 |
} |
224 |
|
225 |
protected void addValue(RotateCADToolContext context, double d) |
226 |
{ |
227 |
RotateCADTool ctxt = context.getOwner(); |
228 |
|
229 |
boolean loopbackFlag =
|
230 |
context.getState().getName().equals( |
231 |
Rotate.PointMain.getName()); |
232 |
|
233 |
if (loopbackFlag == false) |
234 |
{ |
235 |
(context.getState()).Exit(context); |
236 |
} |
237 |
|
238 |
context.clearState(); |
239 |
try
|
240 |
{ |
241 |
ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
242 |
} |
243 |
finally
|
244 |
{ |
245 |
context.setState(Rotate.PointMain); |
246 |
|
247 |
if (loopbackFlag == false) |
248 |
{ |
249 |
(context.getState()).Entry(context); |
250 |
} |
251 |
|
252 |
} |
253 |
return;
|
254 |
} |
255 |
|
256 |
protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event) |
257 |
{ |
258 |
RotateCADTool ctxt = context.getOwner(); |
259 |
|
260 |
boolean loopbackFlag =
|
261 |
context.getState().getName().equals( |
262 |
Rotate.PointMain.getName()); |
263 |
|
264 |
if (loopbackFlag == false) |
265 |
{ |
266 |
(context.getState()).Exit(context); |
267 |
} |
268 |
|
269 |
context.clearState(); |
270 |
try
|
271 |
{ |
272 |
ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
273 |
} |
274 |
finally
|
275 |
{ |
276 |
context.setState(Rotate.PointMain); |
277 |
|
278 |
if (loopbackFlag == false) |
279 |
{ |
280 |
(context.getState()).Entry(context); |
281 |
} |
282 |
|
283 |
} |
284 |
return;
|
285 |
} |
286 |
|
287 |
//-----------------------------------------------------------
|
288 |
// Inner classse.
|
289 |
//
|
290 |
|
291 |
|
292 |
private static final class Rotate_PointMain |
293 |
extends Rotate_Default
|
294 |
{ |
295 |
//-------------------------------------------------------
|
296 |
// Member methods.
|
297 |
//
|
298 |
|
299 |
private Rotate_PointMain(String name, int id) |
300 |
{ |
301 |
super (name, id);
|
302 |
} |
303 |
|
304 |
protected void Entry(RotateCADToolContext context) |
305 |
{ |
306 |
RotateCADTool ctxt = context.getOwner(); |
307 |
|
308 |
ctxt.selection(); |
309 |
ctxt.setQuestion(PluginServices.getText(this,"insert_basis_point")); |
310 |
ctxt.setDescription(new String[]{"cancel"}); |
311 |
return;
|
312 |
} |
313 |
|
314 |
protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event) |
315 |
{ |
316 |
RotateCADTool ctxt = context.getOwner(); |
317 |
|
318 |
|
319 |
(context.getState()).Exit(context); |
320 |
context.clearState(); |
321 |
try
|
322 |
{ |
323 |
ctxt.setQuestion(PluginServices.getText(this,"insert_rotation_angle")); |
324 |
ctxt.setDescription(new String[]{"cancel"}); |
325 |
ctxt.addPoint(pointX, pointY, event); |
326 |
} |
327 |
finally
|
328 |
{ |
329 |
context.setState(Rotate.AngleOrPoint); |
330 |
(context.getState()).Entry(context); |
331 |
} |
332 |
return;
|
333 |
} |
334 |
|
335 |
//-------------------------------------------------------
|
336 |
// Member data.
|
337 |
//
|
338 |
} |
339 |
|
340 |
private static final class Rotate_AngleOrPoint |
341 |
extends Rotate_Default
|
342 |
{ |
343 |
//-------------------------------------------------------
|
344 |
// Member methods.
|
345 |
//
|
346 |
|
347 |
private Rotate_AngleOrPoint(String name, int id) |
348 |
{ |
349 |
super (name, id);
|
350 |
} |
351 |
|
352 |
protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event) |
353 |
{ |
354 |
RotateCADTool ctxt = context.getOwner(); |
355 |
|
356 |
|
357 |
(context.getState()).Exit(context); |
358 |
context.clearState(); |
359 |
try
|
360 |
{ |
361 |
ctxt.setDescription(new String[]{"cancel"}); |
362 |
ctxt.addPoint(pointX, pointY, event); |
363 |
ctxt.end(); |
364 |
ctxt.refresh(); |
365 |
} |
366 |
finally
|
367 |
{ |
368 |
context.setState(Rotate.PointMain); |
369 |
(context.getState()).Entry(context); |
370 |
} |
371 |
return;
|
372 |
} |
373 |
|
374 |
protected void addValue(RotateCADToolContext context, double d) |
375 |
{ |
376 |
RotateCADTool ctxt = context.getOwner(); |
377 |
|
378 |
|
379 |
(context.getState()).Exit(context); |
380 |
context.clearState(); |
381 |
try
|
382 |
{ |
383 |
ctxt.setDescription(new String[]{"cancel"}); |
384 |
ctxt.addValue(d); |
385 |
ctxt.end(); |
386 |
ctxt.refresh(); |
387 |
} |
388 |
finally
|
389 |
{ |
390 |
context.setState(Rotate.PointMain); |
391 |
(context.getState()).Entry(context); |
392 |
} |
393 |
return;
|
394 |
} |
395 |
|
396 |
//-------------------------------------------------------
|
397 |
// Member data.
|
398 |
//
|
399 |
} |
400 |
|
401 |
//-----------------------------------------------------------
|
402 |
// Member data.
|
403 |
//
|
404 |
} |
405 |
} |