Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / automaton / Poligono.java @ 1729

History | View | Annotate | Download (5.73 KB)

1
package com.iver.cit.gvsig.gui.cad.automaton;
2

    
3
public class Poligono 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 ("numero".equalsIgnoreCase(label)){
21
                                        previousStatus = status;
22
                                        status = 1;
23
                                        
24
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
25
                                }
26
                                
27
                                if ("".equalsIgnoreCase(label)){
28
                                        previousStatus = status;
29
                                        status = 7;
30
                                        
31
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
32
                                }
33
                                
34
                                if ("cancel".equalsIgnoreCase(label)){
35
                                        previousStatus = status;
36
                                        status = -1;
37
                                        
38
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
39
                                }
40
                                
41
                                break;
42
                
43
                        case 1:
44
                                
45
                                if ("punto".equalsIgnoreCase(label)){
46
                                        previousStatus = status;
47
                                        status = 2;
48
                                        
49
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
50
                                }
51
                                
52
                                if ("cancel".equalsIgnoreCase(label)){
53
                                        previousStatus = status;
54
                                        status = -1;
55
                                        
56
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
57
                                }
58
                                
59
                                break;
60
                
61
                        case 2:
62
                                
63
                                if ("".equalsIgnoreCase(label)){
64
                                        previousStatus = status;
65
                                        status = 3;
66
                                        
67
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
68
                                }
69
                                
70
                                if ("I".equalsIgnoreCase(label)){
71
                                        previousStatus = status;
72
                                        status = 3;
73
                                        
74
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
75
                                }
76
                                
77
                                if ("C".equalsIgnoreCase(label)){
78
                                        previousStatus = status;
79
                                        status = 4;
80
                                        
81
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
82
                                }
83
                                
84
                                if ("cancel".equalsIgnoreCase(label)){
85
                                        previousStatus = status;
86
                                        status = -1;
87
                                        
88
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
89
                                }
90
                                
91
                                break;
92
                
93
                        case 3:
94
                                
95
                                if ("numero".equalsIgnoreCase(label)){
96
                                        previousStatus = status;
97
                                        status = 5;
98
                                        
99
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
100
                                }
101
                                
102
                                if ("punto".equalsIgnoreCase(label)){
103
                                        previousStatus = status;
104
                                        status = 6;
105
                                        
106
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
107
                                }
108
                                
109
                                if ("cancel".equalsIgnoreCase(label)){
110
                                        previousStatus = status;
111
                                        status = -1;
112
                                        
113
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
114
                                }
115
                                
116
                                break;
117
                
118
                        case 4:
119
                                
120
                                if ("numero".equalsIgnoreCase(label)){
121
                                        previousStatus = status;
122
                                        status = 5;
123
                                        
124
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
125
                                }
126
                                
127
                                if ("punto".equalsIgnoreCase(label)){
128
                                        previousStatus = status;
129
                                        status = 6;
130
                                        
131
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
132
                                }
133
                                
134
                                if ("cancel".equalsIgnoreCase(label)){
135
                                        previousStatus = status;
136
                                        status = -1;
137
                                        
138
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
139
                                }
140
                                
141
                                break;
142
                
143
                        case 5:
144
                                
145
                                if ("cancel".equalsIgnoreCase(label)){
146
                                        previousStatus = status;
147
                                        status = -1;
148
                                        
149
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
150
                                }
151
                                
152
                                break;
153
                
154
                        case 6:
155
                                
156
                                if ("cancel".equalsIgnoreCase(label)){
157
                                        previousStatus = status;
158
                                        status = -1;
159
                                        
160
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
161
                                }
162
                                
163
                                break;
164
                
165
                        case 7:
166
                                
167
                                if ("punto".equalsIgnoreCase(label)){
168
                                        previousStatus = status;
169
                                        status = 2;
170
                                        
171
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
172
                                }
173
                                
174
                                if ("cancel".equalsIgnoreCase(label)){
175
                                        previousStatus = status;
176
                                        status = -1;
177
                                        
178
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
179
                                }
180
                                
181
                                break;
182
                
183
                }
184
                
185
                return com.iver.fsac.Automaton.TRANSITION_FAILED;
186
        }
187
        
188
        public int getPreviousStatus(){
189
                return previousStatus;
190
        }
191
        
192
        public int getStatus(){
193
                return status;
194
        }
195
        
196
        public boolean checkState(char c){
197
                
198
                if (status == -1){
199
                        return "".indexOf(c) != -1;
200
                }
201
                
202
                if (status == 0){
203
                        return "".indexOf(c) != -1;
204
                }
205
                
206
                if (status == 1){
207
                        return "".indexOf(c) != -1;
208
                }
209
                
210
                if (status == 2){
211
                        return "".indexOf(c) != -1;
212
                }
213
                
214
                if (status == 3){
215
                        return "".indexOf(c) != -1;
216
                }
217
                
218
                if (status == 4){
219
                        return "".indexOf(c) != -1;
220
                }
221
                
222
                if (status == 5){
223
                        return "".indexOf(c) != -1;
224
                }
225
                
226
                if (status == 6){
227
                        return "".indexOf(c) != -1;
228
                }
229
                
230
                if (status == 7){
231
                        return "".indexOf(c) != -1;
232
                }
233
                
234
                
235
                return false;
236
        }
237
        
238
        public String[] getCurrentTransitions(){
239
                
240
                if (status == -1){
241
                        return new String[]{};
242
                }
243
                
244
                if (status == 0){
245
                        return new String[]{"numero", "", "cancel"};
246
                }
247
                
248
                if (status == 1){
249
                        return new String[]{"punto", "cancel"};
250
                }
251
                
252
                if (status == 2){
253
                        return new String[]{"", "I", "C", "cancel"};
254
                }
255
                
256
                if (status == 3){
257
                        return new String[]{"numero", "punto", "cancel"};
258
                }
259
                
260
                if (status == 4){
261
                        return new String[]{"numero", "punto", "cancel"};
262
                }
263
                
264
                if (status == 5){
265
                        return new String[]{"cancel"};
266
                }
267
                
268
                if (status == 6){
269
                        return new String[]{"cancel"};
270
                }
271
                
272
                if (status == 7){
273
                        return new String[]{"punto", "cancel"};
274
                }
275
                
276
                
277
                throw new RuntimeException("Bug!");
278
        }
279
        
280
        public String[] getCurrentTransitionDescriptions(){
281
                
282
                if (status == -1){
283
                        return new String[]{};
284
                }
285
                
286
                if (status == 0){
287
                        return new String[]{null, null, "Cancelar"};
288
                }
289
                
290
                if (status == 1){
291
                        return new String[]{null, "Cancelar"};
292
                }
293
                
294
                if (status == 2){
295
                        return new String[]{null, "Inscrito", "Circunscrito", "Cancelar"};
296
                }
297
                
298
                if (status == 3){
299
                        return new String[]{null, null, "Cancelar"};
300
                }
301
                
302
                if (status == 4){
303
                        return new String[]{null, null, "Cancelar"};
304
                }
305
                
306
                if (status == 5){
307
                        return new String[]{"Cancelar"};
308
                }
309
                
310
                if (status == 6){
311
                        return new String[]{"Cancelar"};
312
                }
313
                
314
                if (status == 7){
315
                        return new String[]{null, "Cancelar"};
316
                }
317
                
318
                
319
                throw new RuntimeException("Bug!");
320
        }
321
}