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