Statistics
| Revision:

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

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

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

    
17
    public CircleCADToolContext(CircleCADTool 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 CircleCADToolState getState()
51
        throws statemap.StateUndefinedException
52
    {
53
        if (_state == null)
54
        {
55
            throw(
56
                new statemap.StateUndefinedException());
57
        }
58

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

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

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

    
71
    transient private CircleCADTool _owner;
72

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

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

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

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

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

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

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

    
107
        protected void Default(CircleCADToolContext 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
        /* package */ static ExecuteMap_Default.ExecuteMap_Fiveth Fiveth;
141
        /* package */ static ExecuteMap_Default.ExecuteMap_Sixth Sixth;
142
        /* package */ static ExecuteMap_Default.ExecuteMap_Seventh Seventh;
143
        private static ExecuteMap_Default Default;
144

    
145
        static
146
        {
147
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
148
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
149
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
150
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
151
            Fourth = new ExecuteMap_Default.ExecuteMap_Fourth("ExecuteMap.Fourth", 4);
152
            Fiveth = new ExecuteMap_Default.ExecuteMap_Fiveth("ExecuteMap.Fiveth", 5);
153
            Sixth = new ExecuteMap_Default.ExecuteMap_Sixth("ExecuteMap.Sixth", 6);
154
            Seventh = new ExecuteMap_Default.ExecuteMap_Seventh("ExecuteMap.Seventh", 7);
155
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
156
        }
157

    
158
    }
159

    
160
    protected static class ExecuteMap_Default
161
        extends CircleCADToolState
162
    {
163
    //-----------------------------------------------------------
164
    // Member methods.
165
    //
166

    
167
        protected ExecuteMap_Default(String name, int id)
168
        {
169
            super (name, id);
170
        }
171

    
172
    //-----------------------------------------------------------
173
    // Inner classse.
174
    //
175

    
176

    
177
        private static final class ExecuteMap_Initial
178
            extends ExecuteMap_Default
179
        {
180
        //-------------------------------------------------------
181
        // Member methods.
182
        //
183

    
184
            private ExecuteMap_Initial(String name, int id)
185
            {
186
                super (name, id);
187
            }
188

    
189
            protected void Entry(CircleCADToolContext context)
190
            {
191
                CircleCADTool ctxt = context.getOwner();
192

    
193
                ctxt.init();
194
                ctxt.setQuestion("CIRCULO" + "\n" +
195
                "Insertar punto central o [3P]:");
196
                return;
197
            }
198

    
199
            protected void addOption(CircleCADToolContext context, String s)
200
            {
201
                CircleCADTool ctxt = context.getOwner();
202

    
203

    
204
                (context.getState()).Exit(context);
205
                context.clearState();
206
                try
207
                {
208
                    ctxt.setQuestion("Insertar primer punto");
209
                    ctxt.addOption(s);
210
                }
211
                finally
212
                {
213
                    context.setState(ExecuteMap.Seventh);
214
                    (context.getState()).Entry(context);
215
                }
216
                return;
217
            }
218

    
219
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY)
220
            {
221
                CircleCADTool ctxt = context.getOwner();
222

    
223

    
224
                (context.getState()).Exit(context);
225
                context.clearState();
226
                try
227
                {
228
                    ctxt.setQuestion("Insertar radio o segundo punto");
229
                    ctxt.addPoint(pointX, pointY);
230
                }
231
                finally
232
                {
233
                    context.setState(ExecuteMap.First);
234
                    (context.getState()).Entry(context);
235
                }
236
                return;
237
            }
238

    
239
        //-------------------------------------------------------
240
        // Member data.
241
        //
242
        }
243

    
244
        private static final class ExecuteMap_First
245
            extends ExecuteMap_Default
246
        {
247
        //-------------------------------------------------------
248
        // Member methods.
249
        //
250

    
251
            private ExecuteMap_First(String name, int id)
252
            {
253
                super (name, id);
254
            }
255

    
256
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY)
257
            {
258
                CircleCADTool ctxt = context.getOwner();
259

    
260

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

    
276
            protected void addValue(CircleCADToolContext context, double d)
277
            {
278
                CircleCADTool ctxt = context.getOwner();
279

    
280

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

    
296
        //-------------------------------------------------------
297
        // Member data.
298
        //
299
        }
300

    
301
        private static final class ExecuteMap_Second
302
            extends ExecuteMap_Default
303
        {
304
        //-------------------------------------------------------
305
        // Member methods.
306
        //
307

    
308
            private ExecuteMap_Second(String name, int id)
309
            {
310
                super (name, id);
311
            }
312

    
313
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY)
314
            {
315
                CircleCADTool ctxt = context.getOwner();
316

    
317

    
318
                (context.getState()).Exit(context);
319
                context.clearState();
320
                try
321
                {
322
                    ctxt.setQuestion("Insertar tercer punto");
323
                    ctxt.addPoint(pointX, pointY);
324
                }
325
                finally
326
                {
327
                    context.setState(ExecuteMap.Third);
328
                    (context.getState()).Entry(context);
329
                }
330
                return;
331
            }
332

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

    
338
        private static final class ExecuteMap_Third
339
            extends ExecuteMap_Default
340
        {
341
        //-------------------------------------------------------
342
        // Member methods.
343
        //
344

    
345
            private ExecuteMap_Third(String name, int id)
346
            {
347
                super (name, id);
348
            }
349

    
350
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY)
351
            {
352
                CircleCADTool ctxt = context.getOwner();
353

    
354

    
355
                (context.getState()).Exit(context);
356
                context.clearState();
357
                try
358
                {
359
                    ctxt.addPoint(pointX, pointY);
360
                    ctxt.end();
361
                }
362
                finally
363
                {
364
                    context.setState(ExecuteMap.Fourth);
365
                    (context.getState()).Entry(context);
366
                }
367
                return;
368
            }
369

    
370
        //-------------------------------------------------------
371
        // Member data.
372
        //
373
        }
374

    
375
        private static final class ExecuteMap_Fourth
376
            extends ExecuteMap_Default
377
        {
378
        //-------------------------------------------------------
379
        // Member methods.
380
        //
381

    
382
            private ExecuteMap_Fourth(String name, int id)
383
            {
384
                super (name, id);
385
            }
386

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

    
392
        private static final class ExecuteMap_Fiveth
393
            extends ExecuteMap_Default
394
        {
395
        //-------------------------------------------------------
396
        // Member methods.
397
        //
398

    
399
            private ExecuteMap_Fiveth(String name, int id)
400
            {
401
                super (name, id);
402
            }
403

    
404
        //-------------------------------------------------------
405
        // Member data.
406
        //
407
        }
408

    
409
        private static final class ExecuteMap_Sixth
410
            extends ExecuteMap_Default
411
        {
412
        //-------------------------------------------------------
413
        // Member methods.
414
        //
415

    
416
            private ExecuteMap_Sixth(String name, int id)
417
            {
418
                super (name, id);
419
            }
420

    
421
        //-------------------------------------------------------
422
        // Member data.
423
        //
424
        }
425

    
426
        private static final class ExecuteMap_Seventh
427
            extends ExecuteMap_Default
428
        {
429
        //-------------------------------------------------------
430
        // Member methods.
431
        //
432

    
433
            private ExecuteMap_Seventh(String name, int id)
434
            {
435
                super (name, id);
436
            }
437

    
438
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY)
439
            {
440
                CircleCADTool ctxt = context.getOwner();
441

    
442

    
443
                (context.getState()).Exit(context);
444
                context.clearState();
445
                try
446
                {
447
                    ctxt.setQuestion("Insertar segundo punto");
448
                    ctxt.addPoint(pointX, pointY);
449
                }
450
                finally
451
                {
452
                    context.setState(ExecuteMap.Second);
453
                    (context.getState()).Entry(context);
454
                }
455
                return;
456
            }
457

    
458
        //-------------------------------------------------------
459
        // Member data.
460
        //
461
        }
462

    
463
    //-----------------------------------------------------------
464
    // Member data.
465
    //
466
    }
467
}