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