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 / RectangleCADToolContext.java @ 40557
History | View | Annotate | Download (13.7 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.RectangleCADTool; |
35 |
|
36 |
|
37 |
public final class RectangleCADToolContext |
38 |
extends statemap.FSMContext
|
39 |
{ |
40 |
//---------------------------------------------------------------
|
41 |
// Member methods.
|
42 |
//
|
43 |
|
44 |
public RectangleCADToolContext(RectangleCADTool owner)
|
45 |
{ |
46 |
super();
|
47 |
|
48 |
_owner = owner; |
49 |
setState(Rectangle.FirstPoint);
|
50 |
Rectangle.FirstPoint.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 RectangleCADToolState getState()
|
78 |
throws statemap.StateUndefinedException
|
79 |
{ |
80 |
if (_state == null) |
81 |
{ |
82 |
throw(
|
83 |
new statemap.StateUndefinedException());
|
84 |
} |
85 |
|
86 |
return ((RectangleCADToolState) _state);
|
87 |
} |
88 |
|
89 |
protected RectangleCADTool getOwner()
|
90 |
{ |
91 |
return (_owner);
|
92 |
} |
93 |
|
94 |
//---------------------------------------------------------------
|
95 |
// Member data.
|
96 |
//
|
97 |
|
98 |
transient private RectangleCADTool _owner; |
99 |
|
100 |
//---------------------------------------------------------------
|
101 |
// Inner classes.
|
102 |
//
|
103 |
|
104 |
public static abstract class RectangleCADToolState |
105 |
extends statemap.State
|
106 |
{ |
107 |
//-----------------------------------------------------------
|
108 |
// Member methods.
|
109 |
//
|
110 |
|
111 |
protected RectangleCADToolState(String name, int id) |
112 |
{ |
113 |
super (name, id);
|
114 |
} |
115 |
|
116 |
protected void Entry(RectangleCADToolContext context) {} |
117 |
protected void Exit(RectangleCADToolContext context) {} |
118 |
|
119 |
protected void addOption(RectangleCADToolContext context, String s) |
120 |
{ |
121 |
Default(context); |
122 |
} |
123 |
|
124 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
125 |
{ |
126 |
Default(context); |
127 |
} |
128 |
|
129 |
protected void addValue(RectangleCADToolContext context, double d) |
130 |
{ |
131 |
Default(context); |
132 |
} |
133 |
|
134 |
protected void Default(RectangleCADToolContext 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 Rectangle |
150 |
{ |
151 |
//-----------------------------------------------------------
|
152 |
// Member methods.
|
153 |
//
|
154 |
|
155 |
//-----------------------------------------------------------
|
156 |
// Member data.
|
157 |
//
|
158 |
|
159 |
//-------------------------------------------------------
|
160 |
// Statics.
|
161 |
//
|
162 |
/* package */ static Rectangle_Default.Rectangle_FirstPoint FirstPoint; |
163 |
/* package */ static Rectangle_Default.Rectangle_SecondPointOrSquare SecondPointOrSquare; |
164 |
/* package */ static Rectangle_Default.Rectangle_SecondPointSquare SecondPointSquare; |
165 |
private static Rectangle_Default Default; |
166 |
|
167 |
static
|
168 |
{ |
169 |
FirstPoint = new Rectangle_Default.Rectangle_FirstPoint("Rectangle.FirstPoint", 0); |
170 |
SecondPointOrSquare = new Rectangle_Default.Rectangle_SecondPointOrSquare("Rectangle.SecondPointOrSquare", 1); |
171 |
SecondPointSquare = new Rectangle_Default.Rectangle_SecondPointSquare("Rectangle.SecondPointSquare", 2); |
172 |
Default = new Rectangle_Default("Rectangle.Default", -1); |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
protected static class Rectangle_Default |
178 |
extends RectangleCADToolState
|
179 |
{ |
180 |
//-----------------------------------------------------------
|
181 |
// Member methods.
|
182 |
//
|
183 |
|
184 |
protected Rectangle_Default(String name, int id) |
185 |
{ |
186 |
super (name, id);
|
187 |
} |
188 |
|
189 |
protected void addOption(RectangleCADToolContext context, String s) |
190 |
{ |
191 |
RectangleCADTool ctxt = context.getOwner(); |
192 |
|
193 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
194 |
{ |
195 |
boolean loopbackFlag =
|
196 |
context.getState().getName().equals( |
197 |
Rectangle.FirstPoint.getName());
|
198 |
|
199 |
if (loopbackFlag == false) |
200 |
{ |
201 |
(context.getState()).Exit(context); |
202 |
} |
203 |
|
204 |
context.clearState(); |
205 |
try
|
206 |
{ |
207 |
ctxt.end(); |
208 |
} |
209 |
finally
|
210 |
{ |
211 |
context.setState(Rectangle.FirstPoint);
|
212 |
|
213 |
if (loopbackFlag == false) |
214 |
{ |
215 |
(context.getState()).Entry(context); |
216 |
} |
217 |
|
218 |
} |
219 |
} |
220 |
else
|
221 |
{ |
222 |
boolean loopbackFlag =
|
223 |
context.getState().getName().equals( |
224 |
Rectangle.FirstPoint.getName());
|
225 |
|
226 |
if (loopbackFlag == false) |
227 |
{ |
228 |
(context.getState()).Exit(context); |
229 |
} |
230 |
|
231 |
context.clearState(); |
232 |
try
|
233 |
{ |
234 |
ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
235 |
} |
236 |
finally
|
237 |
{ |
238 |
context.setState(Rectangle.FirstPoint);
|
239 |
|
240 |
if (loopbackFlag == false) |
241 |
{ |
242 |
(context.getState()).Entry(context); |
243 |
} |
244 |
|
245 |
} |
246 |
} |
247 |
|
248 |
return;
|
249 |
} |
250 |
|
251 |
protected void addValue(RectangleCADToolContext context, double d) |
252 |
{ |
253 |
RectangleCADTool ctxt = context.getOwner(); |
254 |
|
255 |
boolean loopbackFlag =
|
256 |
context.getState().getName().equals( |
257 |
Rectangle.FirstPoint.getName());
|
258 |
|
259 |
if (loopbackFlag == false) |
260 |
{ |
261 |
(context.getState()).Exit(context); |
262 |
} |
263 |
|
264 |
context.clearState(); |
265 |
try
|
266 |
{ |
267 |
ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
268 |
} |
269 |
finally
|
270 |
{ |
271 |
context.setState(Rectangle.FirstPoint);
|
272 |
|
273 |
if (loopbackFlag == false) |
274 |
{ |
275 |
(context.getState()).Entry(context); |
276 |
} |
277 |
|
278 |
} |
279 |
return;
|
280 |
} |
281 |
|
282 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
283 |
{ |
284 |
RectangleCADTool ctxt = context.getOwner(); |
285 |
|
286 |
boolean loopbackFlag =
|
287 |
context.getState().getName().equals( |
288 |
Rectangle.FirstPoint.getName());
|
289 |
|
290 |
if (loopbackFlag == false) |
291 |
{ |
292 |
(context.getState()).Exit(context); |
293 |
} |
294 |
|
295 |
context.clearState(); |
296 |
try
|
297 |
{ |
298 |
ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
299 |
} |
300 |
finally
|
301 |
{ |
302 |
context.setState(Rectangle.FirstPoint);
|
303 |
|
304 |
if (loopbackFlag == false) |
305 |
{ |
306 |
(context.getState()).Entry(context); |
307 |
} |
308 |
|
309 |
} |
310 |
return;
|
311 |
} |
312 |
|
313 |
//-----------------------------------------------------------
|
314 |
// Inner classse.
|
315 |
//
|
316 |
|
317 |
|
318 |
private static final class Rectangle_FirstPoint |
319 |
extends Rectangle_Default
|
320 |
{ |
321 |
//-------------------------------------------------------
|
322 |
// Member methods.
|
323 |
//
|
324 |
|
325 |
private Rectangle_FirstPoint(String name, int id) |
326 |
{ |
327 |
super (name, id);
|
328 |
} |
329 |
|
330 |
protected void Entry(RectangleCADToolContext context) |
331 |
{ |
332 |
RectangleCADTool ctxt = context.getOwner(); |
333 |
|
334 |
ctxt.setQuestion(PluginServices.getText(this,"insert_first_point_corner")); |
335 |
ctxt.setDescription(new String[]{"cancel"}); |
336 |
return;
|
337 |
} |
338 |
|
339 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
340 |
{ |
341 |
RectangleCADTool ctxt = context.getOwner(); |
342 |
|
343 |
|
344 |
(context.getState()).Exit(context); |
345 |
context.clearState(); |
346 |
try
|
347 |
{ |
348 |
ctxt.setQuestion(PluginServices.getText(this,"insert_point_corner")+" "+ |
349 |
PluginServices.getText(this,"cad.or")+" "+ |
350 |
PluginServices.getText(this,"square")+" "+ |
351 |
"["+PluginServices.getText(this,"RectangleCADTool.square")+"]"); |
352 |
ctxt.setDescription(new String[]{"square", "cancel"}); |
353 |
ctxt.addPoint(pointX, pointY, event); |
354 |
} |
355 |
finally
|
356 |
{ |
357 |
context.setState(Rectangle.SecondPointOrSquare);
|
358 |
(context.getState()).Entry(context); |
359 |
} |
360 |
return;
|
361 |
} |
362 |
|
363 |
//-------------------------------------------------------
|
364 |
// Member data.
|
365 |
//
|
366 |
} |
367 |
|
368 |
private static final class Rectangle_SecondPointOrSquare |
369 |
extends Rectangle_Default
|
370 |
{ |
371 |
//-------------------------------------------------------
|
372 |
// Member methods.
|
373 |
//
|
374 |
|
375 |
private Rectangle_SecondPointOrSquare(String name, int id) |
376 |
{ |
377 |
super (name, id);
|
378 |
} |
379 |
|
380 |
protected void addOption(RectangleCADToolContext context, String s) |
381 |
{ |
382 |
RectangleCADTool ctxt = context.getOwner(); |
383 |
|
384 |
if (s.equalsIgnoreCase(PluginServices.getText(this,"RectangleCADTool.square")) || s.equals(PluginServices.getText(this,"square"))) |
385 |
{ |
386 |
|
387 |
(context.getState()).Exit(context); |
388 |
context.clearState(); |
389 |
try
|
390 |
{ |
391 |
ctxt.setQuestion(PluginServices.getText(this,"insert_opposited_corner")); |
392 |
ctxt.setDescription(new String[]{"cancel"}); |
393 |
ctxt.addOption(s); |
394 |
} |
395 |
finally
|
396 |
{ |
397 |
context.setState(Rectangle.SecondPointSquare);
|
398 |
(context.getState()).Entry(context); |
399 |
} |
400 |
} |
401 |
else
|
402 |
{ |
403 |
super.addOption(context, s);
|
404 |
} |
405 |
|
406 |
return;
|
407 |
} |
408 |
|
409 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
410 |
{ |
411 |
RectangleCADTool ctxt = context.getOwner(); |
412 |
|
413 |
|
414 |
(context.getState()).Exit(context); |
415 |
context.clearState(); |
416 |
try
|
417 |
{ |
418 |
ctxt.addPoint(pointX, pointY, event); |
419 |
} |
420 |
finally
|
421 |
{ |
422 |
context.setState(Rectangle.FirstPoint);
|
423 |
(context.getState()).Entry(context); |
424 |
} |
425 |
return;
|
426 |
} |
427 |
|
428 |
//-------------------------------------------------------
|
429 |
// Member data.
|
430 |
//
|
431 |
} |
432 |
|
433 |
private static final class Rectangle_SecondPointSquare |
434 |
extends Rectangle_Default
|
435 |
{ |
436 |
//-------------------------------------------------------
|
437 |
// Member methods.
|
438 |
//
|
439 |
|
440 |
private Rectangle_SecondPointSquare(String name, int id) |
441 |
{ |
442 |
super (name, id);
|
443 |
} |
444 |
|
445 |
protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event) |
446 |
{ |
447 |
RectangleCADTool ctxt = context.getOwner(); |
448 |
|
449 |
|
450 |
(context.getState()).Exit(context); |
451 |
context.clearState(); |
452 |
try
|
453 |
{ |
454 |
ctxt.addPoint(pointX, pointY, event); |
455 |
} |
456 |
finally
|
457 |
{ |
458 |
context.setState(Rectangle.FirstPoint);
|
459 |
(context.getState()).Entry(context); |
460 |
} |
461 |
return;
|
462 |
} |
463 |
|
464 |
//-------------------------------------------------------
|
465 |
// Member data.
|
466 |
//
|
467 |
} |
468 |
|
469 |
//-----------------------------------------------------------
|
470 |
// Member data.
|
471 |
//
|
472 |
} |
473 |
} |