root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / smc / InternalPolygonCADToolContext.java @ 29616
History | View | Annotate | Download (10.4 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.InternalPolygonCADTool; |
12 |
|
13 |
|
14 |
public final class InternalPolygonCADToolContext |
15 |
extends statemap.FSMContext
|
16 |
{ |
17 |
//---------------------------------------------------------------
|
18 |
// Member methods.
|
19 |
//
|
20 |
|
21 |
public InternalPolygonCADToolContext(InternalPolygonCADTool owner)
|
22 |
{ |
23 |
super();
|
24 |
|
25 |
_owner = owner; |
26 |
setState(InternalPolygon.AddNextPoint); |
27 |
InternalPolygon.AddNextPoint.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 InternalPolygonCADToolState getState()
|
55 |
throws statemap.StateUndefinedException
|
56 |
{ |
57 |
if (_state == null) |
58 |
{ |
59 |
throw(
|
60 |
new statemap.StateUndefinedException());
|
61 |
} |
62 |
|
63 |
return ((InternalPolygonCADToolState) _state);
|
64 |
} |
65 |
|
66 |
protected InternalPolygonCADTool getOwner()
|
67 |
{ |
68 |
return (_owner);
|
69 |
} |
70 |
|
71 |
//---------------------------------------------------------------
|
72 |
// Member data.
|
73 |
//
|
74 |
|
75 |
transient private InternalPolygonCADTool _owner; |
76 |
|
77 |
//---------------------------------------------------------------
|
78 |
// Inner classes.
|
79 |
//
|
80 |
|
81 |
public static abstract class InternalPolygonCADToolState |
82 |
extends statemap.State
|
83 |
{ |
84 |
//-----------------------------------------------------------
|
85 |
// Member methods.
|
86 |
//
|
87 |
|
88 |
protected InternalPolygonCADToolState(String name, int id) |
89 |
{ |
90 |
super (name, id);
|
91 |
} |
92 |
|
93 |
protected void Entry(InternalPolygonCADToolContext context) {} |
94 |
protected void Exit(InternalPolygonCADToolContext context) {} |
95 |
|
96 |
protected void addOption(InternalPolygonCADToolContext context, String s) |
97 |
{ |
98 |
Default(context); |
99 |
} |
100 |
|
101 |
protected void addPoint(InternalPolygonCADToolContext context, double pointX, double pointY, InputEvent event) |
102 |
{ |
103 |
Default(context); |
104 |
} |
105 |
|
106 |
protected void addValue(InternalPolygonCADToolContext context, double d) |
107 |
{ |
108 |
Default(context); |
109 |
} |
110 |
|
111 |
protected void Default(InternalPolygonCADToolContext 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 InternalPolygon |
127 |
{ |
128 |
//-----------------------------------------------------------
|
129 |
// Member methods.
|
130 |
//
|
131 |
|
132 |
//-----------------------------------------------------------
|
133 |
// Member data.
|
134 |
//
|
135 |
|
136 |
//-------------------------------------------------------
|
137 |
// Statics.
|
138 |
//
|
139 |
/* package */ static InternalPolygon_Default.InternalPolygon_AddNextPoint AddNextPoint; |
140 |
private static InternalPolygon_Default Default; |
141 |
|
142 |
static
|
143 |
{ |
144 |
AddNextPoint = new InternalPolygon_Default.InternalPolygon_AddNextPoint("InternalPolygon.AddNextPoint", 0); |
145 |
Default = new InternalPolygon_Default("InternalPolygon.Default", -1); |
146 |
} |
147 |
|
148 |
} |
149 |
|
150 |
protected static class InternalPolygon_Default |
151 |
extends InternalPolygonCADToolState
|
152 |
{ |
153 |
//-----------------------------------------------------------
|
154 |
// Member methods.
|
155 |
//
|
156 |
|
157 |
protected InternalPolygon_Default(String name, int id) |
158 |
{ |
159 |
super (name, id);
|
160 |
} |
161 |
|
162 |
protected void addOption(InternalPolygonCADToolContext context, String s) |
163 |
{ |
164 |
InternalPolygonCADTool ctxt = context.getOwner(); |
165 |
|
166 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
167 |
{ |
168 |
boolean loopbackFlag =
|
169 |
context.getState().getName().equals( |
170 |
InternalPolygon.AddNextPoint.getName()); |
171 |
|
172 |
if (loopbackFlag == false) |
173 |
{ |
174 |
(context.getState()).Exit(context); |
175 |
} |
176 |
|
177 |
context.clearState(); |
178 |
try
|
179 |
{ |
180 |
ctxt.end(); |
181 |
} |
182 |
finally
|
183 |
{ |
184 |
context.setState(InternalPolygon.AddNextPoint); |
185 |
|
186 |
if (loopbackFlag == false) |
187 |
{ |
188 |
(context.getState()).Entry(context); |
189 |
} |
190 |
|
191 |
} |
192 |
} |
193 |
else
|
194 |
{ |
195 |
boolean loopbackFlag =
|
196 |
context.getState().getName().equals( |
197 |
InternalPolygon.AddNextPoint.getName()); |
198 |
|
199 |
if (loopbackFlag == false) |
200 |
{ |
201 |
(context.getState()).Exit(context); |
202 |
} |
203 |
|
204 |
context.clearState(); |
205 |
try
|
206 |
{ |
207 |
ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
208 |
} |
209 |
finally
|
210 |
{ |
211 |
context.setState(InternalPolygon.AddNextPoint); |
212 |
|
213 |
if (loopbackFlag == false) |
214 |
{ |
215 |
(context.getState()).Entry(context); |
216 |
} |
217 |
|
218 |
} |
219 |
} |
220 |
|
221 |
return;
|
222 |
} |
223 |
|
224 |
protected void addValue(InternalPolygonCADToolContext context, double d) |
225 |
{ |
226 |
InternalPolygonCADTool ctxt = context.getOwner(); |
227 |
|
228 |
boolean loopbackFlag =
|
229 |
context.getState().getName().equals( |
230 |
InternalPolygon.AddNextPoint.getName()); |
231 |
|
232 |
if (loopbackFlag == false) |
233 |
{ |
234 |
(context.getState()).Exit(context); |
235 |
} |
236 |
|
237 |
context.clearState(); |
238 |
try
|
239 |
{ |
240 |
ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
241 |
} |
242 |
finally
|
243 |
{ |
244 |
context.setState(InternalPolygon.AddNextPoint); |
245 |
|
246 |
if (loopbackFlag == false) |
247 |
{ |
248 |
(context.getState()).Entry(context); |
249 |
} |
250 |
|
251 |
} |
252 |
return;
|
253 |
} |
254 |
|
255 |
protected void addPoint(InternalPolygonCADToolContext context, double pointX, double pointY, InputEvent event) |
256 |
{ |
257 |
InternalPolygonCADTool ctxt = context.getOwner(); |
258 |
|
259 |
boolean loopbackFlag =
|
260 |
context.getState().getName().equals( |
261 |
InternalPolygon.AddNextPoint.getName()); |
262 |
|
263 |
if (loopbackFlag == false) |
264 |
{ |
265 |
(context.getState()).Exit(context); |
266 |
} |
267 |
|
268 |
context.clearState(); |
269 |
try
|
270 |
{ |
271 |
ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
272 |
} |
273 |
finally
|
274 |
{ |
275 |
context.setState(InternalPolygon.AddNextPoint); |
276 |
|
277 |
if (loopbackFlag == false) |
278 |
{ |
279 |
(context.getState()).Entry(context); |
280 |
} |
281 |
|
282 |
} |
283 |
return;
|
284 |
} |
285 |
|
286 |
//-----------------------------------------------------------
|
287 |
// Inner classse.
|
288 |
//
|
289 |
|
290 |
|
291 |
private static final class InternalPolygon_AddNextPoint |
292 |
extends InternalPolygon_Default
|
293 |
{ |
294 |
//-------------------------------------------------------
|
295 |
// Member methods.
|
296 |
//
|
297 |
|
298 |
private InternalPolygon_AddNextPoint(String name, int id) |
299 |
{ |
300 |
super (name, id);
|
301 |
} |
302 |
|
303 |
protected void Entry(InternalPolygonCADToolContext context) |
304 |
{ |
305 |
InternalPolygonCADTool ctxt = context.getOwner(); |
306 |
|
307 |
ctxt.selection(); |
308 |
ctxt.setQuestion(PluginServices.getText(this,"next_point")+" "+ |
309 |
PluginServices.getText(this,"cad.or")+" "+ |
310 |
PluginServices.getText(this,"end")+ |
311 |
"["+PluginServices.getText(this,"InternalPolygonCADTool.end")+"]"); |
312 |
ctxt.setDescription(new String[]{"end", "cancel"}); |
313 |
return;
|
314 |
} |
315 |
|
316 |
protected void addOption(InternalPolygonCADToolContext context, String s) |
317 |
{ |
318 |
InternalPolygonCADTool ctxt = context.getOwner(); |
319 |
|
320 |
InternalPolygonCADToolState endState = context.getState(); |
321 |
|
322 |
context.clearState(); |
323 |
try
|
324 |
{ |
325 |
ctxt.setQuestion(PluginServices.getText(this,"next_point")+" "+ |
326 |
PluginServices.getText(this,"cad.or")+" "+ |
327 |
"["+PluginServices.getText(this,"InternalPolygonCADTool.end")+"]"); |
328 |
ctxt.setDescription(new String[]{"end", "cancel"}); |
329 |
ctxt.addOption(s); |
330 |
} |
331 |
finally
|
332 |
{ |
333 |
context.setState(endState); |
334 |
} |
335 |
return;
|
336 |
} |
337 |
|
338 |
protected void addPoint(InternalPolygonCADToolContext context, double pointX, double pointY, InputEvent event) |
339 |
{ |
340 |
InternalPolygonCADTool ctxt = context.getOwner(); |
341 |
|
342 |
InternalPolygonCADToolState endState = context.getState(); |
343 |
|
344 |
context.clearState(); |
345 |
try
|
346 |
{ |
347 |
ctxt.setQuestion(PluginServices.getText(this,"next_point")+" "+ |
348 |
PluginServices.getText(this,"cad.or")+" "+ |
349 |
PluginServices.getText(this,"end")+ |
350 |
"["+PluginServices.getText(this,"InternalPolygonCADTool.end")+"]"); |
351 |
ctxt.setDescription(new String[]{"end", "cancel"}); |
352 |
ctxt.addPoint(pointX, pointY, event); |
353 |
} |
354 |
finally
|
355 |
{ |
356 |
context.setState(endState); |
357 |
} |
358 |
return;
|
359 |
} |
360 |
|
361 |
//-------------------------------------------------------
|
362 |
// Member data.
|
363 |
//
|
364 |
} |
365 |
|
366 |
//-----------------------------------------------------------
|
367 |
// Member data.
|
368 |
//
|
369 |
} |
370 |
} |