Statistics
| Revision:

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

History | View | Annotate | Download (5.35 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 ("".equalsIgnoreCase(label)){
60
                                        previousStatus = status;
61
                                        status = 5;
62
                                        
63
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
64
                                }
65
                                
66
                                if ("aceptar".equalsIgnoreCase(label)){
67
                                        previousStatus = status;
68
                                        status = 5;
69
                                        
70
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
71
                                }
72
                                
73
                                if ("cancel".equalsIgnoreCase(label)){
74
                                        previousStatus = status;
75
                                        status = -1;
76
                                        
77
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
78
                                }
79
                                
80
                                break;
81
                
82
                        case 2:
83
                                
84
                                if ("N".equalsIgnoreCase(label)){
85
                                        previousStatus = status;
86
                                        status = 1;
87
                                        
88
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
89
                                }
90
                                
91
                                if ("punto".equalsIgnoreCase(label)){
92
                                        previousStatus = status;
93
                                        status = 3;
94
                                        
95
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
96
                                }
97
                                
98
                                if ("cancel".equalsIgnoreCase(label)){
99
                                        previousStatus = status;
100
                                        status = -1;
101
                                        
102
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
103
                                }
104
                                
105
                                break;
106
                
107
                        case 3:
108
                                
109
                                if ("punto".equalsIgnoreCase(label)){
110
                                        previousStatus = status;
111
                                        status = 3;
112
                                        
113
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
114
                                }
115
                                
116
                                if ("N".equalsIgnoreCase(label)){
117
                                        previousStatus = status;
118
                                        status = 1;
119
                                        
120
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
121
                                }
122
                                
123
                                if ("cerrar".equalsIgnoreCase(label)){
124
                                        previousStatus = status;
125
                                        status = 4;
126
                                        
127
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
128
                                }
129
                                
130
                                if ("".equalsIgnoreCase(label)){
131
                                        previousStatus = status;
132
                                        status = 5;
133
                                        
134
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
135
                                }
136
                                
137
                                if ("aceptar".equalsIgnoreCase(label)){
138
                                        previousStatus = status;
139
                                        status = 5;
140
                                        
141
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
142
                                }
143
                                
144
                                if ("cancel".equalsIgnoreCase(label)){
145
                                        previousStatus = status;
146
                                        status = -1;
147
                                        
148
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
149
                                }
150
                                
151
                                break;
152
                
153
                        case 4:
154
                                
155
                                if ("cancel".equalsIgnoreCase(label)){
156
                                        previousStatus = status;
157
                                        status = -1;
158
                                        
159
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
160
                                }
161
                                
162
                                break;
163
                
164
                        case 5:
165
                                
166
                                if ("cancel".equalsIgnoreCase(label)){
167
                                        previousStatus = status;
168
                                        status = -1;
169
                                        
170
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
171
                                }
172
                                
173
                                break;
174
                
175
                }
176
                
177
                return com.iver.fsac.Automaton.TRANSITION_FAILED;
178
        }
179
        
180
        public int getPreviousStatus(){
181
                return previousStatus;
182
        }
183
        
184
        public int getStatus(){
185
                return status;
186
        }
187
        
188
        public boolean checkState(char c){
189
                
190
                if (status == -1){
191
                        return "".indexOf(c) != -1;
192
                }
193
                
194
                if (status == 0){
195
                        return "".indexOf(c) != -1;
196
                }
197
                
198
                if (status == 1){
199
                        return "".indexOf(c) != -1;
200
                }
201
                
202
                if (status == 2){
203
                        return "".indexOf(c) != -1;
204
                }
205
                
206
                if (status == 3){
207
                        return "".indexOf(c) != -1;
208
                }
209
                
210
                if (status == 4){
211
                        return "".indexOf(c) != -1;
212
                }
213
                
214
                if (status == 5){
215
                        return "".indexOf(c) != -1;
216
                }
217
                
218
                
219
                return false;
220
        }
221
        
222
        public String[] getCurrentTransitions(){
223
                
224
                if (status == -1){
225
                        return new String[]{};
226
                }
227
                
228
                if (status == 0){
229
                        return new String[]{"punto", "cancel"};
230
                }
231
                
232
                if (status == 1){
233
                        return new String[]{"punto", "A", "cerrar", "", "aceptar", "cancel"};
234
                }
235
                
236
                if (status == 2){
237
                        return new String[]{"N", "punto", "cancel"};
238
                }
239
                
240
                if (status == 3){
241
                        return new String[]{"punto", "N", "cerrar", "", "aceptar", "cancel"};
242
                }
243
                
244
                if (status == 4){
245
                        return new String[]{"cancel"};
246
                }
247
                
248
                if (status == 5){
249
                        return new String[]{"cancel"};
250
                }
251
                
252
                
253
                throw new RuntimeException("Bug!");
254
        }
255
        
256
        public String[] getCurrentTransitionDescriptions(){
257
                
258
                if (status == -1){
259
                        return new String[]{};
260
                }
261
                
262
                if (status == 0){
263
                        return new String[]{null, "Cancelar"};
264
                }
265
                
266
                if (status == 1){
267
                        return new String[]{null, "Arco", "Cerrar", null, "Aceptar", "Cancelar"};
268
                }
269
                
270
                if (status == 2){
271
                        return new String[]{"Linea", null, "Cancelar"};
272
                }
273
                
274
                if (status == 3){
275
                        return new String[]{null, "Linea", "Cerrar", null, "Aceptar", "Cancelar"};
276
                }
277
                
278
                if (status == 4){
279
                        return new String[]{"Cancelar"};
280
                }
281
                
282
                if (status == 5){
283
                        return new String[]{"Cancelar"};
284
                }
285
                
286
                
287
                throw new RuntimeException("Bug!");
288
        }
289
}