Statistics
| Revision:

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

History | View | Annotate | Download (8.68 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

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

    
8
import com.iver.cit.gvsig.gui.cad.tools.LineCADTool;
9

    
10
public final class LineCADToolContext
11
    extends statemap.FSMContext
12
{
13
//---------------------------------------------------------------
14
// Member methods.
15
//
16

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

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

    
26
    public void addPoint(double pointX, double pointY)
27
    {
28
        _transition = "addPoint";
29
        getState().addPoint(this, pointX, pointY);
30
        _transition = "";
31
        return;
32
    }
33

    
34
    public void addValue(double d)
35
    {
36
        _transition = "addValue";
37
        getState().addValue(this, d);
38
        _transition = "";
39
        return;
40
    }
41

    
42
    public LineCADToolState getState()
43
        throws statemap.StateUndefinedException
44
    {
45
        if (_state == null)
46
        {
47
            throw(
48
                new statemap.StateUndefinedException());
49
        }
50

    
51
        return ((LineCADToolState) _state);
52
    }
53

    
54
    protected LineCADTool getOwner()
55
    {
56
        return (_owner);
57
    }
58

    
59
//---------------------------------------------------------------
60
// Member data.
61
//
62

    
63
    transient private LineCADTool _owner;
64

    
65
//---------------------------------------------------------------
66
// Inner classes.
67
//
68

    
69
    public static abstract class LineCADToolState
70
        extends statemap.State
71
    {
72
    //-----------------------------------------------------------
73
    // Member methods.
74
    //
75

    
76
        protected LineCADToolState(String name, int id)
77
        {
78
            super (name, id);
79
        }
80

    
81
        protected void Entry(LineCADToolContext context) {}
82
        protected void Exit(LineCADToolContext context) {}
83

    
84
        protected void addPoint(LineCADToolContext context, double pointX, double pointY)
85
        {
86
            Default(context);
87
        }
88

    
89
        protected void addValue(LineCADToolContext context, double d)
90
        {
91
            Default(context);
92
        }
93

    
94
        protected void Default(LineCADToolContext context)
95
        {
96
            throw (
97
                new statemap.TransitionUndefinedException(
98
                    "State: " +
99
                    context.getState().getName() +
100
                    ", Transition: " +
101
                    context.getTransition()));
102
        }
103

    
104
    //-----------------------------------------------------------
105
    // Member data.
106
    //
107
    }
108

    
109
    /* package */ static abstract class ExecuteMap
110
    {
111
    //-----------------------------------------------------------
112
    // Member methods.
113
    //
114

    
115
    //-----------------------------------------------------------
116
    // Member data.
117
    //
118

    
119
        //-------------------------------------------------------
120
        // Statics.
121
        //
122
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
123
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
124
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
125
        private static ExecuteMap_Default Default;
126

    
127
        static
128
        {
129
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
130
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
131
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
132
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
133
        }
134

    
135
    }
136

    
137
    protected static class ExecuteMap_Default
138
        extends LineCADToolState
139
    {
140
    //-----------------------------------------------------------
141
    // Member methods.
142
    //
143

    
144
        protected ExecuteMap_Default(String name, int id)
145
        {
146
            super (name, id);
147
        }
148

    
149
    //-----------------------------------------------------------
150
    // Inner classse.
151
    //
152

    
153

    
154
        private static final class ExecuteMap_Initial
155
            extends ExecuteMap_Default
156
        {
157
        //-------------------------------------------------------
158
        // Member methods.
159
        //
160

    
161
            private ExecuteMap_Initial(String name, int id)
162
            {
163
                super (name, id);
164
            }
165

    
166
            protected void Entry(LineCADToolContext context)
167
            {
168
                LineCADTool ctxt = context.getOwner();
169

    
170
                ctxt.init();
171
                ctxt.setQuestion("LINEA" + "\n" +
172
                "Insertar primer punto");
173
                return;
174
            }
175

    
176
            protected void Exit(LineCADToolContext context)
177
            {
178
                LineCADTool ctxt = context.getOwner();
179

    
180
                ctxt.end();
181
                return;
182
            }
183

    
184
            protected void addPoint(LineCADToolContext context, double pointX, double pointY)
185
            {
186
                LineCADTool ctxt = context.getOwner();
187

    
188

    
189
                (context.getState()).Exit(context);
190
                context.clearState();
191
                try
192
                {
193
                    ctxt.setQuestion("Insertar segundo punto o angulo");
194
                    ctxt.addPoint(pointX, pointY);
195
                }
196
                finally
197
                {
198
                    context.setState(ExecuteMap.First);
199
                    (context.getState()).Entry(context);
200
                }
201
                return;
202
            }
203

    
204
        //-------------------------------------------------------
205
        // Member data.
206
        //
207
        }
208

    
209
        private static final class ExecuteMap_First
210
            extends ExecuteMap_Default
211
        {
212
        //-------------------------------------------------------
213
        // Member methods.
214
        //
215

    
216
            private ExecuteMap_First(String name, int id)
217
            {
218
                super (name, id);
219
            }
220

    
221
            protected void addPoint(LineCADToolContext context, double pointX, double pointY)
222
            {
223
                LineCADTool ctxt = context.getOwner();
224

    
225
                LineCADToolState endState = context.getState();
226

    
227
                context.clearState();
228
                try
229
                {
230
                    ctxt.setQuestion("Insertar segundo punto o angulo");
231
                    ctxt.addPoint(pointX, pointY);
232
                }
233
                finally
234
                {
235
                    context.setState(endState);
236
                }
237
                return;
238
            }
239

    
240
            protected void addValue(LineCADToolContext context, double d)
241
            {
242
                LineCADTool ctxt = context.getOwner();
243

    
244

    
245
                (context.getState()).Exit(context);
246
                context.clearState();
247
                try
248
                {
249
                    ctxt.setQuestion("Insertar longitud o punto");
250
                    ctxt.addValue(d);
251
                }
252
                finally
253
                {
254
                    context.setState(ExecuteMap.Second);
255
                    (context.getState()).Entry(context);
256
                }
257
                return;
258
            }
259

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

    
265
        private static final class ExecuteMap_Second
266
            extends ExecuteMap_Default
267
        {
268
        //-------------------------------------------------------
269
        // Member methods.
270
        //
271

    
272
            private ExecuteMap_Second(String name, int id)
273
            {
274
                super (name, id);
275
            }
276

    
277
            protected void addPoint(LineCADToolContext context, double pointX, double pointY)
278
            {
279
                LineCADTool ctxt = context.getOwner();
280

    
281

    
282
                (context.getState()).Exit(context);
283
                context.clearState();
284
                try
285
                {
286
                    ctxt.setQuestion("Insertar segundo punto o angulo");
287
                    ctxt.addPoint(pointX, pointY);
288
                }
289
                finally
290
                {
291
                    context.setState(ExecuteMap.First);
292
                    (context.getState()).Entry(context);
293
                }
294
                return;
295
            }
296

    
297
            protected void addValue(LineCADToolContext context, double d)
298
            {
299
                LineCADTool ctxt = context.getOwner();
300

    
301

    
302
                (context.getState()).Exit(context);
303
                context.clearState();
304
                try
305
                {
306
                    ctxt.setQuestion("Insertar segundo punto o angulo");
307
                    ctxt.addValue(d);
308
                }
309
                finally
310
                {
311
                    context.setState(ExecuteMap.First);
312
                    (context.getState()).Entry(context);
313
                }
314
                return;
315
            }
316

    
317
        //-------------------------------------------------------
318
        // Member data.
319
        //
320
        }
321

    
322
    //-----------------------------------------------------------
323
    // Member data.
324
    //
325
    }
326
}