root / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / automaton / Spline.java @ 1514
History | View | Annotate | Download (2.53 KB)
1 |
package com.iver.cit.gvsig.gui.cad.automaton; |
---|---|
2 |
|
3 |
public class Spline 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 ("cerrar".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 ("cancel".equalsIgnoreCase(label)){ |
64 |
previousStatus = status; |
65 |
status = -1;
|
66 |
|
67 |
return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
|
68 |
} |
69 |
|
70 |
break;
|
71 |
|
72 |
} |
73 |
|
74 |
return com.iver.fsac.Automaton.TRANSITION_FAILED;
|
75 |
} |
76 |
|
77 |
public int getPreviousStatus(){ |
78 |
return previousStatus;
|
79 |
} |
80 |
|
81 |
public int getStatus(){ |
82 |
return status;
|
83 |
} |
84 |
|
85 |
public boolean checkState(char c){ |
86 |
|
87 |
if (status == -1){ |
88 |
return "".indexOf(c) != -1; |
89 |
} |
90 |
|
91 |
if (status == 0){ |
92 |
return "".indexOf(c) != -1; |
93 |
} |
94 |
|
95 |
if (status == 1){ |
96 |
return "".indexOf(c) != -1; |
97 |
} |
98 |
|
99 |
if (status == 2){ |
100 |
return "".indexOf(c) != -1; |
101 |
} |
102 |
|
103 |
|
104 |
return false; |
105 |
} |
106 |
|
107 |
public String[] getCurrentTransitions(){ |
108 |
|
109 |
if (status == -1){ |
110 |
return new String[]{}; |
111 |
} |
112 |
|
113 |
if (status == 0){ |
114 |
return new String[]{"punto", "cancel"}; |
115 |
} |
116 |
|
117 |
if (status == 1){ |
118 |
return new String[]{"punto", "cerrar", "cancel"}; |
119 |
} |
120 |
|
121 |
if (status == 2){ |
122 |
return new String[]{"cancel"}; |
123 |
} |
124 |
|
125 |
|
126 |
throw new RuntimeException("Bug!"); |
127 |
} |
128 |
|
129 |
public String[] getCurrentTransitionDescriptions(){ |
130 |
|
131 |
if (status == -1){ |
132 |
return new String[]{}; |
133 |
} |
134 |
|
135 |
if (status == 0){ |
136 |
return new String[]{null, "Cancelar"}; |
137 |
} |
138 |
|
139 |
if (status == 1){ |
140 |
return new String[]{null, "Cerrar", "Cancelar"}; |
141 |
} |
142 |
|
143 |
if (status == 2){ |
144 |
return new String[]{"Cancelar"}; |
145 |
} |
146 |
|
147 |
|
148 |
throw new RuntimeException("Bug!"); |
149 |
} |
150 |
} |