root / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / automaton / Polilinea.java @ 1514
History | View | Annotate | Download (5.03 KB)
1 |
package com.iver.cit.gvsig.gui.cad.automaton; |
---|---|
2 |
|
3 |
public class Polilinea implements com.iver.fsac.Automaton{ |
4 |
private int previousStatus = com.iver.fsac.Automaton.FINISHED; |
5 |
private int status = 0; |
6 |
|
7 |
public void initialize() { |
8 |
status = 0;
|
9 |
} |
10 |
|
11 |
public int transition(String label){ |
12 |
switch (status){
|
13 |
|
14 |
case -1: |
15 |
|
16 |
break;
|
17 |
|
18 |
case 0: |
19 |
|
20 |
if ("punto".equalsIgnoreCase(label)){ |
21 |
previousStatus = status; |
22 |
status = 1;
|
23 |
|
24 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
25 |
} |
26 |
|
27 |
if ("cancel".equalsIgnoreCase(label)){ |
28 |
previousStatus = status; |
29 |
status = -1;
|
30 |
|
31 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
32 |
} |
33 |
|
34 |
break;
|
35 |
|
36 |
case 1: |
37 |
|
38 |
if ("punto".equalsIgnoreCase(label)){ |
39 |
previousStatus = status; |
40 |
status = 1;
|
41 |
|
42 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
43 |
} |
44 |
|
45 |
if ("A".equalsIgnoreCase(label)){ |
46 |
previousStatus = status; |
47 |
status = 2;
|
48 |
|
49 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
50 |
} |
51 |
|
52 |
if ("cerrar".equalsIgnoreCase(label)){ |
53 |
previousStatus = status; |
54 |
status = 4;
|
55 |
|
56 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
57 |
} |
58 |
|
59 |
if ("aceptar".equalsIgnoreCase(label)){ |
60 |
previousStatus = status; |
61 |
status = 5;
|
62 |
|
63 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
64 |
} |
65 |
|
66 |
if ("cancel".equalsIgnoreCase(label)){ |
67 |
previousStatus = status; |
68 |
status = -1;
|
69 |
|
70 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
71 |
} |
72 |
|
73 |
break;
|
74 |
|
75 |
case 2: |
76 |
|
77 |
if ("N".equalsIgnoreCase(label)){ |
78 |
previousStatus = status; |
79 |
status = 1;
|
80 |
|
81 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
82 |
} |
83 |
|
84 |
if ("punto".equalsIgnoreCase(label)){ |
85 |
previousStatus = status; |
86 |
status = 3;
|
87 |
|
88 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
89 |
} |
90 |
|
91 |
if ("cancel".equalsIgnoreCase(label)){ |
92 |
previousStatus = status; |
93 |
status = -1;
|
94 |
|
95 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
96 |
} |
97 |
|
98 |
break;
|
99 |
|
100 |
case 3: |
101 |
|
102 |
if ("punto".equalsIgnoreCase(label)){ |
103 |
previousStatus = status; |
104 |
status = 3;
|
105 |
|
106 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
107 |
} |
108 |
|
109 |
if ("N".equalsIgnoreCase(label)){ |
110 |
previousStatus = status; |
111 |
status = 1;
|
112 |
|
113 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
114 |
} |
115 |
|
116 |
if ("cerrar".equalsIgnoreCase(label)){ |
117 |
previousStatus = status; |
118 |
status = 4;
|
119 |
|
120 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
121 |
} |
122 |
|
123 |
if ("aceptar".equalsIgnoreCase(label)){ |
124 |
previousStatus = status; |
125 |
status = 5;
|
126 |
|
127 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
128 |
} |
129 |
|
130 |
if ("cancel".equalsIgnoreCase(label)){ |
131 |
previousStatus = status; |
132 |
status = -1;
|
133 |
|
134 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
135 |
} |
136 |
|
137 |
break;
|
138 |
|
139 |
case 4: |
140 |
|
141 |
if ("cancel".equalsIgnoreCase(label)){ |
142 |
previousStatus = status; |
143 |
status = -1;
|
144 |
|
145 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
146 |
} |
147 |
|
148 |
break;
|
149 |
|
150 |
case 5: |
151 |
|
152 |
if ("cancel".equalsIgnoreCase(label)){ |
153 |
previousStatus = status; |
154 |
status = -1;
|
155 |
|
156 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
157 |
} |
158 |
|
159 |
break;
|
160 |
|
161 |
} |
162 |
|
163 |
return com.iver.fsac.Automaton.TRANSITION_FAILED;
|
164 |
} |
165 |
|
166 |
public int getPreviousStatus(){ |
167 |
return previousStatus;
|
168 |
} |
169 |
|
170 |
public int getStatus(){ |
171 |
return status;
|
172 |
} |
173 |
|
174 |
public boolean checkState(char c){ |
175 |
|
176 |
if (status == -1){ |
177 |
return "".indexOf(c) != -1; |
178 |
} |
179 |
|
180 |
if (status == 0){ |
181 |
return "".indexOf(c) != -1; |
182 |
} |
183 |
|
184 |
if (status == 1){ |
185 |
return "".indexOf(c) != -1; |
186 |
} |
187 |
|
188 |
if (status == 2){ |
189 |
return "".indexOf(c) != -1; |
190 |
} |
191 |
|
192 |
if (status == 3){ |
193 |
return "".indexOf(c) != -1; |
194 |
} |
195 |
|
196 |
if (status == 4){ |
197 |
return "".indexOf(c) != -1; |
198 |
} |
199 |
|
200 |
if (status == 5){ |
201 |
return "".indexOf(c) != -1; |
202 |
} |
203 |
|
204 |
|
205 |
return false; |
206 |
} |
207 |
|
208 |
public String[] getCurrentTransitions(){ |
209 |
|
210 |
if (status == -1){ |
211 |
return new String[]{}; |
212 |
} |
213 |
|
214 |
if (status == 0){ |
215 |
return new String[]{"punto", "cancel"}; |
216 |
} |
217 |
|
218 |
if (status == 1){ |
219 |
return new String[]{"punto", "A", "cerrar", "aceptar", "cancel"}; |
220 |
} |
221 |
|
222 |
if (status == 2){ |
223 |
return new String[]{"N", "punto", "cancel"}; |
224 |
} |
225 |
|
226 |
if (status == 3){ |
227 |
return new String[]{"punto", "N", "cerrar", "aceptar", "cancel"}; |
228 |
} |
229 |
|
230 |
if (status == 4){ |
231 |
return new String[]{"cancel"}; |
232 |
} |
233 |
|
234 |
if (status == 5){ |
235 |
return new String[]{"cancel"}; |
236 |
} |
237 |
|
238 |
|
239 |
throw new RuntimeException("Bug!"); |
240 |
} |
241 |
|
242 |
public String[] getCurrentTransitionDescriptions(){ |
243 |
|
244 |
if (status == -1){ |
245 |
return new String[]{}; |
246 |
} |
247 |
|
248 |
if (status == 0){ |
249 |
return new String[]{null, "Cancelar"}; |
250 |
} |
251 |
|
252 |
if (status == 1){ |
253 |
return new String[]{null, "Arco", "Cerrar", "Aceptar", "Cancelar"}; |
254 |
} |
255 |
|
256 |
if (status == 2){ |
257 |
return new String[]{"Linea", null, "Cancelar"}; |
258 |
} |
259 |
|
260 |
if (status == 3){ |
261 |
return new String[]{null, "Linea", "Cerrar", "Aceptar", "Cancelar"}; |
262 |
} |
263 |
|
264 |
if (status == 4){ |
265 |
return new String[]{"Cancelar"}; |
266 |
} |
267 |
|
268 |
if (status == 5){ |
269 |
return new String[]{"Cancelar"}; |
270 |
} |
271 |
|
272 |
|
273 |
throw new RuntimeException("Bug!"); |
274 |
} |
275 |
} |