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