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