Statistics
| Revision:

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

History | View | Annotate | Download (12.9 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("Insertar punto central o [3P]:");
195
                return;
196
            }
197

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

    
202

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

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

    
222

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

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

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

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

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

    
259

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

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

    
279

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

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

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

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

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

    
316

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

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

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

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

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

    
353

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
441

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

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

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