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