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