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