Statistics
| Revision:

root / branches / pilotoDWG / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / automaton / Spline.java @ 1514

History | View | Annotate | Download (2.53 KB)

1 1487 fernando
package com.iver.cit.gvsig.gui.cad.automaton;
2
3
public class Spline implements com.iver.fsac.Automaton{
4 1497 fernando
        private int previousStatus = com.iver.fsac.Automaton.FINISHED;
5 1487 fernando
        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 1498 fernando
                        case -1:
15
16
                                break;
17
18 1487 fernando
                        case 0:
19
20
                                if ("punto".equalsIgnoreCase(label)){
21 1497 fernando
                                        previousStatus = status;
22 1487 fernando
                                        status = 1;
23
24
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
25
                                }
26
27
                                if ("cancel".equalsIgnoreCase(label)){
28 1497 fernando
                                        previousStatus = status;
29 1498 fernando
                                        status = -1;
30 1487 fernando
31
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
32
                                }
33
34
                                break;
35
36
                        case 1:
37
38
                                if ("punto".equalsIgnoreCase(label)){
39 1497 fernando
                                        previousStatus = status;
40 1487 fernando
                                        status = 1;
41
42
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
43
                                }
44
45
                                if ("cerrar".equalsIgnoreCase(label)){
46 1497 fernando
                                        previousStatus = status;
47 1487 fernando
                                        status = 2;
48
49
                                        return com.iver.fsac.Automaton.TRANSITION_SUCCESS;
50
                                }
51
52
                                if ("cancel".equalsIgnoreCase(label)){
53 1497 fernando
                                        previousStatus = status;
54 1498 fernando
                                        status = -1;
55 1487 fernando
56
                                        return com.iver.fsac.Automaton.AUTOMATON_FINISHED;
57
                                }
58
59
                                break;
60
61
                        case 2:
62
63
                                if ("cancel".equalsIgnoreCase(label)){
64 1497 fernando
                                        previousStatus = status;
65 1498 fernando
                                        status = -1;
66 1487 fernando
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 1497 fernando
        public int getPreviousStatus(){
78
                return previousStatus;
79
        }
80
81 1487 fernando
        public int getStatus(){
82
                return status;
83
        }
84
85 1496 fernando
        public boolean checkState(char c){
86
87 1498 fernando
                if (status == -1){
88
                        return "".indexOf(c) != -1;
89
                }
90
91 1496 fernando
                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 1487 fernando
                return false;
105
        }
106 1496 fernando
107
        public String[] getCurrentTransitions(){
108
109 1498 fernando
                if (status == -1){
110
                        return new String[]{};
111
                }
112
113 1496 fernando
                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 1498 fernando
                if (status == -1){
132
                        return new String[]{};
133
                }
134
135 1496 fernando
                if (status == 0){
136 1505 fernando
                        return new String[]{null, "Cancelar"};
137 1496 fernando
                }
138
139
                if (status == 1){
140 1505 fernando
                        return new String[]{null, "Cerrar", "Cancelar"};
141 1496 fernando
                }
142
143
                if (status == 2){
144 1505 fernando
                        return new String[]{"Cancelar"};
145 1496 fernando
                }
146
147
148
                throw new RuntimeException("Bug!");
149
        }
150 1487 fernando
}