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