root / trunk / extensions / extTopology / src / com / iver / cit / gvsig / cad / sm / TopologicalEditVertexCADToolContext.java @ 19998
History | View | Annotate | Download (21.6 KB)
1 | 19998 | azabala | |
---|---|---|---|
2 | /**
|
||
3 | Finite state machine, generated with fsm tool
|
||
4 | (http://smc.sourceforge.net)
|
||
5 | @author Alvaro Zabala
|
||
6 | */
|
||
7 | |||
8 | |||
9 | package com.iver.cit.gvsig.cad.sm; |
||
10 | |||
11 | import com.iver.cit.gvsig.cad.TopologicalEditVertexCADTool; |
||
12 | import java.awt.event.InputEvent; |
||
13 | import com.iver.andami.PluginServices; |
||
14 | |||
15 | public final class TopologicalEditVertexCADToolContext |
||
16 | extends statemap.FSMContext
|
||
17 | { |
||
18 | //---------------------------------------------------------------
|
||
19 | // Member methods.
|
||
20 | //
|
||
21 | |||
22 | public TopologicalEditVertexCADToolContext(TopologicalEditVertexCADTool owner)
|
||
23 | { |
||
24 | super();
|
||
25 | |||
26 | _owner = owner; |
||
27 | setState(TopologicalEdition.FirstPoint); |
||
28 | TopologicalEdition.FirstPoint.Entry(this);
|
||
29 | } |
||
30 | |||
31 | public void addOption(String s) |
||
32 | { |
||
33 | _transition = "addOption";
|
||
34 | getState().addOption(this, s);
|
||
35 | _transition = "";
|
||
36 | return;
|
||
37 | } |
||
38 | |||
39 | public void addPoint(double pointX, double pointY, InputEvent event) |
||
40 | { |
||
41 | _transition = "addPoint";
|
||
42 | getState().addPoint(this, pointX, pointY, event);
|
||
43 | _transition = "";
|
||
44 | return;
|
||
45 | } |
||
46 | |||
47 | public void addValue(double d) |
||
48 | { |
||
49 | _transition = "addValue";
|
||
50 | getState().addValue(this, d);
|
||
51 | _transition = "";
|
||
52 | return;
|
||
53 | } |
||
54 | |||
55 | public TopologicalEditVertexCADToolState getState()
|
||
56 | throws statemap.StateUndefinedException
|
||
57 | { |
||
58 | if (_state == null) |
||
59 | { |
||
60 | throw(
|
||
61 | new statemap.StateUndefinedException());
|
||
62 | } |
||
63 | |||
64 | return ((TopologicalEditVertexCADToolState) _state);
|
||
65 | } |
||
66 | |||
67 | protected TopologicalEditVertexCADTool getOwner()
|
||
68 | { |
||
69 | return (_owner);
|
||
70 | } |
||
71 | |||
72 | //---------------------------------------------------------------
|
||
73 | // Member data.
|
||
74 | //
|
||
75 | |||
76 | transient private TopologicalEditVertexCADTool _owner; |
||
77 | |||
78 | //---------------------------------------------------------------
|
||
79 | // Inner classes.
|
||
80 | //
|
||
81 | |||
82 | public static abstract class TopologicalEditVertexCADToolState |
||
83 | extends statemap.State
|
||
84 | { |
||
85 | //-----------------------------------------------------------
|
||
86 | // Member methods.
|
||
87 | //
|
||
88 | |||
89 | protected TopologicalEditVertexCADToolState(String name, int id) |
||
90 | { |
||
91 | super (name, id);
|
||
92 | } |
||
93 | |||
94 | protected void Entry(TopologicalEditVertexCADToolContext context) {} |
||
95 | protected void Exit(TopologicalEditVertexCADToolContext context) {} |
||
96 | |||
97 | protected void addOption(TopologicalEditVertexCADToolContext context, String s) |
||
98 | { |
||
99 | Default(context); |
||
100 | } |
||
101 | |||
102 | protected void addPoint(TopologicalEditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
||
103 | { |
||
104 | Default(context); |
||
105 | } |
||
106 | |||
107 | protected void addValue(TopologicalEditVertexCADToolContext context, double d) |
||
108 | { |
||
109 | Default(context); |
||
110 | } |
||
111 | |||
112 | protected void Default(TopologicalEditVertexCADToolContext context) |
||
113 | { |
||
114 | throw (
|
||
115 | new statemap.TransitionUndefinedException(
|
||
116 | "State: " +
|
||
117 | context.getState().getName() + |
||
118 | ", Transition: " +
|
||
119 | context.getTransition())); |
||
120 | } |
||
121 | |||
122 | //-----------------------------------------------------------
|
||
123 | // Member data.
|
||
124 | //
|
||
125 | } |
||
126 | |||
127 | /* package */ static abstract class TopologicalEdition |
||
128 | { |
||
129 | //-----------------------------------------------------------
|
||
130 | // Member methods.
|
||
131 | //
|
||
132 | |||
133 | //-----------------------------------------------------------
|
||
134 | // Member data.
|
||
135 | //
|
||
136 | |||
137 | //-------------------------------------------------------
|
||
138 | // Statics.
|
||
139 | //
|
||
140 | /* package */ static TopologicalEdition_Default.TopologicalEdition_FirstPoint FirstPoint; |
||
141 | /* package */ static TopologicalEdition_Default.TopologicalEdition_WithSelectedFeatures WithSelectedFeatures; |
||
142 | /* package */ static TopologicalEdition_Default.TopologicalEdition_SecondPoint SecondPoint; |
||
143 | /* package */ static TopologicalEdition_Default.TopologicalEdition_WithHandlers WithHandlers; |
||
144 | private static TopologicalEdition_Default Default; |
||
145 | |||
146 | static
|
||
147 | { |
||
148 | FirstPoint = new TopologicalEdition_Default.TopologicalEdition_FirstPoint("TopologicalEdition.FirstPoint", 0); |
||
149 | WithSelectedFeatures = new TopologicalEdition_Default.TopologicalEdition_WithSelectedFeatures("TopologicalEdition.WithSelectedFeatures", 1); |
||
150 | SecondPoint = new TopologicalEdition_Default.TopologicalEdition_SecondPoint("TopologicalEdition.SecondPoint", 2); |
||
151 | WithHandlers = new TopologicalEdition_Default.TopologicalEdition_WithHandlers("TopologicalEdition.WithHandlers", 3); |
||
152 | Default = new TopologicalEdition_Default("TopologicalEdition.Default", -1); |
||
153 | } |
||
154 | |||
155 | } |
||
156 | |||
157 | protected static class TopologicalEdition_Default |
||
158 | extends TopologicalEditVertexCADToolState
|
||
159 | { |
||
160 | //-----------------------------------------------------------
|
||
161 | // Member methods.
|
||
162 | //
|
||
163 | |||
164 | protected TopologicalEdition_Default(String name, int id) |
||
165 | { |
||
166 | super (name, id);
|
||
167 | } |
||
168 | |||
169 | protected void addOption(TopologicalEditVertexCADToolContext context, String s) |
||
170 | { |
||
171 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
172 | |||
173 | if (s.equals("")) |
||
174 | { |
||
175 | boolean loopbackFlag =
|
||
176 | context.getState().getName().equals( |
||
177 | TopologicalEdition.FirstPoint.getName()); |
||
178 | |||
179 | if (loopbackFlag == false) |
||
180 | { |
||
181 | (context.getState()).Exit(context); |
||
182 | } |
||
183 | |||
184 | context.clearState(); |
||
185 | try
|
||
186 | { |
||
187 | ctxt.restorePreviousTool(); |
||
188 | ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection")); |
||
189 | ctxt.setDescription(new String[]{"cancel"}); |
||
190 | ctxt.end(); |
||
191 | } |
||
192 | finally
|
||
193 | { |
||
194 | context.setState(TopologicalEdition.FirstPoint); |
||
195 | |||
196 | if (loopbackFlag == false) |
||
197 | { |
||
198 | (context.getState()).Entry(context); |
||
199 | } |
||
200 | |||
201 | } |
||
202 | } |
||
203 | else if (s.equals(PluginServices.getText(this,"cancel"))) |
||
204 | { |
||
205 | boolean loopbackFlag =
|
||
206 | context.getState().getName().equals( |
||
207 | TopologicalEdition.FirstPoint.getName()); |
||
208 | |||
209 | if (loopbackFlag == false) |
||
210 | { |
||
211 | (context.getState()).Exit(context); |
||
212 | } |
||
213 | |||
214 | context.clearState(); |
||
215 | try
|
||
216 | { |
||
217 | ctxt.end(); |
||
218 | } |
||
219 | finally
|
||
220 | { |
||
221 | context.setState(TopologicalEdition.FirstPoint); |
||
222 | |||
223 | if (loopbackFlag == false) |
||
224 | { |
||
225 | (context.getState()).Entry(context); |
||
226 | } |
||
227 | |||
228 | } |
||
229 | } |
||
230 | else
|
||
231 | { |
||
232 | boolean loopbackFlag =
|
||
233 | context.getState().getName().equals( |
||
234 | TopologicalEdition.FirstPoint.getName()); |
||
235 | |||
236 | if (loopbackFlag == false) |
||
237 | { |
||
238 | (context.getState()).Exit(context); |
||
239 | } |
||
240 | |||
241 | context.clearState(); |
||
242 | try
|
||
243 | { |
||
244 | ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
||
245 | } |
||
246 | finally
|
||
247 | { |
||
248 | context.setState(TopologicalEdition.FirstPoint); |
||
249 | |||
250 | if (loopbackFlag == false) |
||
251 | { |
||
252 | (context.getState()).Entry(context); |
||
253 | } |
||
254 | |||
255 | } |
||
256 | } |
||
257 | |||
258 | return;
|
||
259 | } |
||
260 | |||
261 | protected void addValue(TopologicalEditVertexCADToolContext context, double d) |
||
262 | { |
||
263 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
264 | |||
265 | boolean loopbackFlag =
|
||
266 | context.getState().getName().equals( |
||
267 | TopologicalEdition.FirstPoint.getName()); |
||
268 | |||
269 | if (loopbackFlag == false) |
||
270 | { |
||
271 | (context.getState()).Exit(context); |
||
272 | } |
||
273 | |||
274 | context.clearState(); |
||
275 | try
|
||
276 | { |
||
277 | ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
||
278 | } |
||
279 | finally
|
||
280 | { |
||
281 | context.setState(TopologicalEdition.FirstPoint); |
||
282 | |||
283 | if (loopbackFlag == false) |
||
284 | { |
||
285 | (context.getState()).Entry(context); |
||
286 | } |
||
287 | |||
288 | } |
||
289 | return;
|
||
290 | } |
||
291 | |||
292 | protected void addPoint(TopologicalEditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
||
293 | { |
||
294 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
295 | |||
296 | boolean loopbackFlag =
|
||
297 | context.getState().getName().equals( |
||
298 | TopologicalEdition.FirstPoint.getName()); |
||
299 | |||
300 | if (loopbackFlag == false) |
||
301 | { |
||
302 | (context.getState()).Exit(context); |
||
303 | } |
||
304 | |||
305 | context.clearState(); |
||
306 | try
|
||
307 | { |
||
308 | ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
||
309 | } |
||
310 | finally
|
||
311 | { |
||
312 | context.setState(TopologicalEdition.FirstPoint); |
||
313 | |||
314 | if (loopbackFlag == false) |
||
315 | { |
||
316 | (context.getState()).Entry(context); |
||
317 | } |
||
318 | |||
319 | } |
||
320 | return;
|
||
321 | } |
||
322 | |||
323 | //-----------------------------------------------------------
|
||
324 | // Inner classse.
|
||
325 | //
|
||
326 | |||
327 | |||
328 | private static final class TopologicalEdition_FirstPoint |
||
329 | extends TopologicalEdition_Default
|
||
330 | { |
||
331 | //-------------------------------------------------------
|
||
332 | // Member methods.
|
||
333 | //
|
||
334 | |||
335 | private TopologicalEdition_FirstPoint(String name, int id) |
||
336 | { |
||
337 | super (name, id);
|
||
338 | } |
||
339 | |||
340 | protected void Entry(TopologicalEditVertexCADToolContext context) |
||
341 | { |
||
342 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
343 | |||
344 | ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection")); |
||
345 | ctxt.setDescription(new String[]{"cancel"}); |
||
346 | return;
|
||
347 | } |
||
348 | |||
349 | protected void addPoint(TopologicalEditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
||
350 | { |
||
351 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
352 | |||
353 | if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && |
||
354 | ctxt.selectFeatures(pointX,pointY, event) && |
||
355 | ctxt.getNextState().equals("TopologicalEdition.SecondPoint"))
|
||
356 | { |
||
357 | |||
358 | (context.getState()).Exit(context); |
||
359 | context.clearState(); |
||
360 | try
|
||
361 | { |
||
362 | ctxt.setQuestion(PluginServices.getText(this,"insert_second_point")); |
||
363 | ctxt.setDescription(new String[]{"cancel"}); |
||
364 | ctxt.addPoint(pointX, pointY, event); |
||
365 | } |
||
366 | finally
|
||
367 | { |
||
368 | context.setState(TopologicalEdition.SecondPoint); |
||
369 | (context.getState()).Entry(context); |
||
370 | } |
||
371 | } |
||
372 | else if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && |
||
373 | ctxt.getNextState().equals("TopologicalEdition.WithSelectedFeatures"))
|
||
374 | { |
||
375 | |||
376 | (context.getState()).Exit(context); |
||
377 | context.clearState(); |
||
378 | try
|
||
379 | { |
||
380 | ctxt.setQuestion(PluginServices.getText(this,"select_handlers")); |
||
381 | ctxt.setDescription(new String[]{"cancel"}); |
||
382 | ctxt.addPoint(pointX, pointY, event); |
||
383 | ctxt.end(); |
||
384 | } |
||
385 | finally
|
||
386 | { |
||
387 | context.setState(TopologicalEdition.WithSelectedFeatures); |
||
388 | (context.getState()).Entry(context); |
||
389 | } |
||
390 | } |
||
391 | else if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && |
||
392 | ctxt.getNextState().equals("TopologicalEdition.WithHandlers"))
|
||
393 | { |
||
394 | |||
395 | (context.getState()).Exit(context); |
||
396 | context.clearState(); |
||
397 | try
|
||
398 | { |
||
399 | ctxt.setQuestion(PluginServices.getText(this,"select_handlers")); |
||
400 | ctxt.setDescription(new String[]{"cancel"}); |
||
401 | ctxt.addPoint(pointX, pointY, event); |
||
402 | ctxt.refresh(); |
||
403 | } |
||
404 | finally
|
||
405 | { |
||
406 | context.setState(TopologicalEdition.WithHandlers); |
||
407 | (context.getState()).Entry(context); |
||
408 | } |
||
409 | } else
|
||
410 | { |
||
411 | super.addPoint(context, pointX, pointY, event);
|
||
412 | } |
||
413 | |||
414 | return;
|
||
415 | } |
||
416 | |||
417 | //-------------------------------------------------------
|
||
418 | // Member data.
|
||
419 | //
|
||
420 | } |
||
421 | |||
422 | private static final class TopologicalEdition_WithSelectedFeatures |
||
423 | extends TopologicalEdition_Default
|
||
424 | { |
||
425 | //-------------------------------------------------------
|
||
426 | // Member methods.
|
||
427 | //
|
||
428 | |||
429 | private TopologicalEdition_WithSelectedFeatures(String name, int id) |
||
430 | { |
||
431 | super (name, id);
|
||
432 | } |
||
433 | |||
434 | protected void addOption(TopologicalEditVertexCADToolContext context, String s) |
||
435 | { |
||
436 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
437 | |||
438 | |||
439 | (context.getState()).Exit(context); |
||
440 | context.clearState(); |
||
441 | try
|
||
442 | { |
||
443 | ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection")); |
||
444 | ctxt.setDescription(new String[]{"cancel"}); |
||
445 | ctxt.setType(s); |
||
446 | } |
||
447 | finally
|
||
448 | { |
||
449 | context.setState(TopologicalEdition.FirstPoint); |
||
450 | (context.getState()).Entry(context); |
||
451 | } |
||
452 | return;
|
||
453 | } |
||
454 | |||
455 | protected void addPoint(TopologicalEditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
||
456 | { |
||
457 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
458 | |||
459 | if (ctxt.selectHandlers(pointX, pointY, event)>0) |
||
460 | { |
||
461 | |||
462 | (context.getState()).Exit(context); |
||
463 | context.clearState(); |
||
464 | try
|
||
465 | { |
||
466 | ctxt.setQuestion(PluginServices.getText(this,"insert_destination_point")); |
||
467 | ctxt.setDescription(new String[]{"cancel"}); |
||
468 | ctxt.addPoint(pointX, pointY, event); |
||
469 | ctxt.refresh(); |
||
470 | } |
||
471 | finally
|
||
472 | { |
||
473 | context.setState(TopologicalEdition.WithHandlers); |
||
474 | (context.getState()).Entry(context); |
||
475 | } |
||
476 | } |
||
477 | else if (ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("TopologicalEdition.WithSelectedFeatures")) |
||
478 | { |
||
479 | TopologicalEditVertexCADToolState endState = context.getState(); |
||
480 | |||
481 | context.clearState(); |
||
482 | try
|
||
483 | { |
||
484 | ctxt.setQuestion(PluginServices.getText(this,"select_handlers")); |
||
485 | ctxt.setDescription(new String[]{"cancel"}); |
||
486 | ctxt.addPoint(pointX, pointY, event); |
||
487 | } |
||
488 | finally
|
||
489 | { |
||
490 | context.setState(endState); |
||
491 | } |
||
492 | } |
||
493 | else
|
||
494 | { |
||
495 | |||
496 | (context.getState()).Exit(context); |
||
497 | context.clearState(); |
||
498 | try
|
||
499 | { |
||
500 | ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection")); |
||
501 | ctxt.setDescription(new String[]{"cancel"}); |
||
502 | ctxt.addPoint(pointX, pointY, event); |
||
503 | } |
||
504 | finally
|
||
505 | { |
||
506 | context.setState(TopologicalEdition.FirstPoint); |
||
507 | (context.getState()).Entry(context); |
||
508 | } |
||
509 | } |
||
510 | |||
511 | return;
|
||
512 | } |
||
513 | |||
514 | //-------------------------------------------------------
|
||
515 | // Member data.
|
||
516 | //
|
||
517 | } |
||
518 | |||
519 | private static final class TopologicalEdition_SecondPoint |
||
520 | extends TopologicalEdition_Default
|
||
521 | { |
||
522 | //-------------------------------------------------------
|
||
523 | // Member methods.
|
||
524 | //
|
||
525 | |||
526 | private TopologicalEdition_SecondPoint(String name, int id) |
||
527 | { |
||
528 | super (name, id);
|
||
529 | } |
||
530 | |||
531 | protected void addOption(TopologicalEditVertexCADToolContext context, String s) |
||
532 | { |
||
533 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
534 | |||
535 | |||
536 | (context.getState()).Exit(context); |
||
537 | context.clearState(); |
||
538 | try
|
||
539 | { |
||
540 | ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection")); |
||
541 | ctxt.setDescription(new String[]{"cancel"}); |
||
542 | ctxt.setType(s); |
||
543 | } |
||
544 | finally
|
||
545 | { |
||
546 | context.setState(TopologicalEdition.FirstPoint); |
||
547 | (context.getState()).Entry(context); |
||
548 | } |
||
549 | return;
|
||
550 | } |
||
551 | |||
552 | protected void addPoint(TopologicalEditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
||
553 | { |
||
554 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
555 | |||
556 | if (ctxt.selectWithSecondPoint(pointX,pointY, event) > 0) |
||
557 | { |
||
558 | |||
559 | (context.getState()).Exit(context); |
||
560 | context.clearState(); |
||
561 | try
|
||
562 | { |
||
563 | ctxt.setQuestion(PluginServices.getText(this,"select_handlers")); |
||
564 | ctxt.setDescription(new String[]{"cancel"}); |
||
565 | ctxt.addPoint(pointX, pointY, event); |
||
566 | ctxt.end(); |
||
567 | } |
||
568 | finally
|
||
569 | { |
||
570 | context.setState(TopologicalEdition.WithSelectedFeatures); |
||
571 | (context.getState()).Entry(context); |
||
572 | } |
||
573 | } |
||
574 | else
|
||
575 | { |
||
576 | |||
577 | (context.getState()).Exit(context); |
||
578 | context.clearState(); |
||
579 | try
|
||
580 | { |
||
581 | ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection")); |
||
582 | ctxt.setDescription(new String[]{"cancel"}); |
||
583 | ctxt.addPoint(pointX, pointY, event); |
||
584 | } |
||
585 | finally
|
||
586 | { |
||
587 | context.setState(TopologicalEdition.FirstPoint); |
||
588 | (context.getState()).Entry(context); |
||
589 | } |
||
590 | } |
||
591 | |||
592 | return;
|
||
593 | } |
||
594 | |||
595 | //-------------------------------------------------------
|
||
596 | // Member data.
|
||
597 | //
|
||
598 | } |
||
599 | |||
600 | private static final class TopologicalEdition_WithHandlers |
||
601 | extends TopologicalEdition_Default
|
||
602 | { |
||
603 | //-------------------------------------------------------
|
||
604 | // Member methods.
|
||
605 | //
|
||
606 | |||
607 | private TopologicalEdition_WithHandlers(String name, int id) |
||
608 | { |
||
609 | super (name, id);
|
||
610 | } |
||
611 | |||
612 | protected void addPoint(TopologicalEditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
||
613 | { |
||
614 | TopologicalEditVertexCADTool ctxt = context.getOwner(); |
||
615 | |||
616 | |||
617 | (context.getState()).Exit(context); |
||
618 | context.clearState(); |
||
619 | try
|
||
620 | { |
||
621 | ctxt.setQuestion(PluginServices.getText(this,"select_handlers")); |
||
622 | ctxt.setDescription(new String[]{"cancel"}); |
||
623 | ctxt.addPoint(pointX, pointY, event); |
||
624 | ctxt.refresh(); |
||
625 | } |
||
626 | finally
|
||
627 | { |
||
628 | context.setState(TopologicalEdition.WithSelectedFeatures); |
||
629 | (context.getState()).Entry(context); |
||
630 | } |
||
631 | return;
|
||
632 | } |
||
633 | |||
634 | //-------------------------------------------------------
|
||
635 | // Member data.
|
||
636 | //
|
||
637 | } |
||
638 | |||
639 | //-----------------------------------------------------------
|
||
640 | // Member data.
|
||
641 | //
|
||
642 | } |
||
643 | } |