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