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 / StretchCADToolContext.java @ 40557
History | View | Annotate | Download (14.1 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.StretchCADTool; |
35 |
|
36 |
|
37 |
public final class StretchCADToolContext |
38 |
extends statemap.FSMContext
|
39 |
{ |
40 |
//---------------------------------------------------------------
|
41 |
// Member methods.
|
42 |
//
|
43 |
|
44 |
public StretchCADToolContext(StretchCADTool owner)
|
45 |
{ |
46 |
super();
|
47 |
|
48 |
_owner = owner; |
49 |
setState(Stretch.SelFirstPoint); |
50 |
Stretch.SelFirstPoint.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 StretchCADToolState getState()
|
78 |
throws statemap.StateUndefinedException
|
79 |
{ |
80 |
if (_state == null) |
81 |
{ |
82 |
throw(
|
83 |
new statemap.StateUndefinedException());
|
84 |
} |
85 |
|
86 |
return ((StretchCADToolState) _state);
|
87 |
} |
88 |
|
89 |
protected StretchCADTool getOwner()
|
90 |
{ |
91 |
return (_owner);
|
92 |
} |
93 |
|
94 |
//---------------------------------------------------------------
|
95 |
// Member data.
|
96 |
//
|
97 |
|
98 |
transient private StretchCADTool _owner; |
99 |
|
100 |
//---------------------------------------------------------------
|
101 |
// Inner classes.
|
102 |
//
|
103 |
|
104 |
public static abstract class StretchCADToolState |
105 |
extends statemap.State
|
106 |
{ |
107 |
//-----------------------------------------------------------
|
108 |
// Member methods.
|
109 |
//
|
110 |
|
111 |
protected StretchCADToolState(String name, int id) |
112 |
{ |
113 |
super (name, id);
|
114 |
} |
115 |
|
116 |
protected void Entry(StretchCADToolContext context) {} |
117 |
protected void Exit(StretchCADToolContext context) {} |
118 |
|
119 |
protected void addOption(StretchCADToolContext context, String s) |
120 |
{ |
121 |
Default(context); |
122 |
} |
123 |
|
124 |
protected void addPoint(StretchCADToolContext context, double pointX, double pointY, InputEvent event) |
125 |
{ |
126 |
Default(context); |
127 |
} |
128 |
|
129 |
protected void addValue(StretchCADToolContext context, double d) |
130 |
{ |
131 |
Default(context); |
132 |
} |
133 |
|
134 |
protected void Default(StretchCADToolContext 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 Stretch |
150 |
{ |
151 |
//-----------------------------------------------------------
|
152 |
// Member methods.
|
153 |
//
|
154 |
|
155 |
//-----------------------------------------------------------
|
156 |
// Member data.
|
157 |
//
|
158 |
|
159 |
//-------------------------------------------------------
|
160 |
// Statics.
|
161 |
//
|
162 |
/* package */ static Stretch_Default.Stretch_SelFirstPoint SelFirstPoint; |
163 |
/* package */ static Stretch_Default.Stretch_SelLastPoint SelLastPoint; |
164 |
/* package */ static Stretch_Default.Stretch_MoveFirstPoint MoveFirstPoint; |
165 |
/* package */ static Stretch_Default.Stretch_MoveLastPoint MoveLastPoint; |
166 |
private static Stretch_Default Default; |
167 |
|
168 |
static
|
169 |
{ |
170 |
SelFirstPoint = new Stretch_Default.Stretch_SelFirstPoint("Stretch.SelFirstPoint", 0); |
171 |
SelLastPoint = new Stretch_Default.Stretch_SelLastPoint("Stretch.SelLastPoint", 1); |
172 |
MoveFirstPoint = new Stretch_Default.Stretch_MoveFirstPoint("Stretch.MoveFirstPoint", 2); |
173 |
MoveLastPoint = new Stretch_Default.Stretch_MoveLastPoint("Stretch.MoveLastPoint", 3); |
174 |
Default = new Stretch_Default("Stretch.Default", -1); |
175 |
} |
176 |
|
177 |
} |
178 |
|
179 |
protected static class Stretch_Default |
180 |
extends StretchCADToolState
|
181 |
{ |
182 |
//-----------------------------------------------------------
|
183 |
// Member methods.
|
184 |
//
|
185 |
|
186 |
protected Stretch_Default(String name, int id) |
187 |
{ |
188 |
super (name, id);
|
189 |
} |
190 |
|
191 |
protected void addOption(StretchCADToolContext context, String s) |
192 |
{ |
193 |
StretchCADTool ctxt = context.getOwner(); |
194 |
|
195 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
196 |
{ |
197 |
boolean loopbackFlag =
|
198 |
context.getState().getName().equals( |
199 |
Stretch.SelFirstPoint.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(Stretch.SelFirstPoint); |
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 |
Stretch.SelFirstPoint.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(Stretch.SelFirstPoint); |
241 |
|
242 |
if (loopbackFlag == false) |
243 |
{ |
244 |
(context.getState()).Entry(context); |
245 |
} |
246 |
|
247 |
} |
248 |
} |
249 |
|
250 |
return;
|
251 |
} |
252 |
|
253 |
protected void addValue(StretchCADToolContext context, double d) |
254 |
{ |
255 |
StretchCADTool ctxt = context.getOwner(); |
256 |
|
257 |
boolean loopbackFlag =
|
258 |
context.getState().getName().equals( |
259 |
Stretch.SelFirstPoint.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(Stretch.SelFirstPoint); |
274 |
|
275 |
if (loopbackFlag == false) |
276 |
{ |
277 |
(context.getState()).Entry(context); |
278 |
} |
279 |
|
280 |
} |
281 |
return;
|
282 |
} |
283 |
|
284 |
protected void addPoint(StretchCADToolContext context, double pointX, double pointY, InputEvent event) |
285 |
{ |
286 |
StretchCADTool ctxt = context.getOwner(); |
287 |
|
288 |
boolean loopbackFlag =
|
289 |
context.getState().getName().equals( |
290 |
Stretch.SelFirstPoint.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(Stretch.SelFirstPoint); |
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 Stretch_SelFirstPoint |
321 |
extends Stretch_Default
|
322 |
{ |
323 |
//-------------------------------------------------------
|
324 |
// Member methods.
|
325 |
//
|
326 |
|
327 |
private Stretch_SelFirstPoint(String name, int id) |
328 |
{ |
329 |
super (name, id);
|
330 |
} |
331 |
|
332 |
protected void Entry(StretchCADToolContext context) |
333 |
{ |
334 |
StretchCADTool ctxt = context.getOwner(); |
335 |
|
336 |
ctxt.selection(); |
337 |
ctxt.setQuestion(PluginServices.getText(this,"insert_selection_point")); |
338 |
ctxt.setDescription(new String[]{"cancel"}); |
339 |
return;
|
340 |
} |
341 |
|
342 |
protected void addPoint(StretchCADToolContext context, double pointX, double pointY, InputEvent event) |
343 |
{ |
344 |
StretchCADTool ctxt = context.getOwner(); |
345 |
|
346 |
|
347 |
(context.getState()).Exit(context); |
348 |
context.clearState(); |
349 |
try
|
350 |
{ |
351 |
ctxt.setQuestion(PluginServices.getText(this,"insert_selection_last_point")); |
352 |
ctxt.setDescription(new String[]{"cancel"}); |
353 |
ctxt.addPoint(pointX, pointY, event); |
354 |
} |
355 |
finally
|
356 |
{ |
357 |
context.setState(Stretch.SelLastPoint); |
358 |
(context.getState()).Entry(context); |
359 |
} |
360 |
return;
|
361 |
} |
362 |
|
363 |
//-------------------------------------------------------
|
364 |
// Member data.
|
365 |
//
|
366 |
} |
367 |
|
368 |
private static final class Stretch_SelLastPoint |
369 |
extends Stretch_Default
|
370 |
{ |
371 |
//-------------------------------------------------------
|
372 |
// Member methods.
|
373 |
//
|
374 |
|
375 |
private Stretch_SelLastPoint(String name, int id) |
376 |
{ |
377 |
super (name, id);
|
378 |
} |
379 |
|
380 |
protected void addPoint(StretchCADToolContext context, double pointX, double pointY, InputEvent event) |
381 |
{ |
382 |
StretchCADTool ctxt = context.getOwner(); |
383 |
|
384 |
|
385 |
(context.getState()).Exit(context); |
386 |
context.clearState(); |
387 |
try
|
388 |
{ |
389 |
ctxt.setQuestion(PluginServices.getText(this,"insert_move_first_point")); |
390 |
ctxt.setDescription(new String[]{"cancel"}); |
391 |
ctxt.addPoint(pointX, pointY, event); |
392 |
} |
393 |
finally
|
394 |
{ |
395 |
context.setState(Stretch.MoveFirstPoint); |
396 |
(context.getState()).Entry(context); |
397 |
} |
398 |
return;
|
399 |
} |
400 |
|
401 |
//-------------------------------------------------------
|
402 |
// Member data.
|
403 |
//
|
404 |
} |
405 |
|
406 |
private static final class Stretch_MoveFirstPoint |
407 |
extends Stretch_Default
|
408 |
{ |
409 |
//-------------------------------------------------------
|
410 |
// Member methods.
|
411 |
//
|
412 |
|
413 |
private Stretch_MoveFirstPoint(String name, int id) |
414 |
{ |
415 |
super (name, id);
|
416 |
} |
417 |
|
418 |
protected void addPoint(StretchCADToolContext context, double pointX, double pointY, InputEvent event) |
419 |
{ |
420 |
StretchCADTool ctxt = context.getOwner(); |
421 |
|
422 |
|
423 |
(context.getState()).Exit(context); |
424 |
context.clearState(); |
425 |
try
|
426 |
{ |
427 |
ctxt.setQuestion(PluginServices.getText(this,"insert_move_last_point")); |
428 |
ctxt.setDescription(new String[]{"cancel"}); |
429 |
ctxt.addPoint(pointX, pointY, event); |
430 |
} |
431 |
finally
|
432 |
{ |
433 |
context.setState(Stretch.MoveLastPoint); |
434 |
(context.getState()).Entry(context); |
435 |
} |
436 |
return;
|
437 |
} |
438 |
|
439 |
//-------------------------------------------------------
|
440 |
// Member data.
|
441 |
//
|
442 |
} |
443 |
|
444 |
private static final class Stretch_MoveLastPoint |
445 |
extends Stretch_Default
|
446 |
{ |
447 |
//-------------------------------------------------------
|
448 |
// Member methods.
|
449 |
//
|
450 |
|
451 |
private Stretch_MoveLastPoint(String name, int id) |
452 |
{ |
453 |
super (name, id);
|
454 |
} |
455 |
|
456 |
protected void addPoint(StretchCADToolContext context, double pointX, double pointY, InputEvent event) |
457 |
{ |
458 |
StretchCADTool ctxt = context.getOwner(); |
459 |
|
460 |
|
461 |
(context.getState()).Exit(context); |
462 |
context.clearState(); |
463 |
try
|
464 |
{ |
465 |
ctxt.setQuestion(PluginServices.getText(this,"insert_selection_point")); |
466 |
ctxt.setDescription(new String[]{"cancel"}); |
467 |
ctxt.addPoint(pointX, pointY, event); |
468 |
ctxt.end(); |
469 |
ctxt.refresh(); |
470 |
} |
471 |
finally
|
472 |
{ |
473 |
context.setState(Stretch.SelFirstPoint); |
474 |
(context.getState()).Entry(context); |
475 |
} |
476 |
return;
|
477 |
} |
478 |
|
479 |
//-------------------------------------------------------
|
480 |
// Member data.
|
481 |
//
|
482 |
} |
483 |
|
484 |
//-----------------------------------------------------------
|
485 |
// Member data.
|
486 |
//
|
487 |
} |
488 |
} |