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