root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / MoveCADToolContext.java @ 5184
History | View | Annotate | Download (7.55 KB)
1 | 4434 | 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.MoveCADTool; |
||
9 | import java.awt.event.InputEvent; |
||
10 | 4584 | caballero | import com.iver.andami.PluginServices; |
11 | 4434 | caballero | |
12 | public final class MoveCADToolContext |
||
13 | extends statemap.FSMContext
|
||
14 | { |
||
15 | //---------------------------------------------------------------
|
||
16 | // Member methods.
|
||
17 | //
|
||
18 | |||
19 | public MoveCADToolContext(MoveCADTool owner)
|
||
20 | { |
||
21 | super();
|
||
22 | |||
23 | _owner = owner; |
||
24 | setState(Move.FirstPointToMove); |
||
25 | Move.FirstPointToMove.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 MoveCADToolState getState()
|
||
45 | throws statemap.StateUndefinedException
|
||
46 | { |
||
47 | if (_state == null) |
||
48 | { |
||
49 | throw(
|
||
50 | new statemap.StateUndefinedException());
|
||
51 | } |
||
52 | |||
53 | return ((MoveCADToolState) _state);
|
||
54 | } |
||
55 | |||
56 | protected MoveCADTool getOwner()
|
||
57 | { |
||
58 | return (_owner);
|
||
59 | } |
||
60 | |||
61 | //---------------------------------------------------------------
|
||
62 | // Member data.
|
||
63 | //
|
||
64 | |||
65 | transient private MoveCADTool _owner; |
||
66 | |||
67 | //---------------------------------------------------------------
|
||
68 | // Inner classes.
|
||
69 | //
|
||
70 | |||
71 | public static abstract class MoveCADToolState |
||
72 | extends statemap.State
|
||
73 | { |
||
74 | //-----------------------------------------------------------
|
||
75 | // Member methods.
|
||
76 | //
|
||
77 | |||
78 | protected MoveCADToolState(String name, int id) |
||
79 | { |
||
80 | super (name, id);
|
||
81 | } |
||
82 | |||
83 | protected void Entry(MoveCADToolContext context) {} |
||
84 | protected void Exit(MoveCADToolContext context) {} |
||
85 | |||
86 | protected void addOption(MoveCADToolContext context, String s) |
||
87 | { |
||
88 | Default(context); |
||
89 | } |
||
90 | |||
91 | protected void addPoint(MoveCADToolContext context, double pointX, double pointY, InputEvent event) |
||
92 | { |
||
93 | Default(context); |
||
94 | } |
||
95 | |||
96 | protected void Default(MoveCADToolContext context) |
||
97 | { |
||
98 | throw (
|
||
99 | new statemap.TransitionUndefinedException(
|
||
100 | "State: " +
|
||
101 | context.getState().getName() + |
||
102 | ", Transition: " +
|
||
103 | context.getTransition())); |
||
104 | } |
||
105 | |||
106 | //-----------------------------------------------------------
|
||
107 | // Member data.
|
||
108 | //
|
||
109 | } |
||
110 | |||
111 | /* package */ static abstract class Move |
||
112 | { |
||
113 | //-----------------------------------------------------------
|
||
114 | // Member methods.
|
||
115 | //
|
||
116 | |||
117 | //-----------------------------------------------------------
|
||
118 | // Member data.
|
||
119 | //
|
||
120 | |||
121 | //-------------------------------------------------------
|
||
122 | // Statics.
|
||
123 | //
|
||
124 | /* package */ static Move_Default.Move_FirstPointToMove FirstPointToMove; |
||
125 | /* package */ static Move_Default.Move_SecondPointToMove SecondPointToMove; |
||
126 | private static Move_Default Default; |
||
127 | |||
128 | static
|
||
129 | { |
||
130 | FirstPointToMove = new Move_Default.Move_FirstPointToMove("Move.FirstPointToMove", 0); |
||
131 | SecondPointToMove = new Move_Default.Move_SecondPointToMove("Move.SecondPointToMove", 1); |
||
132 | Default = new Move_Default("Move.Default", -1); |
||
133 | } |
||
134 | |||
135 | } |
||
136 | |||
137 | protected static class Move_Default |
||
138 | extends MoveCADToolState
|
||
139 | { |
||
140 | //-----------------------------------------------------------
|
||
141 | // Member methods.
|
||
142 | //
|
||
143 | |||
144 | protected Move_Default(String name, int id) |
||
145 | { |
||
146 | super (name, id);
|
||
147 | } |
||
148 | |||
149 | protected void addOption(MoveCADToolContext context, String s) |
||
150 | { |
||
151 | MoveCADTool ctxt = context.getOwner(); |
||
152 | |||
153 | 4584 | caballero | if (s.equals(PluginServices.getText(this,"cancel"))) |
154 | 4434 | caballero | { |
155 | boolean loopbackFlag =
|
||
156 | context.getState().getName().equals( |
||
157 | Move.FirstPointToMove.getName()); |
||
158 | |||
159 | if (loopbackFlag == false) |
||
160 | { |
||
161 | (context.getState()).Exit(context); |
||
162 | } |
||
163 | |||
164 | context.clearState(); |
||
165 | try
|
||
166 | { |
||
167 | ctxt.end(); |
||
168 | } |
||
169 | finally
|
||
170 | { |
||
171 | context.setState(Move.FirstPointToMove); |
||
172 | |||
173 | if (loopbackFlag == false) |
||
174 | { |
||
175 | (context.getState()).Entry(context); |
||
176 | } |
||
177 | |||
178 | } |
||
179 | } |
||
180 | else
|
||
181 | { |
||
182 | super.addOption(context, s);
|
||
183 | } |
||
184 | |||
185 | return;
|
||
186 | } |
||
187 | |||
188 | //-----------------------------------------------------------
|
||
189 | // Inner classse.
|
||
190 | //
|
||
191 | |||
192 | |||
193 | private static final class Move_FirstPointToMove |
||
194 | extends Move_Default
|
||
195 | { |
||
196 | //-------------------------------------------------------
|
||
197 | // Member methods.
|
||
198 | //
|
||
199 | |||
200 | private Move_FirstPointToMove(String name, int id) |
||
201 | { |
||
202 | super (name, id);
|
||
203 | } |
||
204 | |||
205 | protected void Entry(MoveCADToolContext context) |
||
206 | { |
||
207 | MoveCADTool ctxt = context.getOwner(); |
||
208 | |||
209 | ctxt.selection(); |
||
210 | 4892 | caballero | ctxt.setQuestion(PluginServices.getText(this,"insert_point_move")); |
211 | 4584 | caballero | ctxt.setDescription(new String[]{"cancel"}); |
212 | 4434 | caballero | return;
|
213 | } |
||
214 | |||
215 | protected void addPoint(MoveCADToolContext context, double pointX, double pointY, InputEvent event) |
||
216 | { |
||
217 | MoveCADTool ctxt = context.getOwner(); |
||
218 | |||
219 | |||
220 | (context.getState()).Exit(context); |
||
221 | context.clearState(); |
||
222 | try
|
||
223 | { |
||
224 | 4584 | caballero | ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_move")); |
225 | ctxt.setDescription(new String[]{"cancel"}); |
||
226 | 4434 | caballero | ctxt.addPoint(pointX, pointY, event); |
227 | } |
||
228 | finally
|
||
229 | { |
||
230 | context.setState(Move.SecondPointToMove); |
||
231 | (context.getState()).Entry(context); |
||
232 | } |
||
233 | return;
|
||
234 | } |
||
235 | |||
236 | //-------------------------------------------------------
|
||
237 | // Member data.
|
||
238 | //
|
||
239 | } |
||
240 | |||
241 | private static final class Move_SecondPointToMove |
||
242 | extends Move_Default
|
||
243 | { |
||
244 | //-------------------------------------------------------
|
||
245 | // Member methods.
|
||
246 | //
|
||
247 | |||
248 | private Move_SecondPointToMove(String name, int id) |
||
249 | { |
||
250 | super (name, id);
|
||
251 | } |
||
252 | |||
253 | protected void addPoint(MoveCADToolContext context, double pointX, double pointY, InputEvent event) |
||
254 | { |
||
255 | MoveCADTool ctxt = context.getOwner(); |
||
256 | |||
257 | |||
258 | (context.getState()).Exit(context); |
||
259 | context.clearState(); |
||
260 | try
|
||
261 | { |
||
262 | 4584 | caballero | ctxt.setDescription(new String[]{"cancel"}); |
263 | 4434 | caballero | ctxt.addPoint(pointX, pointY, event); |
264 | ctxt.end(); |
||
265 | ctxt.refresh(); |
||
266 | } |
||
267 | finally
|
||
268 | { |
||
269 | context.setState(Move.FirstPointToMove); |
||
270 | (context.getState()).Entry(context); |
||
271 | } |
||
272 | return;
|
||
273 | } |
||
274 | |||
275 | //-------------------------------------------------------
|
||
276 | // Member data.
|
||
277 | //
|
||
278 | } |
||
279 | |||
280 | //-----------------------------------------------------------
|
||
281 | // Member data.
|
||
282 | //
|
||
283 | } |
||
284 | } |