Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / LineCADToolContext.java @ 3716

History | View | Annotate | Download (7.19 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

    
6
package com.iver.cit.gvsig.gui.cad.tools.smc;
7

    
8

    
9
import com.iver.cit.gvsig.gui.cad.tools.LineCADTool; public final class LineCADToolContext
10
    extends statemap.FSMContext
11
{
12
//---------------------------------------------------------------
13
// Member methods.
14
//
15

    
16
    public LineCADToolContext(LineCADTool owner)
17
    {
18
        super();
19

    
20
        _owner = owner;
21
        setState(ExecuteMap.Initial);
22
        ExecuteMap.Initial.Entry(this);
23
    }
24

    
25
    public void addpoint(java.util.BitSet sel, double pointX, double pointY)
26
    {
27
        _transition = "addpoint";
28
        getState().addpoint(this, sel, pointX, pointY);
29
        _transition = "";
30
        return;
31
    }
32

    
33
    public LineCADToolState getState()
34
        throws statemap.StateUndefinedException
35
    {
36
        if (_state == null)
37
        {
38
            throw(
39
                new statemap.StateUndefinedException());
40
        }
41

    
42
        return ((LineCADToolState) _state);
43
    }
44

    
45
    protected LineCADTool getOwner()
46
    {
47
        return (_owner);
48
    }
49

    
50
//---------------------------------------------------------------
51
// Member data.
52
//
53

    
54
    transient private LineCADTool _owner;
55

    
56
//---------------------------------------------------------------
57
// Inner classes.
58
//
59

    
60
    public static abstract class LineCADToolState
61
        extends statemap.State
62
    {
63
    //-----------------------------------------------------------
64
    // Member methods.
65
    //
66

    
67
        protected LineCADToolState(String name, int id)
68
        {
69
            super (name, id);
70
        }
71

    
72
        protected void Entry(LineCADToolContext context) {}
73
        protected void Exit(LineCADToolContext context) {}
74

    
75
        protected void addpoint(LineCADToolContext context, java.util.BitSet sel, double pointX, double pointY)
76
        {
77
            Default(context);
78
        }
79

    
80
        protected void Default(LineCADToolContext context)
81
        {
82
            throw (
83
                new statemap.TransitionUndefinedException(
84
                    "State: " +
85
                    context.getState().getName() +
86
                    ", Transition: " +
87
                    context.getTransition()));
88
        }
89

    
90
    //-----------------------------------------------------------
91
    // Member data.
92
    //
93
    }
94

    
95
    /* package */ static abstract class ExecuteMap
96
    {
97
    //-----------------------------------------------------------
98
    // Member methods.
99
    //
100

    
101
    //-----------------------------------------------------------
102
    // Member data.
103
    //
104

    
105
        //-------------------------------------------------------
106
        // Statics.
107
        //
108
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
109
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
110
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
111
        private static ExecuteMap_Default Default;
112

    
113
        static
114
        {
115
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
116
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
117
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
118
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
119
        }
120

    
121
    }
122

    
123
    protected static class ExecuteMap_Default
124
        extends LineCADToolState
125
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129

    
130
        protected ExecuteMap_Default(String name, int id)
131
        {
132
            super (name, id);
133
        }
134

    
135
    //-----------------------------------------------------------
136
    // Inner classse.
137
    //
138

    
139

    
140
        private static final class ExecuteMap_Initial
141
            extends ExecuteMap_Default
142
        {
143
        //-------------------------------------------------------
144
        // Member methods.
145
        //
146

    
147
            private ExecuteMap_Initial(String name, int id)
148
            {
149
                super (name, id);
150
            }
151

    
152
            protected void Entry(LineCADToolContext context)
153
            {
154
                LineCADTool ctxt = context.getOwner();
155

    
156
                ctxt.init();
157
                ctxt.setQuestion("Insertar primer punto");
158
                return;
159
            }
160

    
161
            protected void addpoint(LineCADToolContext context, java.util.BitSet sel, double pointX, double pointY)
162
            {
163
                LineCADTool ctxt = context.getOwner();
164

    
165

    
166
                (context.getState()).Exit(context);
167
                context.clearState();
168
                try
169
                {
170
                    ctxt.setQuestion("Insertar segundo punto");
171
                    ctxt.addpoint(sel, pointX, pointY);
172
                }
173
                finally
174
                {
175
                    context.setState(ExecuteMap.Second);
176
                    (context.getState()).Entry(context);
177
                }
178
                return;
179
            }
180

    
181
        //-------------------------------------------------------
182
        // Member data.
183
        //
184
        }
185

    
186
        private static final class ExecuteMap_First
187
            extends ExecuteMap_Default
188
        {
189
        //-------------------------------------------------------
190
        // Member methods.
191
        //
192

    
193
            private ExecuteMap_First(String name, int id)
194
            {
195
                super (name, id);
196
            }
197

    
198
            protected void addpoint(LineCADToolContext context, java.util.BitSet sel, double pointX, double pointY)
199
            {
200
                LineCADTool ctxt = context.getOwner();
201

    
202

    
203
                (context.getState()).Exit(context);
204
                context.clearState();
205
                try
206
                {
207
                    ctxt.setQuestion("Insertar segundo punto");
208
                    ctxt.addpoint(sel, pointX, pointY);
209
                }
210
                finally
211
                {
212
                    context.setState(ExecuteMap.Second);
213
                    (context.getState()).Entry(context);
214
                }
215
                return;
216
            }
217

    
218
        //-------------------------------------------------------
219
        // Member data.
220
        //
221
        }
222

    
223
        private static final class ExecuteMap_Second
224
            extends ExecuteMap_Default
225
        {
226
        //-------------------------------------------------------
227
        // Member methods.
228
        //
229

    
230
            private ExecuteMap_Second(String name, int id)
231
            {
232
                super (name, id);
233
            }
234

    
235
            protected void addpoint(LineCADToolContext context, java.util.BitSet sel, double pointX, double pointY)
236
            {
237
                LineCADTool ctxt = context.getOwner();
238

    
239

    
240
                (context.getState()).Exit(context);
241
                context.clearState();
242
                try
243
                {
244
                    ctxt.setQuestion("Insertar primer punto");
245
                    ctxt.addpoint(sel, pointX, pointY);
246
                    ctxt.refresh();
247
                }
248
                finally
249
                {
250
                    context.setState(ExecuteMap.First);
251
                    (context.getState()).Entry(context);
252
                }
253
                return;
254
            }
255

    
256
        //-------------------------------------------------------
257
        // Member data.
258
        //
259
        }
260

    
261
    //-----------------------------------------------------------
262
    // Member data.
263
    //
264
    }
265
}