svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / smc / MultiPointCADToolContext.java @ 29616
History | View | Annotate | Download (10.2 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.MultiPointCADTool; |
12 |
|
13 |
|
14 |
public final class MultiPointCADToolContext |
15 |
extends statemap.FSMContext
|
16 |
{ |
17 |
//---------------------------------------------------------------
|
18 |
// Member methods.
|
19 |
//
|
20 |
|
21 |
public MultiPointCADToolContext(MultiPointCADTool owner)
|
22 |
{ |
23 |
super();
|
24 |
|
25 |
_owner = owner; |
26 |
setState(MultiPoint.InsertPoint); |
27 |
MultiPoint.InsertPoint.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 MultiPointCADToolState getState()
|
55 |
throws statemap.StateUndefinedException
|
56 |
{ |
57 |
if (_state == null) |
58 |
{ |
59 |
throw(
|
60 |
new statemap.StateUndefinedException());
|
61 |
} |
62 |
|
63 |
return ((MultiPointCADToolState) _state);
|
64 |
} |
65 |
|
66 |
protected MultiPointCADTool getOwner()
|
67 |
{ |
68 |
return (_owner);
|
69 |
} |
70 |
|
71 |
//---------------------------------------------------------------
|
72 |
// Member data.
|
73 |
//
|
74 |
|
75 |
transient private MultiPointCADTool _owner; |
76 |
|
77 |
//---------------------------------------------------------------
|
78 |
// Inner classes.
|
79 |
//
|
80 |
|
81 |
public static abstract class MultiPointCADToolState |
82 |
extends statemap.State
|
83 |
{ |
84 |
//-----------------------------------------------------------
|
85 |
// Member methods.
|
86 |
//
|
87 |
|
88 |
protected MultiPointCADToolState(String name, int id) |
89 |
{ |
90 |
super (name, id);
|
91 |
} |
92 |
|
93 |
protected void Entry(MultiPointCADToolContext context) {} |
94 |
protected void Exit(MultiPointCADToolContext context) {} |
95 |
|
96 |
protected void addOption(MultiPointCADToolContext context, String s) |
97 |
{ |
98 |
Default(context); |
99 |
} |
100 |
|
101 |
protected void addPoint(MultiPointCADToolContext context, double pointX, double pointY, InputEvent event) |
102 |
{ |
103 |
Default(context); |
104 |
} |
105 |
|
106 |
protected void addValue(MultiPointCADToolContext context, double d) |
107 |
{ |
108 |
Default(context); |
109 |
} |
110 |
|
111 |
protected void Default(MultiPointCADToolContext 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 MultiPoint |
127 |
{ |
128 |
//-----------------------------------------------------------
|
129 |
// Member methods.
|
130 |
//
|
131 |
|
132 |
//-----------------------------------------------------------
|
133 |
// Member data.
|
134 |
//
|
135 |
|
136 |
//-------------------------------------------------------
|
137 |
// Statics.
|
138 |
//
|
139 |
/* package */ static MultiPoint_Default.MultiPoint_InsertPoint InsertPoint; |
140 |
private static MultiPoint_Default Default; |
141 |
|
142 |
static
|
143 |
{ |
144 |
InsertPoint = new MultiPoint_Default.MultiPoint_InsertPoint("MultiPoint.InsertPoint", 0); |
145 |
Default = new MultiPoint_Default("MultiPoint.Default", -1); |
146 |
} |
147 |
|
148 |
} |
149 |
|
150 |
protected static class MultiPoint_Default |
151 |
extends MultiPointCADToolState
|
152 |
{ |
153 |
//-----------------------------------------------------------
|
154 |
// Member methods.
|
155 |
//
|
156 |
|
157 |
protected MultiPoint_Default(String name, int id) |
158 |
{ |
159 |
super (name, id);
|
160 |
} |
161 |
|
162 |
protected void addOption(MultiPointCADToolContext context, String s) |
163 |
{ |
164 |
MultiPointCADTool ctxt = context.getOwner(); |
165 |
|
166 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
167 |
{ |
168 |
boolean loopbackFlag =
|
169 |
context.getState().getName().equals( |
170 |
MultiPoint.InsertPoint.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(MultiPoint.InsertPoint); |
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 |
MultiPoint.InsertPoint.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(MultiPoint.InsertPoint); |
212 |
|
213 |
if (loopbackFlag == false) |
214 |
{ |
215 |
(context.getState()).Entry(context); |
216 |
} |
217 |
|
218 |
} |
219 |
} |
220 |
|
221 |
return;
|
222 |
} |
223 |
|
224 |
protected void addValue(MultiPointCADToolContext context, double d) |
225 |
{ |
226 |
MultiPointCADTool ctxt = context.getOwner(); |
227 |
|
228 |
boolean loopbackFlag =
|
229 |
context.getState().getName().equals( |
230 |
MultiPoint.InsertPoint.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(MultiPoint.InsertPoint); |
245 |
|
246 |
if (loopbackFlag == false) |
247 |
{ |
248 |
(context.getState()).Entry(context); |
249 |
} |
250 |
|
251 |
} |
252 |
return;
|
253 |
} |
254 |
|
255 |
protected void addPoint(MultiPointCADToolContext context, double pointX, double pointY, InputEvent event) |
256 |
{ |
257 |
MultiPointCADTool ctxt = context.getOwner(); |
258 |
|
259 |
boolean loopbackFlag =
|
260 |
context.getState().getName().equals( |
261 |
MultiPoint.InsertPoint.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(MultiPoint.InsertPoint); |
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 MultiPoint_InsertPoint |
292 |
extends MultiPoint_Default
|
293 |
{ |
294 |
//-------------------------------------------------------
|
295 |
// Member methods.
|
296 |
//
|
297 |
|
298 |
private MultiPoint_InsertPoint(String name, int id) |
299 |
{ |
300 |
super (name, id);
|
301 |
} |
302 |
|
303 |
protected void Entry(MultiPointCADToolContext context) |
304 |
{ |
305 |
MultiPointCADTool ctxt = context.getOwner(); |
306 |
|
307 |
ctxt.setQuestion(PluginServices.getText(this,"insert_point")); |
308 |
ctxt.setDescription(new String[]{"cancel", }); |
309 |
return;
|
310 |
} |
311 |
|
312 |
protected void addOption(MultiPointCADToolContext context, String s) |
313 |
{ |
314 |
MultiPointCADTool ctxt = context.getOwner(); |
315 |
|
316 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"MultipointCADTool.end")) || s.equals(PluginServices.getText(this,"end"))) |
317 |
{ |
318 |
MultiPointCADToolState endState = context.getState(); |
319 |
|
320 |
context.clearState(); |
321 |
try
|
322 |
{ |
323 |
ctxt.setQuestion(PluginServices.getText(this,"insert_point")); |
324 |
ctxt.setDescription(new String[]{"cancel"}); |
325 |
ctxt.addOption(s); |
326 |
ctxt.endGeometry(); |
327 |
} |
328 |
finally
|
329 |
{ |
330 |
context.setState(endState); |
331 |
} |
332 |
} |
333 |
else
|
334 |
{ |
335 |
super.addOption(context, s);
|
336 |
} |
337 |
|
338 |
return;
|
339 |
} |
340 |
|
341 |
protected void addPoint(MultiPointCADToolContext context, double pointX, double pointY, InputEvent event) |
342 |
{ |
343 |
MultiPointCADTool ctxt = context.getOwner(); |
344 |
|
345 |
MultiPointCADToolState endState = context.getState(); |
346 |
|
347 |
context.clearState(); |
348 |
try
|
349 |
{ |
350 |
ctxt.setQuestion(PluginServices.getText(this,"insert_point")+" "+ |
351 |
PluginServices.getText(this,"cad.or")+" "+ |
352 |
PluginServices.getText(this,"end")+ |
353 |
"["+PluginServices.getText(this,"MultipointCADTool.end")+"]"); |
354 |
ctxt.setDescription(new String[]{"cancel", "end"}); |
355 |
ctxt.addPoint(pointX, pointY, event); |
356 |
} |
357 |
finally
|
358 |
{ |
359 |
context.setState(endState); |
360 |
} |
361 |
return;
|
362 |
} |
363 |
|
364 |
//-------------------------------------------------------
|
365 |
// Member data.
|
366 |
//
|
367 |
} |
368 |
|
369 |
//-----------------------------------------------------------
|
370 |
// Member data.
|
371 |
//
|
372 |
} |
373 |
} |