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