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 / PolylineCADToolContext.java @ 40557
History | View | Annotate | Download (27.2 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.PolylineCADTool; |
||
35 | |||
36 | |||
37 | public final class PolylineCADToolContext |
||
38 | extends statemap.FSMContext
|
||
39 | { |
||
40 | //---------------------------------------------------------------
|
||
41 | // Member methods.
|
||
42 | //
|
||
43 | |||
44 | public PolylineCADToolContext(PolylineCADTool owner)
|
||
45 | { |
||
46 | super();
|
||
47 | |||
48 | _owner = owner; |
||
49 | setState(Polyline.FirstPoint); |
||
50 | Polyline.FirstPoint.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 void endPoint(double pointX, double pointY, InputEvent event) |
||
78 | { |
||
79 | _transition = "endPoint";
|
||
80 | getState().endPoint(this, pointX, pointY, event);
|
||
81 | _transition = "";
|
||
82 | return;
|
||
83 | } |
||
84 | |||
85 | public PolylineCADToolState getState()
|
||
86 | throws statemap.StateUndefinedException
|
||
87 | { |
||
88 | if (_state == null) |
||
89 | { |
||
90 | throw(
|
||
91 | new statemap.StateUndefinedException());
|
||
92 | } |
||
93 | |||
94 | return ((PolylineCADToolState) _state);
|
||
95 | } |
||
96 | |||
97 | protected PolylineCADTool getOwner()
|
||
98 | { |
||
99 | return (_owner);
|
||
100 | } |
||
101 | |||
102 | //---------------------------------------------------------------
|
||
103 | // Member data.
|
||
104 | //
|
||
105 | |||
106 | transient private PolylineCADTool _owner; |
||
107 | |||
108 | //---------------------------------------------------------------
|
||
109 | // Inner classes.
|
||
110 | //
|
||
111 | |||
112 | public static abstract class PolylineCADToolState |
||
113 | extends statemap.State
|
||
114 | { |
||
115 | //-----------------------------------------------------------
|
||
116 | // Member methods.
|
||
117 | //
|
||
118 | |||
119 | protected PolylineCADToolState(String name, int id) |
||
120 | { |
||
121 | super (name, id);
|
||
122 | } |
||
123 | |||
124 | protected void Entry(PolylineCADToolContext context) {} |
||
125 | protected void Exit(PolylineCADToolContext context) {} |
||
126 | |||
127 | protected void addOption(PolylineCADToolContext context, String s) |
||
128 | { |
||
129 | Default(context); |
||
130 | } |
||
131 | |||
132 | protected void addPoint(PolylineCADToolContext context, double pointX, double pointY, InputEvent event) |
||
133 | { |
||
134 | Default(context); |
||
135 | } |
||
136 | |||
137 | protected void addValue(PolylineCADToolContext context, double d) |
||
138 | { |
||
139 | Default(context); |
||
140 | } |
||
141 | |||
142 | protected void endPoint(PolylineCADToolContext context, double pointX, double pointY, InputEvent event) |
||
143 | { |
||
144 | Default(context); |
||
145 | } |
||
146 | |||
147 | protected void Default(PolylineCADToolContext context) |
||
148 | { |
||
149 | throw (
|
||
150 | new statemap.TransitionUndefinedException(
|
||
151 | "State: " +
|
||
152 | context.getState().getName() + |
||
153 | ", Transition: " +
|
||
154 | context.getTransition())); |
||
155 | } |
||
156 | |||
157 | //-----------------------------------------------------------
|
||
158 | // Member data.
|
||
159 | //
|
||
160 | } |
||
161 | |||
162 | /* package */ static abstract class Polyline |
||
163 | { |
||
164 | //-----------------------------------------------------------
|
||
165 | // Member methods.
|
||
166 | //
|
||
167 | |||
168 | //-----------------------------------------------------------
|
||
169 | // Member data.
|
||
170 | //
|
||
171 | |||
172 | //-------------------------------------------------------
|
||
173 | // Statics.
|
||
174 | //
|
||
175 | /* package */ static Polyline_Default.Polyline_FirstPoint FirstPoint; |
||
176 | /* package */ static Polyline_Default.Polyline_NextPointOrArcOrClose NextPointOrArcOrClose; |
||
177 | /* package */ static Polyline_Default.Polyline_NextPointOrLineOrClose NextPointOrLineOrClose; |
||
178 | private static Polyline_Default Default; |
||
179 | |||
180 | static
|
||
181 | { |
||
182 | FirstPoint = new Polyline_Default.Polyline_FirstPoint("Polyline.FirstPoint", 0); |
||
183 | NextPointOrArcOrClose = new Polyline_Default.Polyline_NextPointOrArcOrClose("Polyline.NextPointOrArcOrClose", 1); |
||
184 | NextPointOrLineOrClose = new Polyline_Default.Polyline_NextPointOrLineOrClose("Polyline.NextPointOrLineOrClose", 2); |
||
185 | Default = new Polyline_Default("Polyline.Default", -1); |
||
186 | } |
||
187 | |||
188 | } |
||
189 | |||
190 | protected static class Polyline_Default |
||
191 | extends PolylineCADToolState
|
||
192 | { |
||
193 | //-----------------------------------------------------------
|
||
194 | // Member methods.
|
||
195 | //
|
||
196 | |||
197 | protected Polyline_Default(String name, int id) |
||
198 | { |
||
199 | super (name, id);
|
||
200 | } |
||
201 | |||
202 | protected void addOption(PolylineCADToolContext context, String s) |
||
203 | { |
||
204 | PolylineCADTool ctxt = context.getOwner(); |
||
205 | |||
206 | if (s.equals(PluginServices.getText(this,"cancel"))) |
||
207 | { |
||
208 | boolean loopbackFlag =
|
||
209 | context.getState().getName().equals( |
||
210 | Polyline.FirstPoint.getName()); |
||
211 | |||
212 | if (loopbackFlag == false) |
||
213 | { |
||
214 | (context.getState()).Exit(context); |
||
215 | } |
||
216 | |||
217 | context.clearState(); |
||
218 | try
|
||
219 | { |
||
220 | ctxt.cancel(); |
||
221 | } |
||
222 | finally
|
||
223 | { |
||
224 | context.setState(Polyline.FirstPoint); |
||
225 | |||
226 | if (loopbackFlag == false) |
||
227 | { |
||
228 | (context.getState()).Entry(context); |
||
229 | } |
||
230 | |||
231 | } |
||
232 | } |
||
233 | else if (s.equals("")) |
||
234 | { |
||
235 | boolean loopbackFlag =
|
||
236 | context.getState().getName().equals( |
||
237 | Polyline.FirstPoint.getName()); |
||
238 | |||
239 | if (loopbackFlag == false) |
||
240 | { |
||
241 | (context.getState()).Exit(context); |
||
242 | } |
||
243 | |||
244 | context.clearState(); |
||
245 | try
|
||
246 | { |
||
247 | ctxt.endGeometry(); |
||
248 | } |
||
249 | finally
|
||
250 | { |
||
251 | context.setState(Polyline.FirstPoint); |
||
252 | |||
253 | if (loopbackFlag == false) |
||
254 | { |
||
255 | (context.getState()).Entry(context); |
||
256 | } |
||
257 | |||
258 | } |
||
259 | } |
||
260 | else
|
||
261 | { |
||
262 | boolean loopbackFlag =
|
||
263 | context.getState().getName().equals( |
||
264 | Polyline.FirstPoint.getName()); |
||
265 | |||
266 | if (loopbackFlag == false) |
||
267 | { |
||
268 | (context.getState()).Exit(context); |
||
269 | } |
||
270 | |||
271 | context.clearState(); |
||
272 | try
|
||
273 | { |
||
274 | ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
||
275 | } |
||
276 | finally
|
||
277 | { |
||
278 | context.setState(Polyline.FirstPoint); |
||
279 | |||
280 | if (loopbackFlag == false) |
||
281 | { |
||
282 | (context.getState()).Entry(context); |
||
283 | } |
||
284 | |||
285 | } |
||
286 | } |
||
287 | |||
288 | return;
|
||
289 | } |
||
290 | |||
291 | protected void addValue(PolylineCADToolContext context, double d) |
||
292 | { |
||
293 | PolylineCADTool ctxt = context.getOwner(); |
||
294 | |||
295 | boolean loopbackFlag =
|
||
296 | context.getState().getName().equals( |
||
297 | Polyline.FirstPoint.getName()); |
||
298 | |||
299 | if (loopbackFlag == false) |
||
300 | { |
||
301 | (context.getState()).Exit(context); |
||
302 | } |
||
303 | |||
304 | context.clearState(); |
||
305 | try
|
||
306 | { |
||
307 | ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
||
308 | } |
||
309 | finally
|
||
310 | { |
||
311 | context.setState(Polyline.FirstPoint); |
||
312 | |||
313 | if (loopbackFlag == false) |
||
314 | { |
||
315 | (context.getState()).Entry(context); |
||
316 | } |
||
317 | |||
318 | } |
||
319 | return;
|
||
320 | } |
||
321 | |||
322 | protected void addPoint(PolylineCADToolContext context, double pointX, double pointY, InputEvent event) |
||
323 | { |
||
324 | PolylineCADTool ctxt = context.getOwner(); |
||
325 | |||
326 | boolean loopbackFlag =
|
||
327 | context.getState().getName().equals( |
||
328 | Polyline.FirstPoint.getName()); |
||
329 | |||
330 | if (loopbackFlag == false) |
||
331 | { |
||
332 | (context.getState()).Exit(context); |
||
333 | } |
||
334 | |||
335 | context.clearState(); |
||
336 | try
|
||
337 | { |
||
338 | ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
||
339 | } |
||
340 | finally
|
||
341 | { |
||
342 | context.setState(Polyline.FirstPoint); |
||
343 | |||
344 | if (loopbackFlag == false) |
||
345 | { |
||
346 | (context.getState()).Entry(context); |
||
347 | } |
||
348 | |||
349 | } |
||
350 | return;
|
||
351 | } |
||
352 | |||
353 | protected void endPoint(PolylineCADToolContext context, double pointX, double pointY, InputEvent event) |
||
354 | { |
||
355 | PolylineCADTool ctxt = context.getOwner(); |
||
356 | |||
357 | boolean loopbackFlag =
|
||
358 | context.getState().getName().equals( |
||
359 | Polyline.FirstPoint.getName()); |
||
360 | |||
361 | if (loopbackFlag == false) |
||
362 | { |
||
363 | (context.getState()).Exit(context); |
||
364 | } |
||
365 | |||
366 | context.clearState(); |
||
367 | try
|
||
368 | { |
||
369 | ctxt.addPoint(pointX, pointY, event); |
||
370 | ctxt.endGeometry(); |
||
371 | } |
||
372 | finally
|
||
373 | { |
||
374 | context.setState(Polyline.FirstPoint); |
||
375 | |||
376 | if (loopbackFlag == false) |
||
377 | { |
||
378 | (context.getState()).Entry(context); |
||
379 | } |
||
380 | |||
381 | } |
||
382 | return;
|
||
383 | } |
||
384 | |||
385 | //-----------------------------------------------------------
|
||
386 | // Inner classse.
|
||
387 | //
|
||
388 | |||
389 | |||
390 | private static final class Polyline_FirstPoint |
||
391 | extends Polyline_Default
|
||
392 | { |
||
393 | //-------------------------------------------------------
|
||
394 | // Member methods.
|
||
395 | //
|
||
396 | |||
397 | private Polyline_FirstPoint(String name, int id) |
||
398 | { |
||
399 | super (name, id);
|
||
400 | } |
||
401 | |||
402 | protected void Entry(PolylineCADToolContext context) |
||
403 | { |
||
404 | PolylineCADTool ctxt = context.getOwner(); |
||
405 | |||
406 | ctxt.setQuestion(PluginServices.getText(this,"insert_first_point")); |
||
407 | ctxt.setDescription(new String[]{"cancel"}); |
||
408 | return;
|
||
409 | } |
||
410 | |||
411 | protected void addPoint(PolylineCADToolContext context, double pointX, double pointY, InputEvent event) |
||
412 | { |
||
413 | PolylineCADTool ctxt = context.getOwner(); |
||
414 | |||
415 | if (ctxt.isPolygonLayer())
|
||
416 | { |
||
417 | |||
418 | (context.getState()).Exit(context); |
||
419 | context.clearState(); |
||
420 | try
|
||
421 | { |
||
422 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
423 | PluginServices.getText(this,"arc")+ |
||
424 | "["+PluginServices.getText(this,"PolylineCADTool.arc")+"], "+ |
||
425 | PluginServices.getText(this,"cad.or")+" "+ |
||
426 | PluginServices.getText(this,"end")+ |
||
427 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
428 | ctxt.setDescription(new String[]{"inter_arc", "terminate", "cancel"}); |
||
429 | ctxt.addPoint(pointX, pointY, event); |
||
430 | } |
||
431 | finally
|
||
432 | { |
||
433 | context.setState(Polyline.NextPointOrArcOrClose); |
||
434 | (context.getState()).Entry(context); |
||
435 | } |
||
436 | } |
||
437 | else
|
||
438 | { |
||
439 | |||
440 | (context.getState()).Exit(context); |
||
441 | context.clearState(); |
||
442 | try
|
||
443 | { |
||
444 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
445 | PluginServices.getText(this,"arc")+ |
||
446 | "["+PluginServices.getText(this,"PolylineCADTool.arc")+"], "+ |
||
447 | PluginServices.getText(this,"close_polyline")+ |
||
448 | "["+PluginServices.getText(this,"PolylineCADTool.close_polyline")+"], "+ |
||
449 | PluginServices.getText(this,"cad.or")+" "+ |
||
450 | PluginServices.getText(this,"end")+ |
||
451 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
452 | ctxt.setDescription(new String[]{"inter_arc", "close_polyline", "terminate", "cancel"}); |
||
453 | ctxt.addPoint(pointX, pointY, event); |
||
454 | } |
||
455 | finally
|
||
456 | { |
||
457 | context.setState(Polyline.NextPointOrArcOrClose); |
||
458 | (context.getState()).Entry(context); |
||
459 | } |
||
460 | } |
||
461 | |||
462 | return;
|
||
463 | } |
||
464 | |||
465 | //-------------------------------------------------------
|
||
466 | // Member data.
|
||
467 | //
|
||
468 | } |
||
469 | |||
470 | private static final class Polyline_NextPointOrArcOrClose |
||
471 | extends Polyline_Default
|
||
472 | { |
||
473 | //-------------------------------------------------------
|
||
474 | // Member methods.
|
||
475 | //
|
||
476 | |||
477 | private Polyline_NextPointOrArcOrClose(String name, int id) |
||
478 | { |
||
479 | super (name, id);
|
||
480 | } |
||
481 | |||
482 | protected void addOption(PolylineCADToolContext context, String s) |
||
483 | { |
||
484 | PolylineCADTool ctxt = context.getOwner(); |
||
485 | |||
486 | if (ctxt.isPolygonLayer() && (s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.arc")) || s.equals(PluginServices.getText(this,"inter_arc")))) |
||
487 | { |
||
488 | |||
489 | (context.getState()).Exit(context); |
||
490 | context.clearState(); |
||
491 | try
|
||
492 | { |
||
493 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
494 | PluginServices.getText(this,"line")+ |
||
495 | "["+PluginServices.getText(this,"PolylineCADTool.line")+"], "+ |
||
496 | PluginServices.getText(this,"cad.or")+" "+ |
||
497 | PluginServices.getText(this,"end")+ |
||
498 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
499 | ctxt.setDescription(new String[]{"inter_line", "terminate", "cancel"}); |
||
500 | ctxt.addOption(s); |
||
501 | } |
||
502 | finally
|
||
503 | { |
||
504 | context.setState(Polyline.NextPointOrLineOrClose); |
||
505 | (context.getState()).Entry(context); |
||
506 | } |
||
507 | } |
||
508 | else if (s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.arc")) || s.equals(PluginServices.getText(this,"inter_arc"))) |
||
509 | { |
||
510 | |||
511 | (context.getState()).Exit(context); |
||
512 | context.clearState(); |
||
513 | try
|
||
514 | { |
||
515 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
516 | PluginServices.getText(this,"line")+ |
||
517 | "["+PluginServices.getText(this,"PolylineCADTool.line")+"], "+ |
||
518 | PluginServices.getText(this,"close_polyline")+ |
||
519 | "["+PluginServices.getText(this,"PolylineCADTool.close_polyline")+"], "+ |
||
520 | PluginServices.getText(this,"cad.or")+" "+ |
||
521 | PluginServices.getText(this,"end")+ |
||
522 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
523 | ctxt.setDescription(new String[]{"inter_line", "close_polyline", "terminate", "cancel"}); |
||
524 | ctxt.addOption(s); |
||
525 | } |
||
526 | finally
|
||
527 | { |
||
528 | context.setState(Polyline.NextPointOrLineOrClose); |
||
529 | (context.getState()).Entry(context); |
||
530 | } |
||
531 | } |
||
532 | else if (s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.close_polyline")) || s.equals(PluginServices.getText(this,"close_polyline"))) |
||
533 | { |
||
534 | |||
535 | (context.getState()).Exit(context); |
||
536 | context.clearState(); |
||
537 | try
|
||
538 | { |
||
539 | ctxt.addOption(s); |
||
540 | ctxt.closeGeometry(); |
||
541 | ctxt.endGeometry(); |
||
542 | ctxt.end(); |
||
543 | } |
||
544 | finally
|
||
545 | { |
||
546 | context.setState(Polyline.FirstPoint); |
||
547 | (context.getState()).Entry(context); |
||
548 | } |
||
549 | } |
||
550 | else if ((s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.end")) || s.equals(PluginServices.getText(this,"terminate"))) && ctxt.getLinesCount()!=0 ) |
||
551 | { |
||
552 | |||
553 | (context.getState()).Exit(context); |
||
554 | context.clearState(); |
||
555 | try
|
||
556 | { |
||
557 | ctxt.addOption(s); |
||
558 | ctxt.endGeometry(); |
||
559 | ctxt.end(); |
||
560 | } |
||
561 | finally
|
||
562 | { |
||
563 | context.setState(Polyline.FirstPoint); |
||
564 | (context.getState()).Entry(context); |
||
565 | } |
||
566 | } |
||
567 | else if (!s.equals(PluginServices.getText(this,"cancel"))) |
||
568 | { |
||
569 | |||
570 | // No actions.
|
||
571 | } else
|
||
572 | { |
||
573 | super.addOption(context, s);
|
||
574 | } |
||
575 | |||
576 | return;
|
||
577 | } |
||
578 | |||
579 | protected void addPoint(PolylineCADToolContext context, double pointX, double pointY, InputEvent event) |
||
580 | { |
||
581 | PolylineCADTool ctxt = context.getOwner(); |
||
582 | |||
583 | if (ctxt.isPolygonLayer())
|
||
584 | { |
||
585 | PolylineCADToolState endState = context.getState(); |
||
586 | |||
587 | context.clearState(); |
||
588 | try
|
||
589 | { |
||
590 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
591 | PluginServices.getText(this,"arc")+ |
||
592 | "["+PluginServices.getText(this,"PolylineCADTool.arc")+"], "+ |
||
593 | PluginServices.getText(this,"cad.or")+" "+ |
||
594 | PluginServices.getText(this,"end")+ |
||
595 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
596 | ctxt.setDescription(new String[]{"inter_arc", "terminate", "cancel"}); |
||
597 | ctxt.addPoint(pointX, pointY, event); |
||
598 | } |
||
599 | finally
|
||
600 | { |
||
601 | context.setState(endState); |
||
602 | } |
||
603 | } |
||
604 | else
|
||
605 | { |
||
606 | PolylineCADToolState endState = context.getState(); |
||
607 | |||
608 | context.clearState(); |
||
609 | try
|
||
610 | { |
||
611 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
612 | PluginServices.getText(this,"arc")+ |
||
613 | "["+PluginServices.getText(this,"PolylineCADTool.arc")+"], "+ |
||
614 | PluginServices.getText(this,"close_polyline")+ |
||
615 | "["+PluginServices.getText(this,"PolylineCADTool.close_polyline")+"], "+ |
||
616 | PluginServices.getText(this,"cad.or")+" "+ |
||
617 | PluginServices.getText(this,"end")+ |
||
618 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
619 | ctxt.setDescription(new String[]{"inter_arc", "close_polyline", "terminate", "cancel"}); |
||
620 | ctxt.addPoint(pointX, pointY, event); |
||
621 | } |
||
622 | finally
|
||
623 | { |
||
624 | context.setState(endState); |
||
625 | } |
||
626 | } |
||
627 | |||
628 | return;
|
||
629 | } |
||
630 | |||
631 | //-------------------------------------------------------
|
||
632 | // Member data.
|
||
633 | //
|
||
634 | } |
||
635 | |||
636 | private static final class Polyline_NextPointOrLineOrClose |
||
637 | extends Polyline_Default
|
||
638 | { |
||
639 | //-------------------------------------------------------
|
||
640 | // Member methods.
|
||
641 | //
|
||
642 | |||
643 | private Polyline_NextPointOrLineOrClose(String name, int id) |
||
644 | { |
||
645 | super (name, id);
|
||
646 | } |
||
647 | |||
648 | protected void addOption(PolylineCADToolContext context, String s) |
||
649 | { |
||
650 | PolylineCADTool ctxt = context.getOwner(); |
||
651 | |||
652 | if (ctxt.isPolygonLayer() && (s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.line")) || s.equals(PluginServices.getText(this,"inter_line")))) |
||
653 | { |
||
654 | |||
655 | (context.getState()).Exit(context); |
||
656 | context.clearState(); |
||
657 | try
|
||
658 | { |
||
659 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
660 | PluginServices.getText(this,"arc")+ |
||
661 | "["+PluginServices.getText(this,"PolylineCADTool.arc")+"], "+ |
||
662 | PluginServices.getText(this,"cad.or")+" "+ |
||
663 | PluginServices.getText(this,"end")+ |
||
664 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
665 | ctxt.setDescription(new String[]{"inter_arc", "terminate", "cancel"}); |
||
666 | ctxt.addOption(s); |
||
667 | } |
||
668 | finally
|
||
669 | { |
||
670 | context.setState(Polyline.NextPointOrArcOrClose); |
||
671 | (context.getState()).Entry(context); |
||
672 | } |
||
673 | } |
||
674 | else if (s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.line")) || s.equals(PluginServices.getText(this,"inter_line"))) |
||
675 | { |
||
676 | |||
677 | (context.getState()).Exit(context); |
||
678 | context.clearState(); |
||
679 | try
|
||
680 | { |
||
681 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
682 | PluginServices.getText(this,"arc")+ |
||
683 | "["+PluginServices.getText(this,"PolylineCADTool.arc")+"], "+ |
||
684 | PluginServices.getText(this,"close_polyline")+ |
||
685 | "["+PluginServices.getText(this,"PolylineCADTool.close_polyline")+"], "+ |
||
686 | PluginServices.getText(this,"cad.or")+" "+ |
||
687 | PluginServices.getText(this,"end")+ |
||
688 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
689 | ctxt.setDescription(new String[]{"inter_arc", "close_polyline", "terminate", "cancel"}); |
||
690 | ctxt.addOption(s); |
||
691 | } |
||
692 | finally
|
||
693 | { |
||
694 | context.setState(Polyline.NextPointOrArcOrClose); |
||
695 | (context.getState()).Entry(context); |
||
696 | } |
||
697 | } |
||
698 | else if (s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.close_polyline")) || s.equals(PluginServices.getText(this,"close_polyline"))) |
||
699 | { |
||
700 | |||
701 | (context.getState()).Exit(context); |
||
702 | context.clearState(); |
||
703 | try
|
||
704 | { |
||
705 | ctxt.addOption(s); |
||
706 | ctxt.closeGeometry(); |
||
707 | ctxt.endGeometry(); |
||
708 | ctxt.end(); |
||
709 | } |
||
710 | finally
|
||
711 | { |
||
712 | context.setState(Polyline.FirstPoint); |
||
713 | (context.getState()).Entry(context); |
||
714 | } |
||
715 | } |
||
716 | else if ((s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.end")) || s.equals(PluginServices.getText(this,"terminate"))) && ctxt.getLinesCount()!=0) |
||
717 | { |
||
718 | |||
719 | (context.getState()).Exit(context); |
||
720 | context.clearState(); |
||
721 | try
|
||
722 | { |
||
723 | ctxt.addOption(s); |
||
724 | ctxt.endGeometry(); |
||
725 | ctxt.end(); |
||
726 | } |
||
727 | finally
|
||
728 | { |
||
729 | context.setState(Polyline.FirstPoint); |
||
730 | (context.getState()).Entry(context); |
||
731 | } |
||
732 | } |
||
733 | else if (!s.equals(PluginServices.getText(this,"cancel"))) |
||
734 | { |
||
735 | |||
736 | // No actions.
|
||
737 | } else
|
||
738 | { |
||
739 | super.addOption(context, s);
|
||
740 | } |
||
741 | |||
742 | return;
|
||
743 | } |
||
744 | |||
745 | protected void addPoint(PolylineCADToolContext context, double pointX, double pointY, InputEvent event) |
||
746 | { |
||
747 | PolylineCADTool ctxt = context.getOwner(); |
||
748 | |||
749 | if (ctxt.isPolygonLayer())
|
||
750 | { |
||
751 | PolylineCADToolState endState = context.getState(); |
||
752 | |||
753 | context.clearState(); |
||
754 | try
|
||
755 | { |
||
756 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
757 | PluginServices.getText(this,"line")+ |
||
758 | "["+PluginServices.getText(this,"PolylineCADTool.line")+"], "+ |
||
759 | PluginServices.getText(this,"cad.or")+" "+ |
||
760 | PluginServices.getText(this,"end")+ |
||
761 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
762 | ctxt.setDescription(new String[]{"inter_line", "terminate", "cancel"}); |
||
763 | ctxt.addPoint(pointX, pointY, event); |
||
764 | } |
||
765 | finally
|
||
766 | { |
||
767 | context.setState(endState); |
||
768 | } |
||
769 | } |
||
770 | else
|
||
771 | { |
||
772 | PolylineCADToolState endState = context.getState(); |
||
773 | |||
774 | context.clearState(); |
||
775 | try
|
||
776 | { |
||
777 | ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+", "+ |
||
778 | PluginServices.getText(this,"line")+ |
||
779 | "["+PluginServices.getText(this,"PolylineCADTool.line")+"], "+ |
||
780 | PluginServices.getText(this,"close_polyline")+ |
||
781 | "["+PluginServices.getText(this,"PolylineCADTool.close_polyline")+"], "+ |
||
782 | PluginServices.getText(this,"cad.or")+" "+ |
||
783 | PluginServices.getText(this,"end")+ |
||
784 | "["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
||
785 | ctxt.setDescription(new String[]{"inter_line", "close_polyline", "terminate", "cancel"}); |
||
786 | ctxt.addPoint(pointX, pointY, event); |
||
787 | } |
||
788 | finally
|
||
789 | { |
||
790 | context.setState(endState); |
||
791 | } |
||
792 | } |
||
793 | |||
794 | return;
|
||
795 | } |
||
796 | |||
797 | //-------------------------------------------------------
|
||
798 | // Member data.
|
||
799 | //
|
||
800 | } |
||
801 | |||
802 | //-----------------------------------------------------------
|
||
803 | // Member data.
|
||
804 | //
|
||
805 | } |
||
806 | } |