Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / EllipseCADToolContext.java @ 3832

History | View | Annotate | Download (9.12 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.EllipseCADTool;
9

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

    
17
    public EllipseCADToolContext(EllipseCADTool 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 EllipseCADToolState getState()
43
        throws statemap.StateUndefinedException
44
    {
45
        if (_state == null)
46
        {
47
            throw(
48
                new statemap.StateUndefinedException());
49
        }
50

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

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

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

    
63
    transient private EllipseCADTool _owner;
64

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

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

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

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

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

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

    
94
        protected void Default(EllipseCADToolContext 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
        /* package */ static ExecuteMap_Default.ExecuteMap_Third Third;
126
        /* package */ static ExecuteMap_Default.ExecuteMap_Fourth Fourth;
127
        private static ExecuteMap_Default Default;
128

    
129
        static
130
        {
131
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
132
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
133
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
134
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
135
            Fourth = new ExecuteMap_Default.ExecuteMap_Fourth("ExecuteMap.Fourth", 4);
136
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
137
        }
138

    
139
    }
140

    
141
    protected static class ExecuteMap_Default
142
        extends EllipseCADToolState
143
    {
144
    //-----------------------------------------------------------
145
    // Member methods.
146
    //
147

    
148
        protected ExecuteMap_Default(String name, int id)
149
        {
150
            super (name, id);
151
        }
152

    
153
    //-----------------------------------------------------------
154
    // Inner classse.
155
    //
156

    
157

    
158
        private static final class ExecuteMap_Initial
159
            extends ExecuteMap_Default
160
        {
161
        //-------------------------------------------------------
162
        // Member methods.
163
        //
164

    
165
            private ExecuteMap_Initial(String name, int id)
166
            {
167
                super (name, id);
168
            }
169

    
170
            protected void Entry(EllipseCADToolContext context)
171
            {
172
                EllipseCADTool ctxt = context.getOwner();
173

    
174
                ctxt.init();
175
                ctxt.setQuestion("Insertar punto inicial de eje de elipse");
176
                return;
177
            }
178

    
179
            protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
180
            {
181
                EllipseCADTool ctxt = context.getOwner();
182

    
183

    
184
                (context.getState()).Exit(context);
185
                context.clearState();
186
                try
187
                {
188
                    ctxt.setQuestion("Insertar punto final de eje de elipse");
189
                    ctxt.addPoint(pointX, pointY);
190
                }
191
                finally
192
                {
193
                    context.setState(ExecuteMap.First);
194
                    (context.getState()).Entry(context);
195
                }
196
                return;
197
            }
198

    
199
        //-------------------------------------------------------
200
        // Member data.
201
        //
202
        }
203

    
204
        private static final class ExecuteMap_First
205
            extends ExecuteMap_Default
206
        {
207
        //-------------------------------------------------------
208
        // Member methods.
209
        //
210

    
211
            private ExecuteMap_First(String name, int id)
212
            {
213
                super (name, id);
214
            }
215

    
216
            protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
217
            {
218
                EllipseCADTool ctxt = context.getOwner();
219

    
220

    
221
                (context.getState()).Exit(context);
222
                context.clearState();
223
                try
224
                {
225
                    ctxt.setQuestion("Insertar distancia al otro eje");
226
                    ctxt.addPoint(pointX, pointY);
227
                }
228
                finally
229
                {
230
                    context.setState(ExecuteMap.Second);
231
                    (context.getState()).Entry(context);
232
                }
233
                return;
234
            }
235

    
236
        //-------------------------------------------------------
237
        // Member data.
238
        //
239
        }
240

    
241
        private static final class ExecuteMap_Second
242
            extends ExecuteMap_Default
243
        {
244
        //-------------------------------------------------------
245
        // Member methods.
246
        //
247

    
248
            private ExecuteMap_Second(String name, int id)
249
            {
250
                super (name, id);
251
            }
252

    
253
            protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
254
            {
255
                EllipseCADTool ctxt = context.getOwner();
256

    
257

    
258
                (context.getState()).Exit(context);
259
                context.clearState();
260
                try
261
                {
262
                    ctxt.addPoint(pointX, pointY);
263
                    ctxt.end();
264
                }
265
                finally
266
                {
267
                    context.setState(ExecuteMap.Third);
268
                    (context.getState()).Entry(context);
269
                }
270
                return;
271
            }
272

    
273
            protected void addValue(EllipseCADToolContext context, double d)
274
            {
275
                EllipseCADTool ctxt = context.getOwner();
276

    
277

    
278
                (context.getState()).Exit(context);
279
                context.clearState();
280
                try
281
                {
282
                    ctxt.addValue(d);
283
                    ctxt.end();
284
                }
285
                finally
286
                {
287
                    context.setState(ExecuteMap.Fourth);
288
                    (context.getState()).Entry(context);
289
                }
290
                return;
291
            }
292

    
293
        //-------------------------------------------------------
294
        // Member data.
295
        //
296
        }
297

    
298
        private static final class ExecuteMap_Third
299
            extends ExecuteMap_Default
300
        {
301
        //-------------------------------------------------------
302
        // Member methods.
303
        //
304

    
305
            private ExecuteMap_Third(String name, int id)
306
            {
307
                super (name, id);
308
            }
309

    
310
        //-------------------------------------------------------
311
        // Member data.
312
        //
313
        }
314

    
315
        private static final class ExecuteMap_Fourth
316
            extends ExecuteMap_Default
317
        {
318
        //-------------------------------------------------------
319
        // Member methods.
320
        //
321

    
322
            private ExecuteMap_Fourth(String name, int id)
323
            {
324
                super (name, id);
325
            }
326

    
327
        //-------------------------------------------------------
328
        // Member data.
329
        //
330
        }
331

    
332
    //-----------------------------------------------------------
333
    // Member data.
334
    //
335
    }
336
}