root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / smc / RectangleCADToolContext.java @ 29616
History | View | Annotate | Download (12.8 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.RectangleCADTool; |
12 |
|
13 |
|
14 |
public final class RectangleCADToolContext |
15 |
extends statemap.FSMContext
|
16 |
{ |
17 |
//---------------------------------------------------------------
|
18 |
// Member methods.
|
19 |
//
|
20 |
|
21 |
public RectangleCADToolContext(RectangleCADTool owner)
|
22 |
{ |
23 |
super();
|
24 |
|
25 |
_owner = owner; |
26 |
setState(Rectangle.FirstPoint);
|
27 |
Rectangle.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 RectangleCADToolState getState()
|
55 |
throws statemap.StateUndefinedException
|
56 |
{ |
57 |
if (_state == null) |
58 |
{ |
59 |
throw(
|
60 |
new statemap.StateUndefinedException());
|
61 |
} |
62 |
|
63 |
return ((RectangleCADToolState) _state);
|
64 |
} |
65 |
|
66 |
protected RectangleCADTool getOwner()
|
67 |
{ |
68 |
return (_owner);
|
69 |
} |
70 |
|
71 |
//---------------------------------------------------------------
|
72 |
// Member data.
|
73 |
//
|
74 |
|
75 |
transient private RectangleCADTool _owner; |
76 |
|
77 |
//---------------------------------------------------------------
|
78 |
// Inner classes.
|
79 |
//
|
80 |
|
81 |
public static abstract class RectangleCADToolState |
82 |
extends statemap.State
|
83 |
{ |
84 |
//-----------------------------------------------------------
|
85 |
// Member methods.
|
86 |
//
|
87 |
|
88 |
protected RectangleCADToolState(String name, int id) |
89 |
{ |
90 |
super (name, id);
|
91 |
} |
92 |
|
93 |
protected void Entry(RectangleCADToolContext context) {} |
94 |
protected void Exit(RectangleCADToolContext context) {} |
95 |
|
96 |
protected void addOption(RectangleCADToolContext context, String s) |
97 |
{ |
98 |
Default(context); |
99 |
} |
100 |
|
101 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
102 |
{ |
103 |
Default(context); |
104 |
} |
105 |
|
106 |
protected void addValue(RectangleCADToolContext context, double d) |
107 |
{ |
108 |
Default(context); |
109 |
} |
110 |
|
111 |
protected void Default(RectangleCADToolContext 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 Rectangle |
127 |
{ |
128 |
//-----------------------------------------------------------
|
129 |
// Member methods.
|
130 |
//
|
131 |
|
132 |
//-----------------------------------------------------------
|
133 |
// Member data.
|
134 |
//
|
135 |
|
136 |
//-------------------------------------------------------
|
137 |
// Statics.
|
138 |
//
|
139 |
/* package */ static Rectangle_Default.Rectangle_FirstPoint FirstPoint; |
140 |
/* package */ static Rectangle_Default.Rectangle_SecondPointOrSquare SecondPointOrSquare; |
141 |
/* package */ static Rectangle_Default.Rectangle_SecondPointSquare SecondPointSquare; |
142 |
private static Rectangle_Default Default; |
143 |
|
144 |
static
|
145 |
{ |
146 |
FirstPoint = new Rectangle_Default.Rectangle_FirstPoint("Rectangle.FirstPoint", 0); |
147 |
SecondPointOrSquare = new Rectangle_Default.Rectangle_SecondPointOrSquare("Rectangle.SecondPointOrSquare", 1); |
148 |
SecondPointSquare = new Rectangle_Default.Rectangle_SecondPointSquare("Rectangle.SecondPointSquare", 2); |
149 |
Default = new Rectangle_Default("Rectangle.Default", -1); |
150 |
} |
151 |
|
152 |
} |
153 |
|
154 |
protected static class Rectangle_Default |
155 |
extends RectangleCADToolState
|
156 |
{ |
157 |
//-----------------------------------------------------------
|
158 |
// Member methods.
|
159 |
//
|
160 |
|
161 |
protected Rectangle_Default(String name, int id) |
162 |
{ |
163 |
super (name, id);
|
164 |
} |
165 |
|
166 |
protected void addOption(RectangleCADToolContext context, String s) |
167 |
{ |
168 |
RectangleCADTool ctxt = context.getOwner(); |
169 |
|
170 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
171 |
{ |
172 |
boolean loopbackFlag =
|
173 |
context.getState().getName().equals( |
174 |
Rectangle.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(Rectangle.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 |
Rectangle.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(Rectangle.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(RectangleCADToolContext context, double d) |
229 |
{ |
230 |
RectangleCADTool ctxt = context.getOwner(); |
231 |
|
232 |
boolean loopbackFlag =
|
233 |
context.getState().getName().equals( |
234 |
Rectangle.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(Rectangle.FirstPoint);
|
249 |
|
250 |
if (loopbackFlag == false) |
251 |
{ |
252 |
(context.getState()).Entry(context); |
253 |
} |
254 |
|
255 |
} |
256 |
return;
|
257 |
} |
258 |
|
259 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
260 |
{ |
261 |
RectangleCADTool ctxt = context.getOwner(); |
262 |
|
263 |
boolean loopbackFlag =
|
264 |
context.getState().getName().equals( |
265 |
Rectangle.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(Rectangle.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 Rectangle_FirstPoint |
296 |
extends Rectangle_Default
|
297 |
{ |
298 |
//-------------------------------------------------------
|
299 |
// Member methods.
|
300 |
//
|
301 |
|
302 |
private Rectangle_FirstPoint(String name, int id) |
303 |
{ |
304 |
super (name, id);
|
305 |
} |
306 |
|
307 |
protected void Entry(RectangleCADToolContext context) |
308 |
{ |
309 |
RectangleCADTool ctxt = context.getOwner(); |
310 |
|
311 |
ctxt.setQuestion(PluginServices.getText(this,"insert_first_point_corner")); |
312 |
ctxt.setDescription(new String[]{"cancel"}); |
313 |
return;
|
314 |
} |
315 |
|
316 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
317 |
{ |
318 |
RectangleCADTool ctxt = context.getOwner(); |
319 |
|
320 |
|
321 |
(context.getState()).Exit(context); |
322 |
context.clearState(); |
323 |
try
|
324 |
{ |
325 |
ctxt.setQuestion(PluginServices.getText(this,"insert_point_corner")+" "+ |
326 |
PluginServices.getText(this,"cad.or")+" "+ |
327 |
PluginServices.getText(this,"square")+" "+ |
328 |
"["+PluginServices.getText(this,"RectangleCADTool.square")+"]"); |
329 |
ctxt.setDescription(new String[]{"square", "cancel"}); |
330 |
ctxt.addPoint(pointX, pointY, event); |
331 |
} |
332 |
finally
|
333 |
{ |
334 |
context.setState(Rectangle.SecondPointOrSquare);
|
335 |
(context.getState()).Entry(context); |
336 |
} |
337 |
return;
|
338 |
} |
339 |
|
340 |
//-------------------------------------------------------
|
341 |
// Member data.
|
342 |
//
|
343 |
} |
344 |
|
345 |
private static final class Rectangle_SecondPointOrSquare |
346 |
extends Rectangle_Default
|
347 |
{ |
348 |
//-------------------------------------------------------
|
349 |
// Member methods.
|
350 |
//
|
351 |
|
352 |
private Rectangle_SecondPointOrSquare(String name, int id) |
353 |
{ |
354 |
super (name, id);
|
355 |
} |
356 |
|
357 |
protected void addOption(RectangleCADToolContext context, String s) |
358 |
{ |
359 |
RectangleCADTool ctxt = context.getOwner(); |
360 |
|
361 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"RectangleCADTool.square")) || s.equals(PluginServices.getText(this,"square"))) |
362 |
{ |
363 |
|
364 |
(context.getState()).Exit(context); |
365 |
context.clearState(); |
366 |
try
|
367 |
{ |
368 |
ctxt.setQuestion(PluginServices.getText(this,"insert_opposited_corner")); |
369 |
ctxt.setDescription(new String[]{"cancel"}); |
370 |
ctxt.addOption(s); |
371 |
} |
372 |
finally
|
373 |
{ |
374 |
context.setState(Rectangle.SecondPointSquare);
|
375 |
(context.getState()).Entry(context); |
376 |
} |
377 |
} |
378 |
else
|
379 |
{ |
380 |
super.addOption(context, s);
|
381 |
} |
382 |
|
383 |
return;
|
384 |
} |
385 |
|
386 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
387 |
{ |
388 |
RectangleCADTool ctxt = context.getOwner(); |
389 |
|
390 |
|
391 |
(context.getState()).Exit(context); |
392 |
context.clearState(); |
393 |
try
|
394 |
{ |
395 |
ctxt.addPoint(pointX, pointY, event); |
396 |
} |
397 |
finally
|
398 |
{ |
399 |
context.setState(Rectangle.FirstPoint);
|
400 |
(context.getState()).Entry(context); |
401 |
} |
402 |
return;
|
403 |
} |
404 |
|
405 |
//-------------------------------------------------------
|
406 |
// Member data.
|
407 |
//
|
408 |
} |
409 |
|
410 |
private static final class Rectangle_SecondPointSquare |
411 |
extends Rectangle_Default
|
412 |
{ |
413 |
//-------------------------------------------------------
|
414 |
// Member methods.
|
415 |
//
|
416 |
|
417 |
private Rectangle_SecondPointSquare(String name, int id) |
418 |
{ |
419 |
super (name, id);
|
420 |
} |
421 |
|
422 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
423 |
{ |
424 |
RectangleCADTool ctxt = context.getOwner(); |
425 |
|
426 |
|
427 |
(context.getState()).Exit(context); |
428 |
context.clearState(); |
429 |
try
|
430 |
{ |
431 |
ctxt.addPoint(pointX, pointY, event); |
432 |
} |
433 |
finally
|
434 |
{ |
435 |
context.setState(Rectangle.FirstPoint);
|
436 |
(context.getState()).Entry(context); |
437 |
} |
438 |
return;
|
439 |
} |
440 |
|
441 |
//-------------------------------------------------------
|
442 |
// Member data.
|
443 |
//
|
444 |
} |
445 |
|
446 |
//-----------------------------------------------------------
|
447 |
// Member data.
|
448 |
//
|
449 |
} |
450 |
} |