svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / smc / EditVertexCADToolContext.java @ 40557
History | View | Annotate | Download (14.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
//
|
26 |
// Vicente Caballero Navarro
|
27 |
|
28 |
|
29 |
package org.gvsig.editing.gui.cad.tools.smc; |
30 |
|
31 |
import java.awt.event.InputEvent; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.editing.gui.cad.tools.EditVertexCADTool; |
35 |
|
36 |
|
37 |
public final class EditVertexCADToolContext |
38 |
extends statemap.FSMContext
|
39 |
{ |
40 |
//---------------------------------------------------------------
|
41 |
// Member methods.
|
42 |
//
|
43 |
|
44 |
public EditVertexCADToolContext(EditVertexCADTool owner)
|
45 |
{ |
46 |
super();
|
47 |
|
48 |
_owner = owner; |
49 |
setState(EditVertex.SelectVertexOrDelete); |
50 |
EditVertex.SelectVertexOrDelete.Entry(this);
|
51 |
} |
52 |
|
53 |
public void addOption(String s) |
54 |
{ |
55 |
_transition = "addOption";
|
56 |
getState().addOption(this, s);
|
57 |
_transition = "";
|
58 |
return;
|
59 |
} |
60 |
|
61 |
public void addPoint(double pointX, double pointY, InputEvent event) |
62 |
{ |
63 |
_transition = "addPoint";
|
64 |
getState().addPoint(this, pointX, pointY, event);
|
65 |
_transition = "";
|
66 |
return;
|
67 |
} |
68 |
|
69 |
public void addValue(double d) |
70 |
{ |
71 |
_transition = "addValue";
|
72 |
getState().addValue(this, d);
|
73 |
_transition = "";
|
74 |
return;
|
75 |
} |
76 |
|
77 |
public EditVertexCADToolState getState()
|
78 |
throws statemap.StateUndefinedException
|
79 |
{ |
80 |
if (_state == null) |
81 |
{ |
82 |
throw(
|
83 |
new statemap.StateUndefinedException());
|
84 |
} |
85 |
|
86 |
return ((EditVertexCADToolState) _state);
|
87 |
} |
88 |
|
89 |
protected EditVertexCADTool getOwner()
|
90 |
{ |
91 |
return (_owner);
|
92 |
} |
93 |
|
94 |
//---------------------------------------------------------------
|
95 |
// Member data.
|
96 |
//
|
97 |
|
98 |
transient private EditVertexCADTool _owner; |
99 |
|
100 |
//---------------------------------------------------------------
|
101 |
// Inner classes.
|
102 |
//
|
103 |
|
104 |
public static abstract class EditVertexCADToolState |
105 |
extends statemap.State
|
106 |
{ |
107 |
//-----------------------------------------------------------
|
108 |
// Member methods.
|
109 |
//
|
110 |
|
111 |
protected EditVertexCADToolState(String name, int id) |
112 |
{ |
113 |
super (name, id);
|
114 |
} |
115 |
|
116 |
protected void Entry(EditVertexCADToolContext context) {} |
117 |
protected void Exit(EditVertexCADToolContext context) {} |
118 |
|
119 |
protected void addOption(EditVertexCADToolContext context, String s) |
120 |
{ |
121 |
Default(context); |
122 |
} |
123 |
|
124 |
protected void addPoint(EditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
125 |
{ |
126 |
Default(context); |
127 |
} |
128 |
|
129 |
protected void addValue(EditVertexCADToolContext context, double d) |
130 |
{ |
131 |
Default(context); |
132 |
} |
133 |
|
134 |
protected void Default(EditVertexCADToolContext context) |
135 |
{ |
136 |
throw (
|
137 |
new statemap.TransitionUndefinedException(
|
138 |
"State: " +
|
139 |
context.getState().getName() + |
140 |
", Transition: " +
|
141 |
context.getTransition())); |
142 |
} |
143 |
|
144 |
//-----------------------------------------------------------
|
145 |
// Member data.
|
146 |
//
|
147 |
} |
148 |
|
149 |
/* package */ static abstract class EditVertex |
150 |
{ |
151 |
//-----------------------------------------------------------
|
152 |
// Member methods.
|
153 |
//
|
154 |
|
155 |
//-----------------------------------------------------------
|
156 |
// Member data.
|
157 |
//
|
158 |
|
159 |
//-------------------------------------------------------
|
160 |
// Statics.
|
161 |
//
|
162 |
/* package */ static EditVertex_Default.EditVertex_SelectVertexOrDelete SelectVertexOrDelete; |
163 |
/* package */ static EditVertex_Default.EditVertex_AddVertex AddVertex; |
164 |
private static EditVertex_Default Default; |
165 |
|
166 |
static
|
167 |
{ |
168 |
SelectVertexOrDelete = new EditVertex_Default.EditVertex_SelectVertexOrDelete("EditVertex.SelectVertexOrDelete", 0); |
169 |
AddVertex = new EditVertex_Default.EditVertex_AddVertex("EditVertex.AddVertex", 1); |
170 |
Default = new EditVertex_Default("EditVertex.Default", -1); |
171 |
} |
172 |
|
173 |
} |
174 |
|
175 |
protected static class EditVertex_Default |
176 |
extends EditVertexCADToolState
|
177 |
{ |
178 |
//-----------------------------------------------------------
|
179 |
// Member methods.
|
180 |
//
|
181 |
|
182 |
protected EditVertex_Default(String name, int id) |
183 |
{ |
184 |
super (name, id);
|
185 |
} |
186 |
|
187 |
protected void addOption(EditVertexCADToolContext context, String s) |
188 |
{ |
189 |
EditVertexCADTool ctxt = context.getOwner(); |
190 |
|
191 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
192 |
{ |
193 |
boolean loopbackFlag =
|
194 |
context.getState().getName().equals( |
195 |
EditVertex.SelectVertexOrDelete.getName()); |
196 |
|
197 |
if (loopbackFlag == false) |
198 |
{ |
199 |
(context.getState()).Exit(context); |
200 |
} |
201 |
|
202 |
context.clearState(); |
203 |
try
|
204 |
{ |
205 |
ctxt.end(); |
206 |
} |
207 |
finally
|
208 |
{ |
209 |
context.setState(EditVertex.SelectVertexOrDelete); |
210 |
|
211 |
if (loopbackFlag == false) |
212 |
{ |
213 |
(context.getState()).Entry(context); |
214 |
} |
215 |
|
216 |
} |
217 |
} |
218 |
else
|
219 |
{ |
220 |
boolean loopbackFlag =
|
221 |
context.getState().getName().equals( |
222 |
EditVertex.SelectVertexOrDelete.getName()); |
223 |
|
224 |
if (loopbackFlag == false) |
225 |
{ |
226 |
(context.getState()).Exit(context); |
227 |
} |
228 |
|
229 |
context.clearState(); |
230 |
try
|
231 |
{ |
232 |
ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
233 |
} |
234 |
finally
|
235 |
{ |
236 |
context.setState(EditVertex.SelectVertexOrDelete); |
237 |
|
238 |
if (loopbackFlag == false) |
239 |
{ |
240 |
(context.getState()).Entry(context); |
241 |
} |
242 |
|
243 |
} |
244 |
} |
245 |
|
246 |
return;
|
247 |
} |
248 |
|
249 |
protected void addValue(EditVertexCADToolContext context, double d) |
250 |
{ |
251 |
EditVertexCADTool ctxt = context.getOwner(); |
252 |
|
253 |
boolean loopbackFlag =
|
254 |
context.getState().getName().equals( |
255 |
EditVertex.SelectVertexOrDelete.getName()); |
256 |
|
257 |
if (loopbackFlag == false) |
258 |
{ |
259 |
(context.getState()).Exit(context); |
260 |
} |
261 |
|
262 |
context.clearState(); |
263 |
try
|
264 |
{ |
265 |
ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
266 |
} |
267 |
finally
|
268 |
{ |
269 |
context.setState(EditVertex.SelectVertexOrDelete); |
270 |
|
271 |
if (loopbackFlag == false) |
272 |
{ |
273 |
(context.getState()).Entry(context); |
274 |
} |
275 |
|
276 |
} |
277 |
return;
|
278 |
} |
279 |
|
280 |
protected void addPoint(EditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
281 |
{ |
282 |
EditVertexCADTool ctxt = context.getOwner(); |
283 |
|
284 |
boolean loopbackFlag =
|
285 |
context.getState().getName().equals( |
286 |
EditVertex.SelectVertexOrDelete.getName()); |
287 |
|
288 |
if (loopbackFlag == false) |
289 |
{ |
290 |
(context.getState()).Exit(context); |
291 |
} |
292 |
|
293 |
context.clearState(); |
294 |
try
|
295 |
{ |
296 |
ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
297 |
} |
298 |
finally
|
299 |
{ |
300 |
context.setState(EditVertex.SelectVertexOrDelete); |
301 |
|
302 |
if (loopbackFlag == false) |
303 |
{ |
304 |
(context.getState()).Entry(context); |
305 |
} |
306 |
|
307 |
} |
308 |
return;
|
309 |
} |
310 |
|
311 |
//-----------------------------------------------------------
|
312 |
// Inner classse.
|
313 |
//
|
314 |
|
315 |
|
316 |
private static final class EditVertex_SelectVertexOrDelete |
317 |
extends EditVertex_Default
|
318 |
{ |
319 |
//-------------------------------------------------------
|
320 |
// Member methods.
|
321 |
//
|
322 |
|
323 |
private EditVertex_SelectVertexOrDelete(String name, int id) |
324 |
{ |
325 |
super (name, id);
|
326 |
} |
327 |
|
328 |
protected void Entry(EditVertexCADToolContext context) |
329 |
{ |
330 |
EditVertexCADTool ctxt = context.getOwner(); |
331 |
|
332 |
ctxt.selection(); |
333 |
ctxt.setQuestion(PluginServices.getText(this,"point")+", "+ |
334 |
PluginServices.getText(this,"next")+ |
335 |
"["+PluginServices.getText(this,"EditVertexCADTool.nextvertex")+"], "+ |
336 |
PluginServices.getText(this,"previous")+ |
337 |
"["+PluginServices.getText(this,"EditVertexCADTool.previousvertex")+"], "+ |
338 |
PluginServices.getText(this,"add")+ |
339 |
"["+PluginServices.getText(this,"EditVertexCADTool.addvertex")+"] "+ |
340 |
PluginServices.getText(this,"cad.or")+" "+ |
341 |
PluginServices.getText(this,"del")+ |
342 |
"["+PluginServices.getText(this,"EditVertexCADTool.delvertex")+"]"); |
343 |
ctxt.setDescription(new String[]{"next", "previous", "add", "del", "cancel"}); |
344 |
return;
|
345 |
} |
346 |
|
347 |
protected void addOption(EditVertexCADToolContext context, String s) |
348 |
{ |
349 |
EditVertexCADTool ctxt = context.getOwner(); |
350 |
|
351 |
if (s.equals("i") || s.equals("I") || s.equals(PluginServices.getText(this,"add"))) |
352 |
{ |
353 |
|
354 |
(context.getState()).Exit(context); |
355 |
context.clearState(); |
356 |
try
|
357 |
{ |
358 |
ctxt.setQuestion(PluginServices.getText(this,"add_vertex")); |
359 |
ctxt.setDescription(new String[]{"cancel"}); |
360 |
ctxt.addOption(s); |
361 |
} |
362 |
finally
|
363 |
{ |
364 |
context.setState(EditVertex.AddVertex); |
365 |
(context.getState()).Entry(context); |
366 |
} |
367 |
} |
368 |
else if (!s.equals("i") && !s.equals("I") && !s.equals(PluginServices.getText(this,"add"))) |
369 |
{ |
370 |
EditVertexCADToolState endState = context.getState(); |
371 |
|
372 |
context.clearState(); |
373 |
try
|
374 |
{ |
375 |
ctxt.setQuestion(PluginServices.getText(this,"point")+", "+ |
376 |
PluginServices.getText(this,"next")+ |
377 |
"["+PluginServices.getText(this,"EditVertexCADTool.nextvertex")+"], "+ |
378 |
PluginServices.getText(this,"previous")+ |
379 |
"["+PluginServices.getText(this,"EditVertexCADTool.previousvertex")+"], "+ |
380 |
PluginServices.getText(this,"add")+ |
381 |
"["+PluginServices.getText(this,"EditVertexCADTool.addvertex")+"] "+ |
382 |
PluginServices.getText(this,"cad.or")+" "+ |
383 |
PluginServices.getText(this,"del")+ |
384 |
"["+PluginServices.getText(this,"EditVertexCADTool.delvertex")+"]"); |
385 |
ctxt.setDescription(new String[]{"next", "previous", "add", "del", "cancel"}); |
386 |
ctxt.addOption(s); |
387 |
} |
388 |
finally
|
389 |
{ |
390 |
context.setState(endState); |
391 |
} |
392 |
} else
|
393 |
{ |
394 |
super.addOption(context, s);
|
395 |
} |
396 |
|
397 |
return;
|
398 |
} |
399 |
|
400 |
protected void addPoint(EditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
401 |
{ |
402 |
EditVertexCADTool ctxt = context.getOwner(); |
403 |
|
404 |
EditVertexCADToolState endState = context.getState(); |
405 |
|
406 |
context.clearState(); |
407 |
try
|
408 |
{ |
409 |
ctxt.setQuestion(PluginServices.getText(this,"select_from_point")); |
410 |
ctxt.setDescription(new String[]{"next", "previous", "add", "del", "cancel"}); |
411 |
ctxt.addPoint(pointX, pointY, event); |
412 |
} |
413 |
finally
|
414 |
{ |
415 |
context.setState(endState); |
416 |
} |
417 |
return;
|
418 |
} |
419 |
|
420 |
//-------------------------------------------------------
|
421 |
// Member data.
|
422 |
//
|
423 |
} |
424 |
|
425 |
private static final class EditVertex_AddVertex |
426 |
extends EditVertex_Default
|
427 |
{ |
428 |
//-------------------------------------------------------
|
429 |
// Member methods.
|
430 |
//
|
431 |
|
432 |
private EditVertex_AddVertex(String name, int id) |
433 |
{ |
434 |
super (name, id);
|
435 |
} |
436 |
|
437 |
protected void addPoint(EditVertexCADToolContext context, double pointX, double pointY, InputEvent event) |
438 |
{ |
439 |
EditVertexCADTool ctxt = context.getOwner(); |
440 |
|
441 |
|
442 |
(context.getState()).Exit(context); |
443 |
context.clearState(); |
444 |
try
|
445 |
{ |
446 |
ctxt.setQuestion(PluginServices.getText(this,"select_from_point")); |
447 |
ctxt.setDescription(new String[]{"next", "previous", "add", "del", "cancel"}); |
448 |
ctxt.addPoint(pointX, pointY, event); |
449 |
} |
450 |
finally
|
451 |
{ |
452 |
context.setState(EditVertex.SelectVertexOrDelete); |
453 |
(context.getState()).Entry(context); |
454 |
} |
455 |
return;
|
456 |
} |
457 |
|
458 |
//-------------------------------------------------------
|
459 |
// Member data.
|
460 |
//
|
461 |
} |
462 |
|
463 |
//-----------------------------------------------------------
|
464 |
// Member data.
|
465 |
//
|
466 |
} |
467 |
} |