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 | 3766 | caballero | |
---|---|---|---|
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 | 4324 | caballero | import java.awt.event.InputEvent; |
10 | 4584 | caballero | import com.iver.andami.PluginServices; |
11 | 3766 | caballero | |
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 | 3978 | caballero | setState(Rectangle.FirstPoint);
|
25 | Rectangle.FirstPoint.Entry(this); |
||
26 | 3766 | caballero | } |
27 | |||
28 | 3832 | caballero | public void addOption(String s) |
29 | 3766 | caballero | { |
30 | _transition = "addOption";
|
||
31 | 3832 | caballero | getState().addOption(this, s);
|
32 | 3766 | caballero | _transition = "";
|
33 | return;
|
||
34 | } |
||
35 | |||
36 | 4324 | caballero | public void addPoint(double pointX, double pointY, InputEvent event) |
37 | 3766 | caballero | { |
38 | _transition = "addPoint";
|
||
39 | 4324 | caballero | getState().addPoint(this, pointX, pointY, event);
|
40 | 3766 | caballero | _transition = "";
|
41 | return;
|
||
42 | } |
||
43 | |||
44 | 5735 | caballero | public void addValue(double d) |
45 | { |
||
46 | _transition = "addValue";
|
||
47 | getState().addValue(this, d);
|
||
48 | _transition = "";
|
||
49 | return;
|
||
50 | } |
||
51 | |||
52 | 3766 | caballero | 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 | 3832 | caballero | protected void addOption(RectangleCADToolContext context, String s) |
95 | 3766 | caballero | { |
96 | Default(context); |
||
97 | } |
||
98 | |||
99 | 4324 | caballero | protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
100 | 3766 | caballero | { |
101 | Default(context); |
||
102 | } |
||
103 | |||
104 | 5735 | caballero | protected void addValue(RectangleCADToolContext context, double d) |
105 | { |
||
106 | Default(context); |
||
107 | } |
||
108 | |||
109 | 3766 | caballero | 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 | 3978 | caballero | /* package */ static abstract class Rectangle |
125 | 3766 | caballero | { |
126 | //-----------------------------------------------------------
|
||
127 | // Member methods.
|
||
128 | //
|
||
129 | |||
130 | //-----------------------------------------------------------
|
||
131 | // Member data.
|
||
132 | //
|
||
133 | |||
134 | //-------------------------------------------------------
|
||
135 | // Statics.
|
||
136 | //
|
||
137 | 3978 | caballero | /* 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 | 3766 | caballero | |
142 | static
|
||
143 | { |
||
144 | 3978 | caballero | 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 | 3766 | caballero | } |
149 | |||
150 | } |
||
151 | |||
152 | 3978 | caballero | protected static class Rectangle_Default |
153 | 3766 | caballero | extends RectangleCADToolState
|
154 | { |
||
155 | //-----------------------------------------------------------
|
||
156 | // Member methods.
|
||
157 | //
|
||
158 | |||
159 | 3978 | caballero | protected Rectangle_Default(String name, int id) |
160 | 3766 | caballero | { |
161 | super (name, id);
|
||
162 | } |
||
163 | |||
164 | 3883 | caballero | protected void addOption(RectangleCADToolContext context, String s) |
165 | { |
||
166 | RectangleCADTool ctxt = context.getOwner(); |
||
167 | |||
168 | 4584 | caballero | if (s.equals(PluginServices.getText(this,"cancel"))) |
169 | 3883 | caballero | { |
170 | boolean loopbackFlag =
|
||
171 | context.getState().getName().equals( |
||
172 | 3978 | caballero | Rectangle.FirstPoint.getName());
|
173 | 3883 | caballero | |
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 | 3978 | caballero | context.setState(Rectangle.FirstPoint);
|
187 | 3883 | caballero | |
188 | if (loopbackFlag == false) |
||
189 | { |
||
190 | (context.getState()).Entry(context); |
||
191 | } |
||
192 | |||
193 | } |
||
194 | } |
||
195 | else
|
||
196 | { |
||
197 | 5735 | caballero | 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 | 3883 | caballero | } |
222 | |||
223 | return;
|
||
224 | } |
||
225 | |||
226 | 5735 | caballero | 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 | 3766 | caballero | //-----------------------------------------------------------
|
289 | // Inner classse.
|
||
290 | //
|
||
291 | |||
292 | |||
293 | 3978 | caballero | private static final class Rectangle_FirstPoint |
294 | extends Rectangle_Default
|
||
295 | 3766 | caballero | { |
296 | //-------------------------------------------------------
|
||
297 | // Member methods.
|
||
298 | //
|
||
299 | |||
300 | 3978 | caballero | private Rectangle_FirstPoint(String name, int id) |
301 | 3766 | caballero | { |
302 | super (name, id);
|
||
303 | } |
||
304 | |||
305 | protected void Entry(RectangleCADToolContext context) |
||
306 | { |
||
307 | RectangleCADTool ctxt = context.getOwner(); |
||
308 | |||
309 | 4892 | caballero | ctxt.setQuestion(PluginServices.getText(this,"insert_first_point_corner")); |
310 | 4584 | caballero | ctxt.setDescription(new String[]{"cancel"}); |
311 | 3766 | caballero | return;
|
312 | } |
||
313 | |||
314 | 4324 | caballero | protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
315 | 3766 | caballero | { |
316 | RectangleCADTool ctxt = context.getOwner(); |
||
317 | |||
318 | |||
319 | (context.getState()).Exit(context); |
||
320 | context.clearState(); |
||
321 | try
|
||
322 | { |
||
323 | 4584 | caballero | ctxt.setQuestion(PluginServices.getText(this,"insert_point_corner_or_square")); |
324 | ctxt.setDescription(new String[]{"square", "cancel"}); |
||
325 | 4365 | caballero | ctxt.addPoint(pointX, pointY, event); |
326 | 3766 | caballero | } |
327 | finally
|
||
328 | { |
||
329 | 3978 | caballero | context.setState(Rectangle.SecondPointOrSquare);
|
330 | 3766 | caballero | (context.getState()).Entry(context); |
331 | } |
||
332 | return;
|
||
333 | } |
||
334 | |||
335 | //-------------------------------------------------------
|
||
336 | // Member data.
|
||
337 | //
|
||
338 | } |
||
339 | |||
340 | 3978 | caballero | private static final class Rectangle_SecondPointOrSquare |
341 | extends Rectangle_Default
|
||
342 | 3766 | caballero | { |
343 | //-------------------------------------------------------
|
||
344 | // Member methods.
|
||
345 | //
|
||
346 | |||
347 | 3978 | caballero | private Rectangle_SecondPointOrSquare(String name, int id) |
348 | 3766 | caballero | { |
349 | super (name, id);
|
||
350 | } |
||
351 | |||
352 | 3832 | caballero | protected void addOption(RectangleCADToolContext context, String s) |
353 | 3766 | caballero | { |
354 | RectangleCADTool ctxt = context.getOwner(); |
||
355 | |||
356 | 4584 | caballero | if (s.equals("c") || s.equals("C") || s.equals(PluginServices.getText(this,"square"))) |
357 | 3883 | caballero | { |
358 | 3766 | caballero | |
359 | 3883 | caballero | (context.getState()).Exit(context); |
360 | context.clearState(); |
||
361 | try
|
||
362 | { |
||
363 | 4584 | caballero | ctxt.setQuestion(PluginServices.getText(this,"insert_opposited_corner")); |
364 | ctxt.setDescription(new String[]{"cancel"}); |
||
365 | 3883 | caballero | ctxt.addOption(s); |
366 | } |
||
367 | finally
|
||
368 | { |
||
369 | 3978 | caballero | context.setState(Rectangle.SecondPointSquare);
|
370 | 3883 | caballero | (context.getState()).Entry(context); |
371 | } |
||
372 | 3766 | caballero | } |
373 | 3883 | caballero | else
|
374 | 3766 | caballero | { |
375 | 3883 | caballero | super.addOption(context, s);
|
376 | 3766 | caballero | } |
377 | 3883 | caballero | |
378 | 3766 | caballero | return;
|
379 | } |
||
380 | |||
381 | 4324 | caballero | protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
382 | 3766 | caballero | { |
383 | RectangleCADTool ctxt = context.getOwner(); |
||
384 | |||
385 | |||
386 | (context.getState()).Exit(context); |
||
387 | context.clearState(); |
||
388 | try
|
||
389 | { |
||
390 | 4365 | caballero | ctxt.addPoint(pointX, pointY, event); |
391 | 3766 | caballero | ctxt.end(); |
392 | } |
||
393 | finally
|
||
394 | { |
||
395 | 3978 | caballero | context.setState(Rectangle.FirstPoint);
|
396 | 3766 | caballero | (context.getState()).Entry(context); |
397 | } |
||
398 | return;
|
||
399 | } |
||
400 | |||
401 | //-------------------------------------------------------
|
||
402 | // Member data.
|
||
403 | //
|
||
404 | } |
||
405 | |||
406 | 3978 | caballero | private static final class Rectangle_SecondPointSquare |
407 | extends Rectangle_Default
|
||
408 | 3766 | caballero | { |
409 | //-------------------------------------------------------
|
||
410 | // Member methods.
|
||
411 | //
|
||
412 | |||
413 | 3978 | caballero | private Rectangle_SecondPointSquare(String name, int id) |
414 | 3766 | caballero | { |
415 | super (name, id);
|
||
416 | } |
||
417 | |||
418 | 4324 | caballero | protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
419 | 3766 | caballero | { |
420 | RectangleCADTool ctxt = context.getOwner(); |
||
421 | |||
422 | |||
423 | (context.getState()).Exit(context); |
||
424 | context.clearState(); |
||
425 | try
|
||
426 | { |
||
427 | 4365 | caballero | ctxt.addPoint(pointX, pointY, event); |
428 | 3766 | caballero | ctxt.end(); |
429 | } |
||
430 | finally
|
||
431 | { |
||
432 | 3978 | caballero | context.setState(Rectangle.FirstPoint);
|
433 | 3766 | caballero | (context.getState()).Entry(context); |
434 | } |
||
435 | return;
|
||
436 | } |
||
437 | |||
438 | //-------------------------------------------------------
|
||
439 | // Member data.
|
||
440 | //
|
||
441 | } |
||
442 | |||
443 | //-----------------------------------------------------------
|
||
444 | // Member data.
|
||
445 | //
|
||
446 | } |
||
447 | } |