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