root / branches / gvSIG_CAD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / automaton / Simetria.java @ 3513
History | View | Annotate | Download (3.59 KB)
1 |
package com.iver.cit.gvsig.gui.cad.automaton; |
---|---|
2 |
|
3 |
public class Simetria 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 ("cancel".equalsIgnoreCase(label)){ |
46 |
previousStatus = status; |
47 |
status = -1;
|
48 |
|
49 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
50 |
} |
51 |
|
52 |
break;
|
53 |
|
54 |
case 2: |
55 |
|
56 |
if ("".equalsIgnoreCase(label)){ |
57 |
previousStatus = status; |
58 |
status = 3;
|
59 |
|
60 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
61 |
} |
62 |
|
63 |
if ("S".equalsIgnoreCase(label)){ |
64 |
previousStatus = status; |
65 |
status = 3;
|
66 |
|
67 |
return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
|
68 |
} |
69 |
|
70 |
if ("N".equalsIgnoreCase(label)){ |
71 |
previousStatus = status; |
72 |
status = 4;
|
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 ("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 ("cancel".equalsIgnoreCase(label)){ |
100 |
previousStatus = status; |
101 |
status = -1;
|
102 |
|
103 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
104 |
} |
105 |
|
106 |
break;
|
107 |
|
108 |
} |
109 |
|
110 |
return com.iver.fsac.Automaton.TRANSITION_FAILED;
|
111 |
} |
112 |
|
113 |
public int getPreviousStatus(){ |
114 |
return previousStatus;
|
115 |
} |
116 |
|
117 |
public int getStatus(){ |
118 |
return status;
|
119 |
} |
120 |
|
121 |
public boolean checkState(char c){ |
122 |
|
123 |
if (status == -1){ |
124 |
return "".indexOf(c) != -1; |
125 |
} |
126 |
|
127 |
if (status == 0){ |
128 |
return "".indexOf(c) != -1; |
129 |
} |
130 |
|
131 |
if (status == 1){ |
132 |
return "".indexOf(c) != -1; |
133 |
} |
134 |
|
135 |
if (status == 2){ |
136 |
return "".indexOf(c) != -1; |
137 |
} |
138 |
|
139 |
if (status == 3){ |
140 |
return "".indexOf(c) != -1; |
141 |
} |
142 |
|
143 |
if (status == 4){ |
144 |
return "".indexOf(c) != -1; |
145 |
} |
146 |
|
147 |
|
148 |
return false; |
149 |
} |
150 |
|
151 |
public String[] getCurrentTransitions(){ |
152 |
|
153 |
if (status == -1){ |
154 |
return new String[]{}; |
155 |
} |
156 |
|
157 |
if (status == 0){ |
158 |
return new String[]{"punto", "cancel"}; |
159 |
} |
160 |
|
161 |
if (status == 1){ |
162 |
return new String[]{"punto", "cancel"}; |
163 |
} |
164 |
|
165 |
if (status == 2){ |
166 |
return new String[]{"", "S", "N", "cancel"}; |
167 |
} |
168 |
|
169 |
if (status == 3){ |
170 |
return new String[]{"cancel"}; |
171 |
} |
172 |
|
173 |
if (status == 4){ |
174 |
return new String[]{"cancel"}; |
175 |
} |
176 |
|
177 |
|
178 |
throw new RuntimeException("Bug!"); |
179 |
} |
180 |
|
181 |
public String[] getCurrentTransitionDescriptions(){ |
182 |
|
183 |
if (status == -1){ |
184 |
return new String[]{}; |
185 |
} |
186 |
|
187 |
if (status == 0){ |
188 |
return new String[]{null, "Cancelar"}; |
189 |
} |
190 |
|
191 |
if (status == 1){ |
192 |
return new String[]{null, "Cancelar"}; |
193 |
} |
194 |
|
195 |
if (status == 2){ |
196 |
return new String[]{null, "Borrar", "Copiar", "Cancelar"}; |
197 |
} |
198 |
|
199 |
if (status == 3){ |
200 |
return new String[]{"Cancelar"}; |
201 |
} |
202 |
|
203 |
if (status == 4){ |
204 |
return new String[]{"Cancelar"}; |
205 |
} |
206 |
|
207 |
|
208 |
throw new RuntimeException("Bug!"); |
209 |
} |
210 |
} |