Statistics
| Revision:

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

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

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

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

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

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

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

    
71
    transient private PolygonCADTool _owner;
72

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

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

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

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

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

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

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

    
107
        protected void Default(PolygonCADToolContext 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 PolygonCADToolState
156
    {
157
    //-----------------------------------------------------------
158
    // Member methods.
159
    //
160

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

    
166
    //-----------------------------------------------------------
167
    // Inner classse.
168
    //
169

    
170

    
171
        private static final class ExecuteMap_Initial
172
            extends ExecuteMap_Default
173
        {
174
        //-------------------------------------------------------
175
        // Member methods.
176
        //
177

    
178
            private ExecuteMap_Initial(String name, int id)
179
            {
180
                super (name, id);
181
            }
182

    
183
            protected void Entry(PolygonCADToolContext context)
184
            {
185
                PolygonCADTool ctxt = context.getOwner();
186

    
187
                ctxt.init();
188
                ctxt.setQuestion("POLIGONO" + "\n" +
189
                "Insertar numero de lados<5>");
190
                return;
191
            }
192

    
193
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY)
194
            {
195
                PolygonCADTool ctxt = context.getOwner();
196

    
197

    
198
                (context.getState()).Exit(context);
199
                context.clearState();
200
                try
201
                {
202
                    ctxt.setQuestion("Inscrito en el c?rculo[I] o Circunscrito[C]");
203
                    ctxt.addPoint(pointX, pointY);
204
                }
205
                finally
206
                {
207
                    context.setState(ExecuteMap.Second);
208
                    (context.getState()).Entry(context);
209
                }
210
                return;
211
            }
212

    
213
            protected void addValue(PolygonCADToolContext context, double d)
214
            {
215
                PolygonCADTool ctxt = context.getOwner();
216

    
217

    
218
                (context.getState()).Exit(context);
219
                context.clearState();
220
                try
221
                {
222
                    ctxt.setQuestion("Insertar punto central del poligono");
223
                    ctxt.addValue(d);
224
                }
225
                finally
226
                {
227
                    context.setState(ExecuteMap.First);
228
                    (context.getState()).Entry(context);
229
                }
230
                return;
231
            }
232

    
233
        //-------------------------------------------------------
234
        // Member data.
235
        //
236
        }
237

    
238
        private static final class ExecuteMap_First
239
            extends ExecuteMap_Default
240
        {
241
        //-------------------------------------------------------
242
        // Member methods.
243
        //
244

    
245
            private ExecuteMap_First(String name, int id)
246
            {
247
                super (name, id);
248
            }
249

    
250
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY)
251
            {
252
                PolygonCADTool ctxt = context.getOwner();
253

    
254

    
255
                (context.getState()).Exit(context);
256
                context.clearState();
257
                try
258
                {
259
                    ctxt.setQuestion("Inscrito en el c?rculo[I] o Circunscrito[C]<C>");
260
                    ctxt.addPoint(pointX, pointY);
261
                }
262
                finally
263
                {
264
                    context.setState(ExecuteMap.Second);
265
                    (context.getState()).Entry(context);
266
                }
267
                return;
268
            }
269

    
270
        //-------------------------------------------------------
271
        // Member data.
272
        //
273
        }
274

    
275
        private static final class ExecuteMap_Second
276
            extends ExecuteMap_Default
277
        {
278
        //-------------------------------------------------------
279
        // Member methods.
280
        //
281

    
282
            private ExecuteMap_Second(String name, int id)
283
            {
284
                super (name, id);
285
            }
286

    
287
            protected void addOption(PolygonCADToolContext context, String s)
288
            {
289
                PolygonCADTool ctxt = context.getOwner();
290

    
291

    
292
                (context.getState()).Exit(context);
293
                context.clearState();
294
                try
295
                {
296
                    ctxt.setQuestion("Precise r?dio(r)");
297
                    ctxt.addOption(s);
298
                }
299
                finally
300
                {
301
                    context.setState(ExecuteMap.Third);
302
                    (context.getState()).Entry(context);
303
                }
304
                return;
305
            }
306

    
307
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY)
308
            {
309
                PolygonCADTool ctxt = context.getOwner();
310

    
311

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

    
327
            protected void addValue(PolygonCADToolContext context, double d)
328
            {
329
                PolygonCADTool ctxt = context.getOwner();
330

    
331

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

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

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

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

    
364
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY)
365
            {
366
                PolygonCADTool ctxt = context.getOwner();
367

    
368

    
369
                (context.getState()).Exit(context);
370
                context.clearState();
371
                try
372
                {
373
                    ctxt.addPoint(pointX, pointY);
374
                    ctxt.end();
375
                }
376
                finally
377
                {
378
                    context.setState(ExecuteMap.Fourth);
379
                    (context.getState()).Entry(context);
380
                }
381
                return;
382
            }
383

    
384
            protected void addValue(PolygonCADToolContext context, double d)
385
            {
386
                PolygonCADTool ctxt = context.getOwner();
387

    
388

    
389
                (context.getState()).Exit(context);
390
                context.clearState();
391
                try
392
                {
393
                    ctxt.addValue(d);
394
                    ctxt.end();
395
                }
396
                finally
397
                {
398
                    context.setState(ExecuteMap.Fourth);
399
                    (context.getState()).Entry(context);
400
                }
401
                return;
402
            }
403

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

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

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

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

    
426
    //-----------------------------------------------------------
427
    // Member data.
428
    //
429
    }
430
}