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