Statistics
| Revision:

svn-gvsig-desktop / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / automaton / Seleccion.java @ 1570

History | View | Annotate | Download (4.67 KB)

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

    
3
public class Seleccion 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 ("no_sel".equalsIgnoreCase(label)){
39
                                        previousStatus = status;
40
                                        status = 2;
41
                                        
42
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
43
                                }
44
                                
45
                                if ("sel".equalsIgnoreCase(label)){
46
                                        previousStatus = status;
47
                                        status = 0;
48
                                        
49
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
50
                                }
51
                                
52
                                if ("handler".equalsIgnoreCase(label)){
53
                                        previousStatus = status;
54
                                        status = 4;
55
                                        
56
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
57
                                }
58
                                
59
                                if ("cancel".equalsIgnoreCase(label)){
60
                                        previousStatus = status;
61
                                        status = -1;
62
                                        
63
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
64
                                }
65
                                
66
                                break;
67
                
68
                        case 2:
69
                                
70
                                if ("punto".equalsIgnoreCase(label)){
71
                                        previousStatus = status;
72
                                        status = 3;
73
                                        
74
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
75
                                }
76
                                
77
                                if ("cancel".equalsIgnoreCase(label)){
78
                                        previousStatus = status;
79
                                        status = -1;
80
                                        
81
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
82
                                }
83
                                
84
                                break;
85
                
86
                        case 3:
87
                                
88
                                if ("sel".equalsIgnoreCase(label)){
89
                                        previousStatus = status;
90
                                        status = 0;
91
                                        
92
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
93
                                }
94
                                
95
                                if ("no_sel".equalsIgnoreCase(label)){
96
                                        previousStatus = status;
97
                                        status = 0;
98
                                        
99
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
100
                                }
101
                                
102
                                if ("cancel".equalsIgnoreCase(label)){
103
                                        previousStatus = status;
104
                                        status = -1;
105
                                        
106
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
107
                                }
108
                                
109
                                break;
110
                
111
                        case 4:
112
                                
113
                                if ("punto".equalsIgnoreCase(label)){
114
                                        previousStatus = status;
115
                                        status = 5;
116
                                        
117
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
118
                                }
119
                                
120
                                if ("cancel".equalsIgnoreCase(label)){
121
                                        previousStatus = status;
122
                                        status = -1;
123
                                        
124
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
125
                                }
126
                                
127
                                break;
128
                
129
                        case 5:
130
                                
131
                                if ("done".equalsIgnoreCase(label)){
132
                                        previousStatus = status;
133
                                        status = 0;
134
                                        
135
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
136
                                }
137
                                
138
                                if ("cancel".equalsIgnoreCase(label)){
139
                                        previousStatus = status;
140
                                        status = -1;
141
                                        
142
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
143
                                }
144
                                
145
                                break;
146
                
147
                }
148
                
149
                return com.iver.fsac.Automaton.TRANSITION_FAILED;
150
        }
151
        
152
        public int getPreviousStatus(){
153
                return previousStatus;
154
        }
155
        
156
        public int getStatus(){
157
                return status;
158
        }
159
        
160
        public boolean checkState(char c){
161
                
162
                if (status == -1){
163
                        return "".indexOf(c) != -1;
164
                }
165
                
166
                if (status == 0){
167
                        return "cs".indexOf(c) != -1;
168
                }
169
                
170
                if (status == 1){
171
                        return "".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
                return false;
192
        }
193
        
194
        public String[] getCurrentTransitions(){
195
                
196
                if (status == -1){
197
                        return new String[]{};
198
                }
199
                
200
                if (status == 0){
201
                        return new String[]{"punto", "cancel"};
202
                }
203
                
204
                if (status == 1){
205
                        return new String[]{"no_sel", "sel", "handler", "cancel"};
206
                }
207
                
208
                if (status == 2){
209
                        return new String[]{"punto", "cancel"};
210
                }
211
                
212
                if (status == 3){
213
                        return new String[]{"sel", "no_sel", "cancel"};
214
                }
215
                
216
                if (status == 4){
217
                        return new String[]{"punto", "cancel"};
218
                }
219
                
220
                if (status == 5){
221
                        return new String[]{"done", "cancel"};
222
                }
223
                
224
                
225
                throw new RuntimeException("Bug!");
226
        }
227
        
228
        public String[] getCurrentTransitionDescriptions(){
229
                
230
                if (status == -1){
231
                        return new String[]{};
232
                }
233
                
234
                if (status == 0){
235
                        return new String[]{null, "Cancelar"};
236
                }
237
                
238
                if (status == 1){
239
                        return new String[]{null, null, null, "Cancelar"};
240
                }
241
                
242
                if (status == 2){
243
                        return new String[]{null, "Cancelar"};
244
                }
245
                
246
                if (status == 3){
247
                        return new String[]{null, 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, "Cancelar"};
256
                }
257
                
258
                
259
                throw new RuntimeException("Bug!");
260
        }
261
}