svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / SelectionCADToolContext.java @ 4465
History | View | Annotate | Download (13.6 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.SelectionCADTool; |
9 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
10 |
import java.awt.event.InputEvent; |
11 |
|
12 |
public final class SelectionCADToolContext |
13 |
extends statemap.FSMContext
|
14 |
{ |
15 |
//---------------------------------------------------------------
|
16 |
// Member methods.
|
17 |
//
|
18 |
|
19 |
public SelectionCADToolContext(SelectionCADTool owner)
|
20 |
{ |
21 |
super();
|
22 |
|
23 |
_owner = owner; |
24 |
setState(Selection.FirstPoint); |
25 |
Selection.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 SelectionCADToolState getState()
|
45 |
throws statemap.StateUndefinedException
|
46 |
{ |
47 |
if (_state == null) |
48 |
{ |
49 |
throw(
|
50 |
new statemap.StateUndefinedException());
|
51 |
} |
52 |
|
53 |
return ((SelectionCADToolState) _state);
|
54 |
} |
55 |
|
56 |
protected SelectionCADTool getOwner()
|
57 |
{ |
58 |
return (_owner);
|
59 |
} |
60 |
|
61 |
//---------------------------------------------------------------
|
62 |
// Member data.
|
63 |
//
|
64 |
|
65 |
transient private SelectionCADTool _owner; |
66 |
|
67 |
//---------------------------------------------------------------
|
68 |
// Inner classes.
|
69 |
//
|
70 |
|
71 |
public static abstract class SelectionCADToolState |
72 |
extends statemap.State
|
73 |
{ |
74 |
//-----------------------------------------------------------
|
75 |
// Member methods.
|
76 |
//
|
77 |
|
78 |
protected SelectionCADToolState(String name, int id) |
79 |
{ |
80 |
super (name, id);
|
81 |
} |
82 |
|
83 |
protected void Entry(SelectionCADToolContext context) {} |
84 |
protected void Exit(SelectionCADToolContext context) {} |
85 |
|
86 |
protected void addOption(SelectionCADToolContext context, String s) |
87 |
{ |
88 |
Default(context); |
89 |
} |
90 |
|
91 |
protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event) |
92 |
{ |
93 |
Default(context); |
94 |
} |
95 |
|
96 |
protected void Default(SelectionCADToolContext 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 Selection |
112 |
{ |
113 |
//-----------------------------------------------------------
|
114 |
// Member methods.
|
115 |
//
|
116 |
|
117 |
//-----------------------------------------------------------
|
118 |
// Member data.
|
119 |
//
|
120 |
|
121 |
//-------------------------------------------------------
|
122 |
// Statics.
|
123 |
//
|
124 |
/* package */ static Selection_Default.Selection_FirstPoint FirstPoint; |
125 |
/* package */ static Selection_Default.Selection_SecondPoint SecondPoint; |
126 |
/* package */ static Selection_Default.Selection_WithSelectedFeatures WithSelectedFeatures; |
127 |
/* package */ static Selection_Default.Selection_WithHandlers WithHandlers; |
128 |
private static Selection_Default Default; |
129 |
|
130 |
static
|
131 |
{ |
132 |
FirstPoint = new Selection_Default.Selection_FirstPoint("Selection.FirstPoint", 0); |
133 |
SecondPoint = new Selection_Default.Selection_SecondPoint("Selection.SecondPoint", 1); |
134 |
WithSelectedFeatures = new Selection_Default.Selection_WithSelectedFeatures("Selection.WithSelectedFeatures", 2); |
135 |
WithHandlers = new Selection_Default.Selection_WithHandlers("Selection.WithHandlers", 3); |
136 |
Default = new Selection_Default("Selection.Default", -1); |
137 |
} |
138 |
|
139 |
} |
140 |
|
141 |
protected static class Selection_Default |
142 |
extends SelectionCADToolState
|
143 |
{ |
144 |
//-----------------------------------------------------------
|
145 |
// Member methods.
|
146 |
//
|
147 |
|
148 |
protected Selection_Default(String name, int id) |
149 |
{ |
150 |
super (name, id);
|
151 |
} |
152 |
|
153 |
protected void addOption(SelectionCADToolContext context, String s) |
154 |
{ |
155 |
SelectionCADTool ctxt = context.getOwner(); |
156 |
|
157 |
if (s.equals("Cancelar")) |
158 |
{ |
159 |
boolean loopbackFlag =
|
160 |
context.getState().getName().equals( |
161 |
Selection.FirstPoint.getName()); |
162 |
|
163 |
if (loopbackFlag == false) |
164 |
{ |
165 |
(context.getState()).Exit(context); |
166 |
} |
167 |
|
168 |
context.clearState(); |
169 |
try
|
170 |
{ |
171 |
ctxt.end(); |
172 |
} |
173 |
finally
|
174 |
{ |
175 |
context.setState(Selection.FirstPoint); |
176 |
|
177 |
if (loopbackFlag == false) |
178 |
{ |
179 |
(context.getState()).Entry(context); |
180 |
} |
181 |
|
182 |
} |
183 |
} |
184 |
else
|
185 |
{ |
186 |
super.addOption(context, s);
|
187 |
} |
188 |
|
189 |
return;
|
190 |
} |
191 |
|
192 |
//-----------------------------------------------------------
|
193 |
// Inner classse.
|
194 |
//
|
195 |
|
196 |
|
197 |
private static final class Selection_FirstPoint |
198 |
extends Selection_Default
|
199 |
{ |
200 |
//-------------------------------------------------------
|
201 |
// Member methods.
|
202 |
//
|
203 |
|
204 |
private Selection_FirstPoint(String name, int id) |
205 |
{ |
206 |
super (name, id);
|
207 |
} |
208 |
|
209 |
protected void Entry(SelectionCADToolContext context) |
210 |
{ |
211 |
SelectionCADTool ctxt = context.getOwner(); |
212 |
|
213 |
ctxt.setQuestion("SELECCION" + "\n" + |
214 |
"Precise punto del rect?ngulo de selecci?n");
|
215 |
ctxt.setDescription(new String[]{"Cancelar"}); |
216 |
return;
|
217 |
} |
218 |
|
219 |
protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event) |
220 |
{ |
221 |
SelectionCADTool ctxt = context.getOwner(); |
222 |
|
223 |
if (ctxt.selectFeatures(pointX,pointY) && ctxt.getNextState().equals("Selection.SecondPoint")) |
224 |
{ |
225 |
|
226 |
(context.getState()).Exit(context); |
227 |
context.clearState(); |
228 |
try
|
229 |
{ |
230 |
ctxt.setQuestion("Precise segundo punto del rect?ngulo de seleccion");
|
231 |
ctxt.setDescription(new String[]{"Cancelar"}); |
232 |
ctxt.addPoint(pointX, pointY, event); |
233 |
} |
234 |
finally
|
235 |
{ |
236 |
context.setState(Selection.SecondPoint); |
237 |
(context.getState()).Entry(context); |
238 |
} |
239 |
} |
240 |
else if (ctxt.getNextState().equals("Selection.WithSelectedFeatures")) |
241 |
{ |
242 |
|
243 |
(context.getState()).Exit(context); |
244 |
context.clearState(); |
245 |
try
|
246 |
{ |
247 |
ctxt.setQuestion("select_handlers");
|
248 |
ctxt.setDescription(new String[]{"Cancelar"}); |
249 |
ctxt.addPoint(pointX, pointY, event); |
250 |
ctxt.end(); |
251 |
} |
252 |
finally
|
253 |
{ |
254 |
context.setState(Selection.WithSelectedFeatures); |
255 |
(context.getState()).Entry(context); |
256 |
} |
257 |
} else
|
258 |
{ |
259 |
super.addPoint(context, pointX, pointY, event);
|
260 |
} |
261 |
|
262 |
return;
|
263 |
} |
264 |
|
265 |
//-------------------------------------------------------
|
266 |
// Member data.
|
267 |
//
|
268 |
} |
269 |
|
270 |
private static final class Selection_SecondPoint |
271 |
extends Selection_Default
|
272 |
{ |
273 |
//-------------------------------------------------------
|
274 |
// Member methods.
|
275 |
//
|
276 |
|
277 |
private Selection_SecondPoint(String name, int id) |
278 |
{ |
279 |
super (name, id);
|
280 |
} |
281 |
|
282 |
protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event) |
283 |
{ |
284 |
SelectionCADTool ctxt = context.getOwner(); |
285 |
|
286 |
if (ctxt.selectWithSecondPoint(pointX,pointY) > 0) |
287 |
{ |
288 |
|
289 |
(context.getState()).Exit(context); |
290 |
context.clearState(); |
291 |
try
|
292 |
{ |
293 |
ctxt.setQuestion("select_handlers");
|
294 |
ctxt.setDescription(new String[]{"Cancelar"}); |
295 |
ctxt.addPoint(pointX, pointY, event); |
296 |
ctxt.end(); |
297 |
} |
298 |
finally
|
299 |
{ |
300 |
context.setState(Selection.WithSelectedFeatures); |
301 |
(context.getState()).Entry(context); |
302 |
} |
303 |
} |
304 |
else
|
305 |
{ |
306 |
|
307 |
(context.getState()).Exit(context); |
308 |
context.clearState(); |
309 |
try
|
310 |
{ |
311 |
ctxt.setQuestion("Precise punto del rect?ngulo de selecci?n");
|
312 |
ctxt.setDescription(new String[]{"Cancelar"}); |
313 |
} |
314 |
finally
|
315 |
{ |
316 |
context.setState(Selection.FirstPoint); |
317 |
(context.getState()).Entry(context); |
318 |
} |
319 |
} |
320 |
|
321 |
return;
|
322 |
} |
323 |
|
324 |
//-------------------------------------------------------
|
325 |
// Member data.
|
326 |
//
|
327 |
} |
328 |
|
329 |
private static final class Selection_WithSelectedFeatures |
330 |
extends Selection_Default
|
331 |
{ |
332 |
//-------------------------------------------------------
|
333 |
// Member methods.
|
334 |
//
|
335 |
|
336 |
private Selection_WithSelectedFeatures(String name, int id) |
337 |
{ |
338 |
super (name, id);
|
339 |
} |
340 |
|
341 |
protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event) |
342 |
{ |
343 |
SelectionCADTool ctxt = context.getOwner(); |
344 |
|
345 |
if (ctxt.selectHandlers(pointX, pointY)>0) |
346 |
{ |
347 |
|
348 |
(context.getState()).Exit(context); |
349 |
context.clearState(); |
350 |
try
|
351 |
{ |
352 |
ctxt.setQuestion("Precise punto destino");
|
353 |
ctxt.setDescription(new String[]{"Cancelar"}); |
354 |
ctxt.addPoint(pointX, pointY, event); |
355 |
} |
356 |
finally
|
357 |
{ |
358 |
context.setState(Selection.WithHandlers); |
359 |
(context.getState()).Entry(context); |
360 |
} |
361 |
} |
362 |
else if (ctxt.selectFeatures(pointX,pointY) && ctxt.getNextState().equals("Selection.WithSelectedFeatures")) |
363 |
{ |
364 |
SelectionCADToolState endState = context.getState(); |
365 |
|
366 |
context.clearState(); |
367 |
try
|
368 |
{ |
369 |
ctxt.setQuestion("select_handlers");
|
370 |
ctxt.setDescription(new String[]{"Cancelar"}); |
371 |
ctxt.addPoint(pointX, pointY, event); |
372 |
} |
373 |
finally
|
374 |
{ |
375 |
context.setState(endState); |
376 |
} |
377 |
} |
378 |
else
|
379 |
{ |
380 |
|
381 |
(context.getState()).Exit(context); |
382 |
context.clearState(); |
383 |
try
|
384 |
{ |
385 |
ctxt.setQuestion("Precise punto del rect?ngulo de selecci?n");
|
386 |
ctxt.setDescription(new String[]{"Cancelar"}); |
387 |
ctxt.addPoint(pointX, pointY, event); |
388 |
} |
389 |
finally
|
390 |
{ |
391 |
context.setState(Selection.FirstPoint); |
392 |
(context.getState()).Entry(context); |
393 |
} |
394 |
} |
395 |
|
396 |
return;
|
397 |
} |
398 |
|
399 |
//-------------------------------------------------------
|
400 |
// Member data.
|
401 |
//
|
402 |
} |
403 |
|
404 |
private static final class Selection_WithHandlers |
405 |
extends Selection_Default
|
406 |
{ |
407 |
//-------------------------------------------------------
|
408 |
// Member methods.
|
409 |
//
|
410 |
|
411 |
private Selection_WithHandlers(String name, int id) |
412 |
{ |
413 |
super (name, id);
|
414 |
} |
415 |
|
416 |
protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event) |
417 |
{ |
418 |
SelectionCADTool ctxt = context.getOwner(); |
419 |
|
420 |
|
421 |
(context.getState()).Exit(context); |
422 |
context.clearState(); |
423 |
try
|
424 |
{ |
425 |
ctxt.setQuestion("select_handlers");
|
426 |
ctxt.setDescription(new String[]{"Cancelar"}); |
427 |
ctxt.addPoint(pointX, pointY, event); |
428 |
ctxt.refresh(); |
429 |
} |
430 |
finally
|
431 |
{ |
432 |
context.setState(Selection.WithSelectedFeatures); |
433 |
(context.getState()).Entry(context); |
434 |
} |
435 |
return;
|
436 |
} |
437 |
|
438 |
//-------------------------------------------------------
|
439 |
// Member data.
|
440 |
//
|
441 |
} |
442 |
|
443 |
//-----------------------------------------------------------
|
444 |
// Member data.
|
445 |
//
|
446 |
} |
447 |
} |