Statistics
| Revision:

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

History | View | Annotate | Download (3.4 KB)

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

    
3
public class Rectangulo 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 ("C".equalsIgnoreCase(label)){
39
                                        previousStatus = status;
40
                                        status = 2;
41
                                        
42
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
43
                                }
44
                                
45
                                if ("punto".equalsIgnoreCase(label)){
46
                                        previousStatus = status;
47
                                        status = 3;
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 = 4;
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 ("cancel".equalsIgnoreCase(label)){
82
                                        previousStatus = status;
83
                                        status = -1;
84
                                        
85
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
86
                                }
87
                                
88
                                break;
89
                
90
                        case 4:
91
                                
92
                                if ("cancel".equalsIgnoreCase(label)){
93
                                        previousStatus = status;
94
                                        status = -1;
95
                                        
96
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
97
                                }
98
                                
99
                                break;
100
                
101
                }
102
                
103
                return com.iver.fsac.Automaton.TRANSITION_FAILED;
104
        }
105
        
106
        public int getPreviousStatus(){
107
                return previousStatus;
108
        }
109
        
110
        public int getStatus(){
111
                return status;
112
        }
113
        
114
        public boolean checkState(char c){
115
                
116
                if (status == -1){
117
                        return "".indexOf(c) != -1;
118
                }
119
                
120
                if (status == 0){
121
                        return "".indexOf(c) != -1;
122
                }
123
                
124
                if (status == 1){
125
                        return "".indexOf(c) != -1;
126
                }
127
                
128
                if (status == 2){
129
                        return "".indexOf(c) != -1;
130
                }
131
                
132
                if (status == 3){
133
                        return "".indexOf(c) != -1;
134
                }
135
                
136
                if (status == 4){
137
                        return "".indexOf(c) != -1;
138
                }
139
                
140
                
141
                return false;
142
        }
143
        
144
        public String[] getCurrentTransitions(){
145
                
146
                if (status == -1){
147
                        return new String[]{};
148
                }
149
                
150
                if (status == 0){
151
                        return new String[]{"punto", "cancel"};
152
                }
153
                
154
                if (status == 1){
155
                        return new String[]{"C", "punto", "cancel"};
156
                }
157
                
158
                if (status == 2){
159
                        return new String[]{"punto", "cancel"};
160
                }
161
                
162
                if (status == 3){
163
                        return new String[]{"cancel"};
164
                }
165
                
166
                if (status == 4){
167
                        return new String[]{"cancel"};
168
                }
169
                
170
                
171
                throw new RuntimeException("Bug!");
172
        }
173
        
174
        public String[] getCurrentTransitionDescriptions(){
175
                
176
                if (status == -1){
177
                        return new String[]{};
178
                }
179
                
180
                if (status == 0){
181
                        return new String[]{null, null};
182
                }
183
                
184
                if (status == 1){
185
                        return new String[]{null, null, null};
186
                }
187
                
188
                if (status == 2){
189
                        return new String[]{null, null};
190
                }
191
                
192
                if (status == 3){
193
                        return new String[]{null};
194
                }
195
                
196
                if (status == 4){
197
                        return new String[]{null};
198
                }
199
                
200
                
201
                throw new RuntimeException("Bug!");
202
        }
203
}