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