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