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