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