svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / smc / ArcCADToolContext.java @ 29616
History | View | Annotate | Download (11.1 KB)
1 |
|
---|---|
2 |
//
|
3 |
// Vicente Caballero Navarro
|
4 |
|
5 |
|
6 |
package org.gvsig.editing.gui.cad.tools.smc; |
7 |
|
8 |
import java.awt.event.InputEvent; |
9 |
|
10 |
import org.gvsig.andami.PluginServices; |
11 |
import org.gvsig.editing.gui.cad.tools.ArcCADTool; |
12 |
|
13 |
|
14 |
public final class ArcCADToolContext |
15 |
extends statemap.FSMContext
|
16 |
{ |
17 |
//---------------------------------------------------------------
|
18 |
// Member methods.
|
19 |
//
|
20 |
|
21 |
public ArcCADToolContext(ArcCADTool owner)
|
22 |
{ |
23 |
super();
|
24 |
|
25 |
_owner = owner; |
26 |
setState(Arc.FirstPoint); |
27 |
Arc.FirstPoint.Entry(this);
|
28 |
} |
29 |
|
30 |
public void addOption(String s) |
31 |
{ |
32 |
_transition = "addOption";
|
33 |
getState().addOption(this, s);
|
34 |
_transition = "";
|
35 |
return;
|
36 |
} |
37 |
|
38 |
public void addPoint(double pointX, double pointY, InputEvent event) |
39 |
{ |
40 |
_transition = "addPoint";
|
41 |
getState().addPoint(this, pointX, pointY, event);
|
42 |
_transition = "";
|
43 |
return;
|
44 |
} |
45 |
|
46 |
public void addValue(double d) |
47 |
{ |
48 |
_transition = "addValue";
|
49 |
getState().addValue(this, d);
|
50 |
_transition = "";
|
51 |
return;
|
52 |
} |
53 |
|
54 |
public ArcCADToolState getState()
|
55 |
throws statemap.StateUndefinedException
|
56 |
{ |
57 |
if (_state == null) |
58 |
{ |
59 |
throw(
|
60 |
new statemap.StateUndefinedException());
|
61 |
} |
62 |
|
63 |
return ((ArcCADToolState) _state);
|
64 |
} |
65 |
|
66 |
protected ArcCADTool getOwner()
|
67 |
{ |
68 |
return (_owner);
|
69 |
} |
70 |
|
71 |
//---------------------------------------------------------------
|
72 |
// Member data.
|
73 |
//
|
74 |
|
75 |
transient private ArcCADTool _owner; |
76 |
|
77 |
//---------------------------------------------------------------
|
78 |
// Inner classes.
|
79 |
//
|
80 |
|
81 |
public static abstract class ArcCADToolState |
82 |
extends statemap.State
|
83 |
{ |
84 |
//-----------------------------------------------------------
|
85 |
// Member methods.
|
86 |
//
|
87 |
|
88 |
protected ArcCADToolState(String name, int id) |
89 |
{ |
90 |
super (name, id);
|
91 |
} |
92 |
|
93 |
protected void Entry(ArcCADToolContext context) {} |
94 |
protected void Exit(ArcCADToolContext context) {} |
95 |
|
96 |
protected void addOption(ArcCADToolContext context, String s) |
97 |
{ |
98 |
Default(context); |
99 |
} |
100 |
|
101 |
protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event) |
102 |
{ |
103 |
Default(context); |
104 |
} |
105 |
|
106 |
protected void addValue(ArcCADToolContext context, double d) |
107 |
{ |
108 |
Default(context); |
109 |
} |
110 |
|
111 |
protected void Default(ArcCADToolContext context) |
112 |
{ |
113 |
throw (
|
114 |
new statemap.TransitionUndefinedException(
|
115 |
"State: " +
|
116 |
context.getState().getName() + |
117 |
", Transition: " +
|
118 |
context.getTransition())); |
119 |
} |
120 |
|
121 |
//-----------------------------------------------------------
|
122 |
// Member data.
|
123 |
//
|
124 |
} |
125 |
|
126 |
/* package */ static abstract class Arc |
127 |
{ |
128 |
//-----------------------------------------------------------
|
129 |
// Member methods.
|
130 |
//
|
131 |
|
132 |
//-----------------------------------------------------------
|
133 |
// Member data.
|
134 |
//
|
135 |
|
136 |
//-------------------------------------------------------
|
137 |
// Statics.
|
138 |
//
|
139 |
/* package */ static Arc_Default.Arc_FirstPoint FirstPoint; |
140 |
/* package */ static Arc_Default.Arc_SecondPoint SecondPoint; |
141 |
/* package */ static Arc_Default.Arc_ThirdPoint ThirdPoint; |
142 |
private static Arc_Default Default; |
143 |
|
144 |
static
|
145 |
{ |
146 |
FirstPoint = new Arc_Default.Arc_FirstPoint("Arc.FirstPoint", 0); |
147 |
SecondPoint = new Arc_Default.Arc_SecondPoint("Arc.SecondPoint", 1); |
148 |
ThirdPoint = new Arc_Default.Arc_ThirdPoint("Arc.ThirdPoint", 2); |
149 |
Default = new Arc_Default("Arc.Default", -1); |
150 |
} |
151 |
|
152 |
} |
153 |
|
154 |
protected static class Arc_Default |
155 |
extends ArcCADToolState
|
156 |
{ |
157 |
//-----------------------------------------------------------
|
158 |
// Member methods.
|
159 |
//
|
160 |
|
161 |
protected Arc_Default(String name, int id) |
162 |
{ |
163 |
super (name, id);
|
164 |
} |
165 |
|
166 |
protected void addOption(ArcCADToolContext context, String s) |
167 |
{ |
168 |
ArcCADTool ctxt = context.getOwner(); |
169 |
|
170 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
171 |
{ |
172 |
boolean loopbackFlag =
|
173 |
context.getState().getName().equals( |
174 |
Arc.FirstPoint.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(Arc.FirstPoint); |
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 |
Arc.FirstPoint.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(Arc.FirstPoint); |
216 |
|
217 |
if (loopbackFlag == false) |
218 |
{ |
219 |
(context.getState()).Entry(context); |
220 |
} |
221 |
|
222 |
} |
223 |
} |
224 |
|
225 |
return;
|
226 |
} |
227 |
|
228 |
protected void addValue(ArcCADToolContext context, double d) |
229 |
{ |
230 |
ArcCADTool ctxt = context.getOwner(); |
231 |
|
232 |
boolean loopbackFlag =
|
233 |
context.getState().getName().equals( |
234 |
Arc.FirstPoint.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(Arc.FirstPoint); |
249 |
|
250 |
if (loopbackFlag == false) |
251 |
{ |
252 |
(context.getState()).Entry(context); |
253 |
} |
254 |
|
255 |
} |
256 |
return;
|
257 |
} |
258 |
|
259 |
protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event) |
260 |
{ |
261 |
ArcCADTool ctxt = context.getOwner(); |
262 |
|
263 |
boolean loopbackFlag =
|
264 |
context.getState().getName().equals( |
265 |
Arc.FirstPoint.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(Arc.FirstPoint); |
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 Arc_FirstPoint |
296 |
extends Arc_Default
|
297 |
{ |
298 |
//-------------------------------------------------------
|
299 |
// Member methods.
|
300 |
//
|
301 |
|
302 |
private Arc_FirstPoint(String name, int id) |
303 |
{ |
304 |
super (name, id);
|
305 |
} |
306 |
|
307 |
protected void Entry(ArcCADToolContext context) |
308 |
{ |
309 |
ArcCADTool ctxt = context.getOwner(); |
310 |
|
311 |
ctxt.setQuestion(PluginServices.getText(this,"insert_first_point")); |
312 |
ctxt.setDescription(new String[]{"cancel"}); |
313 |
return;
|
314 |
} |
315 |
|
316 |
protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event) |
317 |
{ |
318 |
ArcCADTool ctxt = context.getOwner(); |
319 |
|
320 |
|
321 |
(context.getState()).Exit(context); |
322 |
context.clearState(); |
323 |
try
|
324 |
{ |
325 |
ctxt.setQuestion(PluginServices.getText(this,"insert_second_point")); |
326 |
ctxt.setDescription(new String[]{"cancel"}); |
327 |
ctxt.addPoint(pointX, pointY, event); |
328 |
} |
329 |
finally
|
330 |
{ |
331 |
context.setState(Arc.SecondPoint); |
332 |
(context.getState()).Entry(context); |
333 |
} |
334 |
return;
|
335 |
} |
336 |
|
337 |
//-------------------------------------------------------
|
338 |
// Member data.
|
339 |
//
|
340 |
} |
341 |
|
342 |
private static final class Arc_SecondPoint |
343 |
extends Arc_Default
|
344 |
{ |
345 |
//-------------------------------------------------------
|
346 |
// Member methods.
|
347 |
//
|
348 |
|
349 |
private Arc_SecondPoint(String name, int id) |
350 |
{ |
351 |
super (name, id);
|
352 |
} |
353 |
|
354 |
protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event) |
355 |
{ |
356 |
ArcCADTool ctxt = context.getOwner(); |
357 |
|
358 |
|
359 |
(context.getState()).Exit(context); |
360 |
context.clearState(); |
361 |
try
|
362 |
{ |
363 |
ctxt.setQuestion(PluginServices.getText(this,"insert_last_point")); |
364 |
ctxt.setDescription(new String[]{"cancel"}); |
365 |
ctxt.addPoint(pointX, pointY, event); |
366 |
} |
367 |
finally
|
368 |
{ |
369 |
context.setState(Arc.ThirdPoint); |
370 |
(context.getState()).Entry(context); |
371 |
} |
372 |
return;
|
373 |
} |
374 |
|
375 |
//-------------------------------------------------------
|
376 |
// Member data.
|
377 |
//
|
378 |
} |
379 |
|
380 |
private static final class Arc_ThirdPoint |
381 |
extends Arc_Default
|
382 |
{ |
383 |
//-------------------------------------------------------
|
384 |
// Member methods.
|
385 |
//
|
386 |
|
387 |
private Arc_ThirdPoint(String name, int id) |
388 |
{ |
389 |
super (name, id);
|
390 |
} |
391 |
|
392 |
protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event) |
393 |
{ |
394 |
ArcCADTool ctxt = context.getOwner(); |
395 |
|
396 |
|
397 |
(context.getState()).Exit(context); |
398 |
context.clearState(); |
399 |
try
|
400 |
{ |
401 |
ctxt.addPoint(pointX, pointY, event); |
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 |
} |