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 / SplitGeometryCADToolContext.java @ 40557
History | View | Annotate | Download (13.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 |
Finite state machine, generated with fsm tool
|
27 |
(http://smc.sourceforge.net)
|
28 |
@author Alvaro Zabala
|
29 |
*/
|
30 |
|
31 |
|
32 |
package org.gvsig.editing.gui.cad.tools.smc; |
33 |
|
34 |
import java.awt.event.InputEvent; |
35 |
|
36 |
import org.gvsig.andami.PluginServices; |
37 |
import org.gvsig.editing.gui.cad.tools.SplitGeometryCADTool; |
38 |
|
39 |
|
40 |
public final class SplitGeometryCADToolContext |
41 |
extends statemap.FSMContext
|
42 |
{ |
43 |
//---------------------------------------------------------------
|
44 |
// Member methods.
|
45 |
//
|
46 |
|
47 |
public SplitGeometryCADToolContext(SplitGeometryCADTool owner)
|
48 |
{ |
49 |
super();
|
50 |
|
51 |
_owner = owner; |
52 |
setState(SplitGeometry.FirstPoint); |
53 |
SplitGeometry.FirstPoint.Entry(this);
|
54 |
} |
55 |
|
56 |
public void addOption(String s) |
57 |
{ |
58 |
_transition = "addOption";
|
59 |
getState().addOption(this, s);
|
60 |
_transition = "";
|
61 |
return;
|
62 |
} |
63 |
|
64 |
public void addPoint(double pointX, double pointY, InputEvent event) |
65 |
{ |
66 |
_transition = "addPoint";
|
67 |
getState().addPoint(this, pointX, pointY, event);
|
68 |
_transition = "";
|
69 |
return;
|
70 |
} |
71 |
|
72 |
public void addValue(double d) |
73 |
{ |
74 |
_transition = "addValue";
|
75 |
getState().addValue(this, d);
|
76 |
_transition = "";
|
77 |
return;
|
78 |
} |
79 |
|
80 |
public SplitGeometryCADToolState getState()
|
81 |
throws statemap.StateUndefinedException
|
82 |
{ |
83 |
if (_state == null) |
84 |
{ |
85 |
throw(
|
86 |
new statemap.StateUndefinedException());
|
87 |
} |
88 |
|
89 |
return ((SplitGeometryCADToolState) _state);
|
90 |
} |
91 |
|
92 |
protected SplitGeometryCADTool getOwner()
|
93 |
{ |
94 |
return (_owner);
|
95 |
} |
96 |
|
97 |
//---------------------------------------------------------------
|
98 |
// Member data.
|
99 |
//
|
100 |
|
101 |
transient private SplitGeometryCADTool _owner; |
102 |
|
103 |
//---------------------------------------------------------------
|
104 |
// Inner classes.
|
105 |
//
|
106 |
|
107 |
public static abstract class SplitGeometryCADToolState |
108 |
extends statemap.State
|
109 |
{ |
110 |
//-----------------------------------------------------------
|
111 |
// Member methods.
|
112 |
//
|
113 |
|
114 |
protected SplitGeometryCADToolState(String name, int id) |
115 |
{ |
116 |
super (name, id);
|
117 |
} |
118 |
|
119 |
protected void Entry(SplitGeometryCADToolContext context) {} |
120 |
protected void Exit(SplitGeometryCADToolContext context) {} |
121 |
|
122 |
protected void addOption(SplitGeometryCADToolContext context, String s) |
123 |
{ |
124 |
Default(context); |
125 |
} |
126 |
|
127 |
protected void addPoint(SplitGeometryCADToolContext context, double pointX, double pointY, InputEvent event) |
128 |
{ |
129 |
Default(context); |
130 |
} |
131 |
|
132 |
protected void addValue(SplitGeometryCADToolContext context, double d) |
133 |
{ |
134 |
Default(context); |
135 |
} |
136 |
|
137 |
protected void Default(SplitGeometryCADToolContext context) |
138 |
{ |
139 |
throw (
|
140 |
new statemap.TransitionUndefinedException(
|
141 |
"State: " +
|
142 |
context.getState().getName() + |
143 |
", Transition: " +
|
144 |
context.getTransition())); |
145 |
} |
146 |
|
147 |
//-----------------------------------------------------------
|
148 |
// Member data.
|
149 |
//
|
150 |
} |
151 |
|
152 |
/* package */ static abstract class SplitGeometry |
153 |
{ |
154 |
//-----------------------------------------------------------
|
155 |
// Member methods.
|
156 |
//
|
157 |
|
158 |
//-----------------------------------------------------------
|
159 |
// Member data.
|
160 |
//
|
161 |
|
162 |
//-------------------------------------------------------
|
163 |
// Statics.
|
164 |
//
|
165 |
/* package */ static SplitGeometry_Default.SplitGeometry_FirstPoint FirstPoint; |
166 |
/* package */ static SplitGeometry_Default.SplitGeometry_DigitizingLine DigitizingLine; |
167 |
private static SplitGeometry_Default Default; |
168 |
|
169 |
static
|
170 |
{ |
171 |
FirstPoint = new SplitGeometry_Default.SplitGeometry_FirstPoint("SplitGeometry.FirstPoint", 0); |
172 |
DigitizingLine = new SplitGeometry_Default.SplitGeometry_DigitizingLine("SplitGeometry.DigitizingLine", 1); |
173 |
Default = new SplitGeometry_Default("SplitGeometry.Default", -1); |
174 |
} |
175 |
|
176 |
} |
177 |
|
178 |
protected static class SplitGeometry_Default |
179 |
extends SplitGeometryCADToolState
|
180 |
{ |
181 |
//-----------------------------------------------------------
|
182 |
// Member methods.
|
183 |
//
|
184 |
|
185 |
protected SplitGeometry_Default(String name, int id) |
186 |
{ |
187 |
super (name, id);
|
188 |
} |
189 |
|
190 |
protected void addOption(SplitGeometryCADToolContext context, String s) |
191 |
{ |
192 |
SplitGeometryCADTool ctxt = context.getOwner(); |
193 |
|
194 |
if (s.equals("")) |
195 |
{ |
196 |
boolean loopbackFlag =
|
197 |
context.getState().getName().equals( |
198 |
SplitGeometry.FirstPoint.getName()); |
199 |
|
200 |
if (loopbackFlag == false) |
201 |
{ |
202 |
(context.getState()).Exit(context); |
203 |
} |
204 |
|
205 |
context.clearState(); |
206 |
try
|
207 |
{ |
208 |
ctxt.restorePreviousTool(); |
209 |
ctxt.setQuestion(PluginServices.getText(this,"insert_first_point")); |
210 |
ctxt.setDescription(new String[]{"cancel"}); |
211 |
ctxt.end(); |
212 |
} |
213 |
finally
|
214 |
{ |
215 |
context.setState(SplitGeometry.FirstPoint); |
216 |
|
217 |
if (loopbackFlag == false) |
218 |
{ |
219 |
(context.getState()).Entry(context); |
220 |
} |
221 |
|
222 |
} |
223 |
} |
224 |
else if (s.equals(PluginServices.getText(this,"cancel"))) |
225 |
{ |
226 |
boolean loopbackFlag =
|
227 |
context.getState().getName().equals( |
228 |
SplitGeometry.FirstPoint.getName()); |
229 |
|
230 |
if (loopbackFlag == false) |
231 |
{ |
232 |
(context.getState()).Exit(context); |
233 |
} |
234 |
|
235 |
context.clearState(); |
236 |
try
|
237 |
{ |
238 |
ctxt.end(); |
239 |
} |
240 |
finally
|
241 |
{ |
242 |
context.setState(SplitGeometry.FirstPoint); |
243 |
|
244 |
if (loopbackFlag == false) |
245 |
{ |
246 |
(context.getState()).Entry(context); |
247 |
} |
248 |
|
249 |
} |
250 |
} |
251 |
else
|
252 |
{ |
253 |
boolean loopbackFlag =
|
254 |
context.getState().getName().equals( |
255 |
SplitGeometry.FirstPoint.getName()); |
256 |
|
257 |
if (loopbackFlag == false) |
258 |
{ |
259 |
(context.getState()).Exit(context); |
260 |
} |
261 |
|
262 |
context.clearState(); |
263 |
try
|
264 |
{ |
265 |
ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
266 |
} |
267 |
finally
|
268 |
{ |
269 |
context.setState(SplitGeometry.FirstPoint); |
270 |
|
271 |
if (loopbackFlag == false) |
272 |
{ |
273 |
(context.getState()).Entry(context); |
274 |
} |
275 |
|
276 |
} |
277 |
} |
278 |
|
279 |
return;
|
280 |
} |
281 |
|
282 |
protected void addValue(SplitGeometryCADToolContext context, double d) |
283 |
{ |
284 |
SplitGeometryCADTool ctxt = context.getOwner(); |
285 |
|
286 |
boolean loopbackFlag =
|
287 |
context.getState().getName().equals( |
288 |
SplitGeometry.FirstPoint.getName()); |
289 |
|
290 |
if (loopbackFlag == false) |
291 |
{ |
292 |
(context.getState()).Exit(context); |
293 |
} |
294 |
|
295 |
context.clearState(); |
296 |
try
|
297 |
{ |
298 |
ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
299 |
} |
300 |
finally
|
301 |
{ |
302 |
context.setState(SplitGeometry.FirstPoint); |
303 |
|
304 |
if (loopbackFlag == false) |
305 |
{ |
306 |
(context.getState()).Entry(context); |
307 |
} |
308 |
|
309 |
} |
310 |
return;
|
311 |
} |
312 |
|
313 |
protected void addPoint(SplitGeometryCADToolContext context, double pointX, double pointY, InputEvent event) |
314 |
{ |
315 |
SplitGeometryCADTool ctxt = context.getOwner(); |
316 |
|
317 |
boolean loopbackFlag =
|
318 |
context.getState().getName().equals( |
319 |
SplitGeometry.FirstPoint.getName()); |
320 |
|
321 |
if (loopbackFlag == false) |
322 |
{ |
323 |
(context.getState()).Exit(context); |
324 |
} |
325 |
|
326 |
context.clearState(); |
327 |
try
|
328 |
{ |
329 |
ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
330 |
} |
331 |
finally
|
332 |
{ |
333 |
context.setState(SplitGeometry.FirstPoint); |
334 |
|
335 |
if (loopbackFlag == false) |
336 |
{ |
337 |
(context.getState()).Entry(context); |
338 |
} |
339 |
|
340 |
} |
341 |
return;
|
342 |
} |
343 |
|
344 |
//-----------------------------------------------------------
|
345 |
// Inner classse.
|
346 |
//
|
347 |
|
348 |
|
349 |
private static final class SplitGeometry_FirstPoint |
350 |
extends SplitGeometry_Default
|
351 |
{ |
352 |
//-------------------------------------------------------
|
353 |
// Member methods.
|
354 |
//
|
355 |
|
356 |
private SplitGeometry_FirstPoint(String name, int id) |
357 |
{ |
358 |
super (name, id);
|
359 |
} |
360 |
|
361 |
protected void Entry(SplitGeometryCADToolContext context) |
362 |
{ |
363 |
SplitGeometryCADTool ctxt = context.getOwner(); |
364 |
|
365 |
ctxt.setQuestion(PluginServices.getText(this,"insert_first_point")); |
366 |
ctxt.setDescription(new String[]{"cancel"}); |
367 |
return;
|
368 |
} |
369 |
|
370 |
protected void addPoint(SplitGeometryCADToolContext context, double pointX, double pointY, InputEvent event) |
371 |
{ |
372 |
SplitGeometryCADTool ctxt = context.getOwner(); |
373 |
|
374 |
|
375 |
(context.getState()).Exit(context); |
376 |
context.clearState(); |
377 |
try
|
378 |
{ |
379 |
ctxt.setQuestion(PluginServices.getText(this,"insert_more_points_or_finish")); |
380 |
ctxt.setDescription(new String[]{"cancel"}); |
381 |
ctxt.addPoint(pointX, pointY, event); |
382 |
} |
383 |
finally
|
384 |
{ |
385 |
context.setState(SplitGeometry.DigitizingLine); |
386 |
(context.getState()).Entry(context); |
387 |
} |
388 |
return;
|
389 |
} |
390 |
|
391 |
//-------------------------------------------------------
|
392 |
// Member data.
|
393 |
//
|
394 |
} |
395 |
|
396 |
private static final class SplitGeometry_DigitizingLine |
397 |
extends SplitGeometry_Default
|
398 |
{ |
399 |
//-------------------------------------------------------
|
400 |
// Member methods.
|
401 |
//
|
402 |
|
403 |
private SplitGeometry_DigitizingLine(String name, int id) |
404 |
{ |
405 |
super (name, id);
|
406 |
} |
407 |
|
408 |
protected void addOption(SplitGeometryCADToolContext context, String s) |
409 |
{ |
410 |
SplitGeometryCADTool ctxt = context.getOwner(); |
411 |
|
412 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"SplitGeometryCADTool.end")) || s.equalsIgnoreCase(PluginServices.getText(this,"terminate"))) |
413 |
{ |
414 |
|
415 |
(context.getState()).Exit(context); |
416 |
context.clearState(); |
417 |
try
|
418 |
{ |
419 |
ctxt.finishDigitizedLine(); |
420 |
ctxt.splitSelectedGeometryWithDigitizedLine(); |
421 |
ctxt.end(); |
422 |
} |
423 |
finally
|
424 |
{ |
425 |
context.setState(SplitGeometry.FirstPoint); |
426 |
(context.getState()).Entry(context); |
427 |
} |
428 |
} |
429 |
else
|
430 |
{ |
431 |
super.addOption(context, s);
|
432 |
} |
433 |
|
434 |
return;
|
435 |
} |
436 |
|
437 |
protected void addPoint(SplitGeometryCADToolContext context, double pointX, double pointY, InputEvent event) |
438 |
{ |
439 |
SplitGeometryCADTool ctxt = context.getOwner(); |
440 |
|
441 |
SplitGeometryCADToolState endState = context.getState(); |
442 |
|
443 |
context.clearState(); |
444 |
try
|
445 |
{ |
446 |
ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+ |
447 |
PluginServices.getText(this,"cad.or")+" "+ |
448 |
PluginServices.getText(this,"end")+ |
449 |
"["+PluginServices.getText(this,"PolylineCADTool.end")+"]"); |
450 |
ctxt.setDescription(new String[]{"inter_arc", "terminate", "cancel"}); |
451 |
ctxt.addPoint(pointX, pointY, event); |
452 |
} |
453 |
finally
|
454 |
{ |
455 |
context.setState(endState); |
456 |
} |
457 |
return;
|
458 |
} |
459 |
|
460 |
//-------------------------------------------------------
|
461 |
// Member data.
|
462 |
//
|
463 |
} |
464 |
|
465 |
//-----------------------------------------------------------
|
466 |
// Member data.
|
467 |
//
|
468 |
} |
469 |
} |