Statistics
| Revision:

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

History | View | Annotate | Download (3.22 KB)

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

    
3
public class Recortar 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 ("aceptar".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 = 3;
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
                }
98
                
99
                return com.iver.fsac.Automaton.TRANSITION_FAILED;
100
        }
101
        
102
        public int getPreviousStatus(){
103
                return previousStatus;
104
        }
105
        
106
        public int getStatus(){
107
                return status;
108
        }
109
        
110
        public boolean checkState(char c){
111
                
112
                if (status == -1){
113
                        return "".indexOf(c) != -1;
114
                }
115
                
116
                if (status == 0){
117
                        return "".indexOf(c) != -1;
118
                }
119
                
120
                if (status == 1){
121
                        return "".indexOf(c) != -1;
122
                }
123
                
124
                if (status == 2){
125
                        return "".indexOf(c) != -1;
126
                }
127
                
128
                if (status == 3){
129
                        return "".indexOf(c) != -1;
130
                }
131
                
132
                
133
                return false;
134
        }
135
        
136
        public String[] getCurrentTransitions(){
137
                
138
                if (status == -1){
139
                        return new String[]{};
140
                }
141
                
142
                if (status == 0){
143
                        return new String[]{"punto", "cancel"};
144
                }
145
                
146
                if (status == 1){
147
                        return new String[]{"punto", "aceptar", "cancel"};
148
                }
149
                
150
                if (status == 2){
151
                        return new String[]{"punto", "cancel"};
152
                }
153
                
154
                if (status == 3){
155
                        return new String[]{"punto", "cancel"};
156
                }
157
                
158
                
159
                throw new RuntimeException("Bug!");
160
        }
161
        
162
        public String[] getCurrentTransitionDescriptions(){
163
                
164
                if (status == -1){
165
                        return new String[]{};
166
                }
167
                
168
                if (status == 0){
169
                        return new String[]{null, null};
170
                }
171
                
172
                if (status == 1){
173
                        return new String[]{null, null, null};
174
                }
175
                
176
                if (status == 2){
177
                        return new String[]{null, null};
178
                }
179
                
180
                if (status == 3){
181
                        return new String[]{null, null};
182
                }
183
                
184
                
185
                throw new RuntimeException("Bug!");
186
        }
187
}