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