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 / CopyCADToolContext.java @ 41114
History | View | Annotate | Download (11.2 KB)
1 | 40557 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | |
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.CopyCADTool; |
||
35 | |||
36 | |||
37 | public final class CopyCADToolContext |
||
38 | extends statemap.FSMContext
|
||
39 | { |
||
40 | //---------------------------------------------------------------
|
||
41 | // Member methods.
|
||
42 | //
|
||
43 | |||
44 | public CopyCADToolContext(CopyCADTool owner)
|
||
45 | { |
||
46 | super();
|
||
47 | |||
48 | _owner = owner; |
||
49 | setState(Copy.FirstPointToMove); |
||
50 | Copy.FirstPointToMove.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 CopyCADToolState getState()
|
||
78 | throws statemap.StateUndefinedException
|
||
79 | { |
||
80 | if (_state == null) |
||
81 | { |
||
82 | throw(
|
||
83 | new statemap.StateUndefinedException());
|
||
84 | } |
||
85 | |||
86 | return ((CopyCADToolState) _state);
|
||
87 | } |
||
88 | |||
89 | protected CopyCADTool getOwner()
|
||
90 | { |
||
91 | return (_owner);
|
||
92 | } |
||
93 | |||
94 | //---------------------------------------------------------------
|
||
95 | // Member data.
|
||
96 | //
|
||
97 | |||
98 | transient private CopyCADTool _owner; |
||
99 | |||
100 | //---------------------------------------------------------------
|
||
101 | // Inner classes.
|
||
102 | //
|
||
103 | |||
104 | public static abstract class CopyCADToolState |
||
105 | extends statemap.State
|
||
106 | { |
||
107 | //-----------------------------------------------------------
|
||
108 | // Member methods.
|
||
109 | //
|
||
110 | |||
111 | protected CopyCADToolState(String name, int id) |
||
112 | { |
||
113 | super (name, id);
|
||
114 | } |
||
115 | |||
116 | protected void Entry(CopyCADToolContext context) {} |
||
117 | protected void Exit(CopyCADToolContext context) {} |
||
118 | |||
119 | protected void addOption(CopyCADToolContext context, String s) |
||
120 | { |
||
121 | Default(context); |
||
122 | } |
||
123 | |||
124 | protected void addPoint(CopyCADToolContext context, double pointX, double pointY, InputEvent event) |
||
125 | { |
||
126 | Default(context); |
||
127 | } |
||
128 | |||
129 | protected void addValue(CopyCADToolContext context, double d) |
||
130 | { |
||
131 | Default(context); |
||
132 | } |
||
133 | |||
134 | protected void Default(CopyCADToolContext 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 Copy |
||
150 | { |
||
151 | //-----------------------------------------------------------
|
||
152 | // Member methods.
|
||
153 | //
|
||
154 | |||
155 | //-----------------------------------------------------------
|
||
156 | // Member data.
|
||
157 | //
|
||
158 | |||
159 | //-------------------------------------------------------
|
||
160 | // Statics.
|
||
161 | //
|
||
162 | /* package */ static Copy_Default.Copy_FirstPointToMove FirstPointToMove; |
||
163 | /* package */ static Copy_Default.Copy_SecondPointToMove SecondPointToMove; |
||
164 | private static Copy_Default Default; |
||
165 | |||
166 | static
|
||
167 | { |
||
168 | FirstPointToMove = new Copy_Default.Copy_FirstPointToMove("Copy.FirstPointToMove", 0); |
||
169 | SecondPointToMove = new Copy_Default.Copy_SecondPointToMove("Copy.SecondPointToMove", 1); |
||
170 | Default = new Copy_Default("Copy.Default", -1); |
||
171 | } |
||
172 | |||
173 | } |
||
174 | |||
175 | protected static class Copy_Default |
||
176 | extends CopyCADToolState
|
||
177 | { |
||
178 | //-----------------------------------------------------------
|
||
179 | // Member methods.
|
||
180 | //
|
||
181 | |||
182 | protected Copy_Default(String name, int id) |
||
183 | { |
||
184 | super (name, id);
|
||
185 | } |
||
186 | |||
187 | protected void addOption(CopyCADToolContext context, String s) |
||
188 | { |
||
189 | CopyCADTool ctxt = context.getOwner(); |
||
190 | |||
191 | if (s.equals(PluginServices.getText(this,"cancel"))) |
||
192 | { |
||
193 | boolean loopbackFlag =
|
||
194 | context.getState().getName().equals( |
||
195 | Copy.FirstPointToMove.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(Copy.FirstPointToMove); |
||
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 | Copy.FirstPointToMove.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(Copy.FirstPointToMove); |
||
237 | |||
238 | if (loopbackFlag == false) |
||
239 | { |
||
240 | (context.getState()).Entry(context); |
||
241 | } |
||
242 | |||
243 | } |
||
244 | } |
||
245 | |||
246 | return;
|
||
247 | } |
||
248 | |||
249 | protected void addValue(CopyCADToolContext context, double d) |
||
250 | { |
||
251 | CopyCADTool ctxt = context.getOwner(); |
||
252 | |||
253 | boolean loopbackFlag =
|
||
254 | context.getState().getName().equals( |
||
255 | Copy.FirstPointToMove.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(Copy.FirstPointToMove); |
||
270 | |||
271 | if (loopbackFlag == false) |
||
272 | { |
||
273 | (context.getState()).Entry(context); |
||
274 | } |
||
275 | |||
276 | } |
||
277 | return;
|
||
278 | } |
||
279 | |||
280 | protected void addPoint(CopyCADToolContext context, double pointX, double pointY, InputEvent event) |
||
281 | { |
||
282 | CopyCADTool ctxt = context.getOwner(); |
||
283 | |||
284 | boolean loopbackFlag =
|
||
285 | context.getState().getName().equals( |
||
286 | Copy.FirstPointToMove.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(Copy.FirstPointToMove); |
||
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 Copy_FirstPointToMove |
||
317 | extends Copy_Default
|
||
318 | { |
||
319 | //-------------------------------------------------------
|
||
320 | // Member methods.
|
||
321 | //
|
||
322 | |||
323 | private Copy_FirstPointToMove(String name, int id) |
||
324 | { |
||
325 | super (name, id);
|
||
326 | } |
||
327 | |||
328 | protected void Entry(CopyCADToolContext context) |
||
329 | { |
||
330 | CopyCADTool ctxt = context.getOwner(); |
||
331 | |||
332 | ctxt.selection(); |
||
333 | 41114 | jldominguez | ctxt.setQuestion(PluginServices.getText(this,"insert_basis_point")); |
334 | 40435 | jjdelcerro | ctxt.setDescription(new String[]{"cancel"}); |
335 | return;
|
||
336 | } |
||
337 | |||
338 | protected void addPoint(CopyCADToolContext context, double pointX, double pointY, InputEvent event) |
||
339 | { |
||
340 | CopyCADTool ctxt = context.getOwner(); |
||
341 | |||
342 | |||
343 | (context.getState()).Exit(context); |
||
344 | context.clearState(); |
||
345 | try
|
||
346 | { |
||
347 | 41114 | jldominguez | ctxt.setQuestion(PluginServices.getText(this,"insert_second_point")); |
348 | 40435 | jjdelcerro | ctxt.setDescription(new String[]{"cancel"}); |
349 | ctxt.addPoint(pointX, pointY, event); |
||
350 | } |
||
351 | finally
|
||
352 | { |
||
353 | context.setState(Copy.SecondPointToMove); |
||
354 | (context.getState()).Entry(context); |
||
355 | } |
||
356 | return;
|
||
357 | } |
||
358 | |||
359 | //-------------------------------------------------------
|
||
360 | // Member data.
|
||
361 | //
|
||
362 | } |
||
363 | |||
364 | private static final class Copy_SecondPointToMove |
||
365 | extends Copy_Default
|
||
366 | { |
||
367 | //-------------------------------------------------------
|
||
368 | // Member methods.
|
||
369 | //
|
||
370 | |||
371 | private Copy_SecondPointToMove(String name, int id) |
||
372 | { |
||
373 | super (name, id);
|
||
374 | } |
||
375 | |||
376 | protected void addPoint(CopyCADToolContext context, double pointX, double pointY, InputEvent event) |
||
377 | { |
||
378 | CopyCADTool ctxt = context.getOwner(); |
||
379 | |||
380 | |||
381 | (context.getState()).Exit(context); |
||
382 | context.clearState(); |
||
383 | try
|
||
384 | { |
||
385 | ctxt.setDescription(new String[]{"cancel"}); |
||
386 | ctxt.addPoint(pointX, pointY, event); |
||
387 | ctxt.end(); |
||
388 | ctxt.refresh(); |
||
389 | } |
||
390 | finally
|
||
391 | { |
||
392 | context.setState(Copy.FirstPointToMove); |
||
393 | (context.getState()).Entry(context); |
||
394 | } |
||
395 | return;
|
||
396 | } |
||
397 | |||
398 | //-------------------------------------------------------
|
||
399 | // Member data.
|
||
400 | //
|
||
401 | } |
||
402 | |||
403 | //-----------------------------------------------------------
|
||
404 | // Member data.
|
||
405 | //
|
||
406 | } |
||
407 | } |