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