root / tags / v1_1_Build_1015 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / JoinCADToolContext.java @ 13679
History | View | Annotate | Download (9.65 KB)
1 | 5984 | caballero | |
---|---|---|---|
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.JoinCADTool; |
||
9 | import java.awt.event.InputEvent; |
||
10 | import com.iver.andami.PluginServices; |
||
11 | |||
12 | public final class JoinCADToolContext |
||
13 | extends statemap.FSMContext
|
||
14 | { |
||
15 | //---------------------------------------------------------------
|
||
16 | // Member methods.
|
||
17 | //
|
||
18 | |||
19 | public JoinCADToolContext(JoinCADTool owner)
|
||
20 | { |
||
21 | super();
|
||
22 | |||
23 | _owner = owner; |
||
24 | setState(Join.FirstPoint); |
||
25 | Join.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 JoinCADToolState getState()
|
||
53 | throws statemap.StateUndefinedException
|
||
54 | { |
||
55 | if (_state == null) |
||
56 | { |
||
57 | throw(
|
||
58 | new statemap.StateUndefinedException());
|
||
59 | } |
||
60 | |||
61 | return ((JoinCADToolState) _state);
|
||
62 | } |
||
63 | |||
64 | protected JoinCADTool getOwner()
|
||
65 | { |
||
66 | return (_owner);
|
||
67 | } |
||
68 | |||
69 | //---------------------------------------------------------------
|
||
70 | // Member data.
|
||
71 | //
|
||
72 | |||
73 | transient private JoinCADTool _owner; |
||
74 | |||
75 | //---------------------------------------------------------------
|
||
76 | // Inner classes.
|
||
77 | //
|
||
78 | |||
79 | public static abstract class JoinCADToolState |
||
80 | extends statemap.State
|
||
81 | { |
||
82 | //-----------------------------------------------------------
|
||
83 | // Member methods.
|
||
84 | //
|
||
85 | |||
86 | protected JoinCADToolState(String name, int id) |
||
87 | { |
||
88 | super (name, id);
|
||
89 | } |
||
90 | |||
91 | protected void Entry(JoinCADToolContext context) {} |
||
92 | protected void Exit(JoinCADToolContext context) {} |
||
93 | |||
94 | protected void addOption(JoinCADToolContext context, String s) |
||
95 | { |
||
96 | Default(context); |
||
97 | } |
||
98 | |||
99 | protected void addPoint(JoinCADToolContext context, double pointX, double pointY, InputEvent event) |
||
100 | { |
||
101 | Default(context); |
||
102 | } |
||
103 | |||
104 | protected void addValue(JoinCADToolContext context, double d) |
||
105 | { |
||
106 | Default(context); |
||
107 | } |
||
108 | |||
109 | protected void Default(JoinCADToolContext 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 Join |
||
125 | { |
||
126 | //-----------------------------------------------------------
|
||
127 | // Member methods.
|
||
128 | //
|
||
129 | |||
130 | //-----------------------------------------------------------
|
||
131 | // Member data.
|
||
132 | //
|
||
133 | |||
134 | //-------------------------------------------------------
|
||
135 | // Statics.
|
||
136 | //
|
||
137 | /* package */ static Join_Default.Join_FirstPoint FirstPoint; |
||
138 | private static Join_Default Default; |
||
139 | |||
140 | static
|
||
141 | { |
||
142 | FirstPoint = new Join_Default.Join_FirstPoint("Join.FirstPoint", 0); |
||
143 | Default = new Join_Default("Join.Default", -1); |
||
144 | } |
||
145 | |||
146 | } |
||
147 | |||
148 | protected static class Join_Default |
||
149 | extends JoinCADToolState
|
||
150 | { |
||
151 | //-----------------------------------------------------------
|
||
152 | // Member methods.
|
||
153 | //
|
||
154 | |||
155 | protected Join_Default(String name, int id) |
||
156 | { |
||
157 | super (name, id);
|
||
158 | } |
||
159 | |||
160 | protected void addOption(JoinCADToolContext context, String s) |
||
161 | { |
||
162 | JoinCADTool ctxt = context.getOwner(); |
||
163 | |||
164 | if (s.equals(PluginServices.getText(this,"cancel"))) |
||
165 | { |
||
166 | boolean loopbackFlag =
|
||
167 | context.getState().getName().equals( |
||
168 | Join.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(Join.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 | Join.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(Join.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(JoinCADToolContext context, double d) |
||
223 | { |
||
224 | JoinCADTool ctxt = context.getOwner(); |
||
225 | |||
226 | boolean loopbackFlag =
|
||
227 | context.getState().getName().equals( |
||
228 | Join.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(Join.FirstPoint); |
||
243 | |||
244 | if (loopbackFlag == false) |
||
245 | { |
||
246 | (context.getState()).Entry(context); |
||
247 | } |
||
248 | |||
249 | } |
||
250 | return;
|
||
251 | } |
||
252 | |||
253 | protected void addPoint(JoinCADToolContext context, double pointX, double pointY, InputEvent event) |
||
254 | { |
||
255 | JoinCADTool ctxt = context.getOwner(); |
||
256 | |||
257 | boolean loopbackFlag =
|
||
258 | context.getState().getName().equals( |
||
259 | Join.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(Join.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 Join_FirstPoint |
||
290 | extends Join_Default
|
||
291 | { |
||
292 | //-------------------------------------------------------
|
||
293 | // Member methods.
|
||
294 | //
|
||
295 | |||
296 | private Join_FirstPoint(String name, int id) |
||
297 | { |
||
298 | super (name, id);
|
||
299 | } |
||
300 | |||
301 | protected void Entry(JoinCADToolContext context) |
||
302 | { |
||
303 | JoinCADTool ctxt = context.getOwner(); |
||
304 | |||
305 | 6008 | caballero | ctxt.setQuestion(PluginServices.getText(this,"select_geometry")); |
306 | 5984 | caballero | ctxt.setDescription(new String[]{"cancel"}); |
307 | return;
|
||
308 | } |
||
309 | |||
310 | protected void addOption(JoinCADToolContext context, String s) |
||
311 | { |
||
312 | JoinCADTool ctxt = context.getOwner(); |
||
313 | |||
314 | 6008 | caballero | if (s.equals("e") || s.equals("E") || s.equals(PluginServices.getText(this,"end"))) |
315 | { |
||
316 | JoinCADToolState endState = context.getState(); |
||
317 | 5984 | caballero | |
318 | 6008 | caballero | context.clearState(); |
319 | try
|
||
320 | { |
||
321 | ctxt.setQuestion(PluginServices.getText(this,"select_geometry")); |
||
322 | ctxt.setDescription(new String[]{"cancel"}); |
||
323 | ctxt.addOption(s); |
||
324 | ctxt.end(); |
||
325 | } |
||
326 | finally
|
||
327 | { |
||
328 | context.setState(endState); |
||
329 | } |
||
330 | 5984 | caballero | } |
331 | 6008 | caballero | else
|
332 | 5984 | caballero | { |
333 | 6008 | caballero | super.addOption(context, s);
|
334 | 5984 | caballero | } |
335 | 6008 | caballero | |
336 | 5984 | caballero | return;
|
337 | } |
||
338 | |||
339 | protected void addPoint(JoinCADToolContext context, double pointX, double pointY, InputEvent event) |
||
340 | { |
||
341 | JoinCADTool ctxt = context.getOwner(); |
||
342 | |||
343 | JoinCADToolState endState = context.getState(); |
||
344 | |||
345 | context.clearState(); |
||
346 | try
|
||
347 | { |
||
348 | 6008 | caballero | ctxt.setQuestion(PluginServices.getText(this,"select_other_geometry_or_end")); |
349 | ctxt.setDescription(new String[]{"cancel", "end"}); |
||
350 | 5984 | caballero | ctxt.addPoint(pointX, pointY, event); |
351 | } |
||
352 | finally
|
||
353 | { |
||
354 | context.setState(endState); |
||
355 | } |
||
356 | return;
|
||
357 | } |
||
358 | |||
359 | //-------------------------------------------------------
|
||
360 | // Member data.
|
||
361 | //
|
||
362 | } |
||
363 | |||
364 | //-----------------------------------------------------------
|
||
365 | // Member data.
|
||
366 | //
|
||
367 | } |
||
368 | } |