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