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