Statistics
| Revision:

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

History | View | Annotate | Download (2.89 KB)

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

    
3
public class Girar 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 = 2;
41
                                        
42
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
43
                                }
44
                                
45
                                if ("numero".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 ("cancel".equalsIgnoreCase(label)){
64
                                        previousStatus = status;
65
                                        status = -1;
66
                                        
67
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
68
                                }
69
                                
70
                                break;
71
                
72
                        case 3:
73
                                
74
                                if ("cancel".equalsIgnoreCase(label)){
75
                                        previousStatus = status;
76
                                        status = -1;
77
                                        
78
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
79
                                }
80
                                
81
                                break;
82
                
83
                }
84
                
85
                return com.iver.fsac.Automaton.TRANSITION_FAILED;
86
        }
87
        
88
        public int getPreviousStatus(){
89
                return previousStatus;
90
        }
91
        
92
        public int getStatus(){
93
                return status;
94
        }
95
        
96
        public boolean checkState(char c){
97
                
98
                if (status == -1){
99
                        return "".indexOf(c) != -1;
100
                }
101
                
102
                if (status == 0){
103
                        return "".indexOf(c) != -1;
104
                }
105
                
106
                if (status == 1){
107
                        return "".indexOf(c) != -1;
108
                }
109
                
110
                if (status == 2){
111
                        return "".indexOf(c) != -1;
112
                }
113
                
114
                if (status == 3){
115
                        return "".indexOf(c) != -1;
116
                }
117
                
118
                
119
                return false;
120
        }
121
        
122
        public String[] getCurrentTransitions(){
123
                
124
                if (status == -1){
125
                        return new String[]{};
126
                }
127
                
128
                if (status == 0){
129
                        return new String[]{"punto", "cancel"};
130
                }
131
                
132
                if (status == 1){
133
                        return new String[]{"punto", "numero", "cancel"};
134
                }
135
                
136
                if (status == 2){
137
                        return new String[]{"cancel"};
138
                }
139
                
140
                if (status == 3){
141
                        return new String[]{"cancel"};
142
                }
143
                
144
                
145
                throw new RuntimeException("Bug!");
146
        }
147
        
148
        public String[] getCurrentTransitionDescriptions(){
149
                
150
                if (status == -1){
151
                        return new String[]{};
152
                }
153
                
154
                if (status == 0){
155
                        return new String[]{null, "Cancelar"};
156
                }
157
                
158
                if (status == 1){
159
                        return new String[]{null, null, "Cancelar"};
160
                }
161
                
162
                if (status == 2){
163
                        return new String[]{"Cancelar"};
164
                }
165
                
166
                if (status == 3){
167
                        return new String[]{"Cancelar"};
168
                }
169
                
170
                
171
                throw new RuntimeException("Bug!");
172
        }
173
}