Statistics
| Revision:

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

History | View | Annotate | Download (8.66 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("Insertar primer punto");
172
                return;
173
            }
174

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

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

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

    
187

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

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

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

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

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

    
224
                LineCADToolState endState = context.getState();
225

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

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

    
243

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

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

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

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

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

    
280

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

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

    
300

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

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

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