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