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