svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / com / iver / cit / gvsig / gui / cad / tools / smc / ExtendCADToolContext.java @ 25563
History | View | Annotate | Download (9.04 KB)
1 |
|
---|---|
2 |
//
|
3 |
// Vicente Caballero Navarro
|
4 |
|
5 |
|
6 |
package com.iver.cit.gvsig.gui.cad.tools.smc; |
7 |
|
8 |
import java.awt.event.InputEvent; |
9 |
|
10 |
import com.iver.andami.PluginServices; |
11 |
import com.iver.cit.gvsig.gui.cad.tools.ExtendCADTool; |
12 |
|
13 |
public final class ExtendCADToolContext |
14 |
extends statemap.FSMContext
|
15 |
{ |
16 |
//---------------------------------------------------------------
|
17 |
// Member methods.
|
18 |
//
|
19 |
|
20 |
public ExtendCADToolContext(ExtendCADTool owner)
|
21 |
{ |
22 |
super();
|
23 |
|
24 |
_owner = owner; |
25 |
setState(Extend.SelectGeometryToExtend); |
26 |
Extend.SelectGeometryToExtend.Entry(this);
|
27 |
} |
28 |
|
29 |
public void addOption(String s) |
30 |
{ |
31 |
_transition = "addOption";
|
32 |
getState().addOption(this, s);
|
33 |
_transition = "";
|
34 |
return;
|
35 |
} |
36 |
|
37 |
public void addPoint(double pointX, double pointY, InputEvent event) |
38 |
{ |
39 |
_transition = "addPoint";
|
40 |
getState().addPoint(this, pointX, pointY, event);
|
41 |
_transition = "";
|
42 |
return;
|
43 |
} |
44 |
|
45 |
public void addValue(double d) |
46 |
{ |
47 |
_transition = "addValue";
|
48 |
getState().addValue(this, d);
|
49 |
_transition = "";
|
50 |
return;
|
51 |
} |
52 |
|
53 |
public ExtendCADToolState getState()
|
54 |
throws statemap.StateUndefinedException
|
55 |
{ |
56 |
if (_state == null) |
57 |
{ |
58 |
throw(
|
59 |
new statemap.StateUndefinedException());
|
60 |
} |
61 |
|
62 |
return ((ExtendCADToolState) _state);
|
63 |
} |
64 |
|
65 |
protected ExtendCADTool getOwner()
|
66 |
{ |
67 |
return (_owner);
|
68 |
} |
69 |
|
70 |
//---------------------------------------------------------------
|
71 |
// Member data.
|
72 |
//
|
73 |
|
74 |
transient private ExtendCADTool _owner; |
75 |
|
76 |
//---------------------------------------------------------------
|
77 |
// Inner classes.
|
78 |
//
|
79 |
|
80 |
public static abstract class ExtendCADToolState |
81 |
extends statemap.State
|
82 |
{ |
83 |
//-----------------------------------------------------------
|
84 |
// Member methods.
|
85 |
//
|
86 |
|
87 |
protected ExtendCADToolState(String name, int id) |
88 |
{ |
89 |
super (name, id);
|
90 |
} |
91 |
|
92 |
protected void Entry(ExtendCADToolContext context) {} |
93 |
protected void Exit(ExtendCADToolContext context) {} |
94 |
|
95 |
protected void addOption(ExtendCADToolContext context, String s) |
96 |
{ |
97 |
Default(context); |
98 |
} |
99 |
|
100 |
protected void addPoint(ExtendCADToolContext context, double pointX, double pointY, InputEvent event) |
101 |
{ |
102 |
Default(context); |
103 |
} |
104 |
|
105 |
protected void addValue(ExtendCADToolContext context, double d) |
106 |
{ |
107 |
Default(context); |
108 |
} |
109 |
|
110 |
protected void Default(ExtendCADToolContext context) |
111 |
{ |
112 |
throw (
|
113 |
new statemap.TransitionUndefinedException(
|
114 |
"State: " +
|
115 |
context.getState().getName() + |
116 |
", Transition: " +
|
117 |
context.getTransition())); |
118 |
} |
119 |
|
120 |
//-----------------------------------------------------------
|
121 |
// Member data.
|
122 |
//
|
123 |
} |
124 |
|
125 |
/* package */ static abstract class Extend |
126 |
{ |
127 |
//-----------------------------------------------------------
|
128 |
// Member methods.
|
129 |
//
|
130 |
|
131 |
//-----------------------------------------------------------
|
132 |
// Member data.
|
133 |
//
|
134 |
|
135 |
//-------------------------------------------------------
|
136 |
// Statics.
|
137 |
//
|
138 |
/* package */ static Extend_Default.Extend_SelectGeometryToExtend SelectGeometryToExtend; |
139 |
private static Extend_Default Default; |
140 |
|
141 |
static
|
142 |
{ |
143 |
SelectGeometryToExtend = new Extend_Default.Extend_SelectGeometryToExtend("Extend.SelectGeometryToExtend", 0); |
144 |
Default = new Extend_Default("Extend.Default", -1); |
145 |
} |
146 |
|
147 |
} |
148 |
|
149 |
protected static class Extend_Default |
150 |
extends ExtendCADToolState
|
151 |
{ |
152 |
//-----------------------------------------------------------
|
153 |
// Member methods.
|
154 |
//
|
155 |
|
156 |
protected Extend_Default(String name, int id) |
157 |
{ |
158 |
super (name, id);
|
159 |
} |
160 |
|
161 |
protected void addOption(ExtendCADToolContext context, String s) |
162 |
{ |
163 |
ExtendCADTool ctxt = context.getOwner(); |
164 |
|
165 |
if (s.equals(PluginServices.getText(this,"cancel"))) |
166 |
{ |
167 |
boolean loopbackFlag =
|
168 |
context.getState().getName().equals( |
169 |
Extend.SelectGeometryToExtend.getName()); |
170 |
|
171 |
if (loopbackFlag == false) |
172 |
{ |
173 |
(context.getState()).Exit(context); |
174 |
} |
175 |
|
176 |
context.clearState(); |
177 |
try
|
178 |
{ |
179 |
ctxt.end(); |
180 |
} |
181 |
finally
|
182 |
{ |
183 |
context.setState(Extend.SelectGeometryToExtend); |
184 |
|
185 |
if (loopbackFlag == false) |
186 |
{ |
187 |
(context.getState()).Entry(context); |
188 |
} |
189 |
|
190 |
} |
191 |
} |
192 |
else
|
193 |
{ |
194 |
boolean loopbackFlag =
|
195 |
context.getState().getName().equals( |
196 |
Extend.SelectGeometryToExtend.getName()); |
197 |
|
198 |
if (loopbackFlag == false) |
199 |
{ |
200 |
(context.getState()).Exit(context); |
201 |
} |
202 |
|
203 |
context.clearState(); |
204 |
try
|
205 |
{ |
206 |
ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s); |
207 |
} |
208 |
finally
|
209 |
{ |
210 |
context.setState(Extend.SelectGeometryToExtend); |
211 |
|
212 |
if (loopbackFlag == false) |
213 |
{ |
214 |
(context.getState()).Entry(context); |
215 |
} |
216 |
|
217 |
} |
218 |
} |
219 |
|
220 |
return;
|
221 |
} |
222 |
|
223 |
protected void addValue(ExtendCADToolContext context, double d) |
224 |
{ |
225 |
ExtendCADTool ctxt = context.getOwner(); |
226 |
|
227 |
boolean loopbackFlag =
|
228 |
context.getState().getName().equals( |
229 |
Extend.SelectGeometryToExtend.getName()); |
230 |
|
231 |
if (loopbackFlag == false) |
232 |
{ |
233 |
(context.getState()).Exit(context); |
234 |
} |
235 |
|
236 |
context.clearState(); |
237 |
try
|
238 |
{ |
239 |
ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d); |
240 |
} |
241 |
finally
|
242 |
{ |
243 |
context.setState(Extend.SelectGeometryToExtend); |
244 |
|
245 |
if (loopbackFlag == false) |
246 |
{ |
247 |
(context.getState()).Entry(context); |
248 |
} |
249 |
|
250 |
} |
251 |
return;
|
252 |
} |
253 |
|
254 |
protected void addPoint(ExtendCADToolContext context, double pointX, double pointY, InputEvent event) |
255 |
{ |
256 |
ExtendCADTool ctxt = context.getOwner(); |
257 |
|
258 |
boolean loopbackFlag =
|
259 |
context.getState().getName().equals( |
260 |
Extend.SelectGeometryToExtend.getName()); |
261 |
|
262 |
if (loopbackFlag == false) |
263 |
{ |
264 |
(context.getState()).Exit(context); |
265 |
} |
266 |
|
267 |
context.clearState(); |
268 |
try
|
269 |
{ |
270 |
ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY); |
271 |
} |
272 |
finally
|
273 |
{ |
274 |
context.setState(Extend.SelectGeometryToExtend); |
275 |
|
276 |
if (loopbackFlag == false) |
277 |
{ |
278 |
(context.getState()).Entry(context); |
279 |
} |
280 |
|
281 |
} |
282 |
return;
|
283 |
} |
284 |
|
285 |
//-----------------------------------------------------------
|
286 |
// Inner classse.
|
287 |
//
|
288 |
|
289 |
|
290 |
private static final class Extend_SelectGeometryToExtend |
291 |
extends Extend_Default
|
292 |
{ |
293 |
//-------------------------------------------------------
|
294 |
// Member methods.
|
295 |
//
|
296 |
|
297 |
private Extend_SelectGeometryToExtend(String name, int id) |
298 |
{ |
299 |
super (name, id);
|
300 |
} |
301 |
|
302 |
protected void Entry(ExtendCADToolContext context) |
303 |
{ |
304 |
ExtendCADTool ctxt = context.getOwner(); |
305 |
|
306 |
ctxt.selection(); |
307 |
ctxt.setQuestion(PluginServices.getText(this,"select_geometry_to_extend")); |
308 |
ctxt.setDescription(new String[]{"cancel"}); |
309 |
return;
|
310 |
} |
311 |
|
312 |
protected void addPoint(ExtendCADToolContext context, double pointX, double pointY, InputEvent event) |
313 |
{ |
314 |
ExtendCADTool ctxt = context.getOwner(); |
315 |
|
316 |
ExtendCADToolState endState = context.getState(); |
317 |
|
318 |
context.clearState(); |
319 |
try
|
320 |
{ |
321 |
ctxt.setQuestion(PluginServices.getText(this,"select_geometry_to_extend")); |
322 |
ctxt.setDescription(new String[]{"cancel"}); |
323 |
ctxt.addPoint(pointX, pointY, event); |
324 |
} |
325 |
finally
|
326 |
{ |
327 |
context.setState(endState); |
328 |
} |
329 |
return;
|
330 |
} |
331 |
|
332 |
//-------------------------------------------------------
|
333 |
// Member data.
|
334 |
//
|
335 |
} |
336 |
|
337 |
//-----------------------------------------------------------
|
338 |
// Member data.
|
339 |
//
|
340 |
} |
341 |
} |