Statistics
| Revision:

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

History | View | Annotate | Download (10.6 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 addOption(String s)
27
    {
28
        _transition = "addOption";
29
        getState().addOption(this, s);
30
        _transition = "";
31
        return;
32
    }
33

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

    
42
    public void addValue(double d)
43
    {
44
        _transition = "addValue";
45
        getState().addValue(this, d);
46
        _transition = "";
47
        return;
48
    }
49

    
50
    public EllipseCADToolState getState()
51
        throws statemap.StateUndefinedException
52
    {
53
        if (_state == null)
54
        {
55
            throw(
56
                new statemap.StateUndefinedException());
57
        }
58

    
59
        return ((EllipseCADToolState) _state);
60
    }
61

    
62
    protected EllipseCADTool getOwner()
63
    {
64
        return (_owner);
65
    }
66

    
67
//---------------------------------------------------------------
68
// Member data.
69
//
70

    
71
    transient private EllipseCADTool _owner;
72

    
73
//---------------------------------------------------------------
74
// Inner classes.
75
//
76

    
77
    public static abstract class EllipseCADToolState
78
        extends statemap.State
79
    {
80
    //-----------------------------------------------------------
81
    // Member methods.
82
    //
83

    
84
        protected EllipseCADToolState(String name, int id)
85
        {
86
            super (name, id);
87
        }
88

    
89
        protected void Entry(EllipseCADToolContext context) {}
90
        protected void Exit(EllipseCADToolContext context) {}
91

    
92
        protected void addOption(EllipseCADToolContext context, String s)
93
        {
94
            Default(context);
95
        }
96

    
97
        protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
98
        {
99
            Default(context);
100
        }
101

    
102
        protected void addValue(EllipseCADToolContext context, double d)
103
        {
104
            Default(context);
105
        }
106

    
107
        protected void Default(EllipseCADToolContext context)
108
        {
109
            throw (
110
                new statemap.TransitionUndefinedException(
111
                    "State: " +
112
                    context.getState().getName() +
113
                    ", Transition: " +
114
                    context.getTransition()));
115
        }
116

    
117
    //-----------------------------------------------------------
118
    // Member data.
119
    //
120
    }
121

    
122
    /* package */ static abstract class ExecuteMap
123
    {
124
    //-----------------------------------------------------------
125
    // Member methods.
126
    //
127

    
128
    //-----------------------------------------------------------
129
    // Member data.
130
    //
131

    
132
        //-------------------------------------------------------
133
        // Statics.
134
        //
135
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
136
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
137
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
138
        /* package */ static ExecuteMap_Default.ExecuteMap_Third Third;
139
        /* package */ static ExecuteMap_Default.ExecuteMap_Fourth Fourth;
140
        private static ExecuteMap_Default Default;
141

    
142
        static
143
        {
144
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
145
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
146
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
147
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
148
            Fourth = new ExecuteMap_Default.ExecuteMap_Fourth("ExecuteMap.Fourth", 4);
149
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
150
        }
151

    
152
    }
153

    
154
    protected static class ExecuteMap_Default
155
        extends EllipseCADToolState
156
    {
157
    //-----------------------------------------------------------
158
    // Member methods.
159
    //
160

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

    
166
        protected void addOption(EllipseCADToolContext context, String s)
167
        {
168
            EllipseCADTool ctxt = context.getOwner();
169

    
170
            if (s.equals("Cancelar"))
171
            {
172
                boolean loopbackFlag =
173
                    context.getState().getName().equals(
174
                        ExecuteMap.Initial.getName());
175

    
176
                if (loopbackFlag == false)
177
                {
178
                    (context.getState()).Exit(context);
179
                }
180

    
181
                context.clearState();
182
                try
183
                {
184
                    ctxt.end();
185
                }
186
                finally
187
                {
188
                    context.setState(ExecuteMap.Initial);
189

    
190
                    if (loopbackFlag == false)
191
                    {
192
                        (context.getState()).Entry(context);
193
                    }
194

    
195
                }
196
            }
197
            else
198
            {
199
                super.addOption(context, s);
200
            }
201

    
202
            return;
203
        }
204

    
205
    //-----------------------------------------------------------
206
    // Inner classse.
207
    //
208

    
209

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

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

    
222
            protected void Entry(EllipseCADToolContext context)
223
            {
224
                EllipseCADTool ctxt = context.getOwner();
225

    
226
                ctxt.setQuestion("ELIPSE" + "\n" +
227
                "Insertar punto inicial de eje de elipse");
228
                ctxt.setDescription(new String[]{"Cancelar"});
229
                return;
230
            }
231

    
232
            protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
233
            {
234
                EllipseCADTool ctxt = context.getOwner();
235

    
236

    
237
                (context.getState()).Exit(context);
238
                context.clearState();
239
                try
240
                {
241
                    ctxt.setQuestion("Insertar punto final de eje de elipse");
242
                    ctxt.setDescription(new String[]{"Cancelar"});
243
                    ctxt.addPoint(pointX, pointY);
244
                }
245
                finally
246
                {
247
                    context.setState(ExecuteMap.First);
248
                    (context.getState()).Entry(context);
249
                }
250
                return;
251
            }
252

    
253
        //-------------------------------------------------------
254
        // Member data.
255
        //
256
        }
257

    
258
        private static final class ExecuteMap_First
259
            extends ExecuteMap_Default
260
        {
261
        //-------------------------------------------------------
262
        // Member methods.
263
        //
264

    
265
            private ExecuteMap_First(String name, int id)
266
            {
267
                super (name, id);
268
            }
269

    
270
            protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
271
            {
272
                EllipseCADTool ctxt = context.getOwner();
273

    
274

    
275
                (context.getState()).Exit(context);
276
                context.clearState();
277
                try
278
                {
279
                    ctxt.setQuestion("Insertar distancia al otro eje");
280
                    ctxt.setDescription(new String[]{"Cancelar"});
281
                    ctxt.addPoint(pointX, pointY);
282
                }
283
                finally
284
                {
285
                    context.setState(ExecuteMap.Second);
286
                    (context.getState()).Entry(context);
287
                }
288
                return;
289
            }
290

    
291
        //-------------------------------------------------------
292
        // Member data.
293
        //
294
        }
295

    
296
        private static final class ExecuteMap_Second
297
            extends ExecuteMap_Default
298
        {
299
        //-------------------------------------------------------
300
        // Member methods.
301
        //
302

    
303
            private ExecuteMap_Second(String name, int id)
304
            {
305
                super (name, id);
306
            }
307

    
308
            protected void addPoint(EllipseCADToolContext context, double pointX, double pointY)
309
            {
310
                EllipseCADTool ctxt = context.getOwner();
311

    
312

    
313
                (context.getState()).Exit(context);
314
                context.clearState();
315
                try
316
                {
317
                    ctxt.addPoint(pointX, pointY);
318
                    ctxt.end();
319
                }
320
                finally
321
                {
322
                    context.setState(ExecuteMap.Third);
323
                    (context.getState()).Entry(context);
324
                }
325
                return;
326
            }
327

    
328
            protected void addValue(EllipseCADToolContext context, double d)
329
            {
330
                EllipseCADTool ctxt = context.getOwner();
331

    
332

    
333
                (context.getState()).Exit(context);
334
                context.clearState();
335
                try
336
                {
337
                    ctxt.addValue(d);
338
                    ctxt.end();
339
                }
340
                finally
341
                {
342
                    context.setState(ExecuteMap.Fourth);
343
                    (context.getState()).Entry(context);
344
                }
345
                return;
346
            }
347

    
348
        //-------------------------------------------------------
349
        // Member data.
350
        //
351
        }
352

    
353
        private static final class ExecuteMap_Third
354
            extends ExecuteMap_Default
355
        {
356
        //-------------------------------------------------------
357
        // Member methods.
358
        //
359

    
360
            private ExecuteMap_Third(String name, int id)
361
            {
362
                super (name, id);
363
            }
364

    
365
        //-------------------------------------------------------
366
        // Member data.
367
        //
368
        }
369

    
370
        private static final class ExecuteMap_Fourth
371
            extends ExecuteMap_Default
372
        {
373
        //-------------------------------------------------------
374
        // Member methods.
375
        //
376

    
377
            private ExecuteMap_Fourth(String name, int id)
378
            {
379
                super (name, id);
380
            }
381

    
382
        //-------------------------------------------------------
383
        // Member data.
384
        //
385
        }
386

    
387
    //-----------------------------------------------------------
388
    // Member data.
389
    //
390
    }
391
}