Statistics
| Revision:

root / branches / gvSIG_CAD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / automaton / Equidistancia.java @ 3513

History | View | Annotate | Download (3.79 KB)

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

    
3
public class Equidistancia 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 ("numero".equalsIgnoreCase(label)){
28
                                        previousStatus = status;
29
                                        status = 2;
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 ("punto".equalsIgnoreCase(label)){
64
                                        previousStatus = status;
65
                                        status = 3;
66
                                        
67
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
68
                                }
69
                                
70
                                if ("cancel".equalsIgnoreCase(label)){
71
                                        previousStatus = status;
72
                                        status = -1;
73
                                        
74
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
75
                                }
76
                                
77
                                break;
78
                
79
                        case 3:
80
                                
81
                                if ("punto".equalsIgnoreCase(label)){
82
                                        previousStatus = status;
83
                                        status = 4;
84
                                        
85
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
86
                                }
87
                                
88
                                if ("cancel".equalsIgnoreCase(label)){
89
                                        previousStatus = status;
90
                                        status = -1;
91
                                        
92
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
93
                                }
94
                                
95
                                break;
96
                
97
                        case 4:
98
                                
99
                                if ("punto".equalsIgnoreCase(label)){
100
                                        previousStatus = status;
101
                                        status = 3;
102
                                        
103
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
104
                                }
105
                                
106
                                if ("cancel".equalsIgnoreCase(label)){
107
                                        previousStatus = status;
108
                                        status = -1;
109
                                        
110
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
111
                                }
112
                                
113
                                break;
114
                
115
                }
116
                
117
                return com.iver.fsac.Automaton.TRANSITION_FAILED;
118
        }
119
        
120
        public int getPreviousStatus(){
121
                return previousStatus;
122
        }
123
        
124
        public int getStatus(){
125
                return status;
126
        }
127
        
128
        public boolean checkState(char c){
129
                
130
                if (status == -1){
131
                        return "".indexOf(c) != -1;
132
                }
133
                
134
                if (status == 0){
135
                        return "".indexOf(c) != -1;
136
                }
137
                
138
                if (status == 1){
139
                        return "".indexOf(c) != -1;
140
                }
141
                
142
                if (status == 2){
143
                        return "".indexOf(c) != -1;
144
                }
145
                
146
                if (status == 3){
147
                        return "".indexOf(c) != -1;
148
                }
149
                
150
                if (status == 4){
151
                        return "".indexOf(c) != -1;
152
                }
153
                
154
                
155
                return false;
156
        }
157
        
158
        public String[] getCurrentTransitions(){
159
                
160
                if (status == -1){
161
                        return new String[]{};
162
                }
163
                
164
                if (status == 0){
165
                        return new String[]{"punto", "numero", "cancel"};
166
                }
167
                
168
                if (status == 1){
169
                        return new String[]{"punto", "cancel"};
170
                }
171
                
172
                if (status == 2){
173
                        return new String[]{"punto", "cancel"};
174
                }
175
                
176
                if (status == 3){
177
                        return new String[]{"punto", "cancel"};
178
                }
179
                
180
                if (status == 4){
181
                        return new String[]{"punto", "cancel"};
182
                }
183
                
184
                
185
                throw new RuntimeException("Bug!");
186
        }
187
        
188
        public String[] getCurrentTransitionDescriptions(){
189
                
190
                if (status == -1){
191
                        return new String[]{};
192
                }
193
                
194
                if (status == 0){
195
                        return new String[]{null, null, "Cancelar"};
196
                }
197
                
198
                if (status == 1){
199
                        return new String[]{null, "Cancelar"};
200
                }
201
                
202
                if (status == 2){
203
                        return new String[]{null, "Cancelar"};
204
                }
205
                
206
                if (status == 3){
207
                        return new String[]{null, "Cancelar"};
208
                }
209
                
210
                if (status == 4){
211
                        return new String[]{null, "Cancelar"};
212
                }
213
                
214
                
215
                throw new RuntimeException("Bug!");
216
        }
217
}