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