Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / RectangleCADToolContext.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.RectangleCADTool;
9

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

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

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

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

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

    
63
    transient private RectangleCADTool _owner;
64

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

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

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

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

    
84
        protected void addOption(RectangleCADToolContext context, String s)
85
        {
86
            Default(context);
87
        }
88

    
89
        protected void addPoint(RectangleCADToolContext context, double pointX, double pointY)
90
        {
91
            Default(context);
92
        }
93

    
94
        protected void Default(RectangleCADToolContext 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 RectangleCADToolState
143
    {
144
    //-----------------------------------------------------------
145
    // Member methods.
146
    //
147

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

    
153
        protected void addOption(RectangleCADToolContext context, String s)
154
        {
155
            RectangleCADTool ctxt = context.getOwner();
156

    
157
            if (s.equals("Cancelar"))
158
            {
159
                boolean loopbackFlag =
160
                    context.getState().getName().equals(
161
                        ExecuteMap.Initial.getName());
162

    
163
                if (loopbackFlag == false)
164
                {
165
                    (context.getState()).Exit(context);
166
                }
167

    
168
                context.clearState();
169
                try
170
                {
171
                    ctxt.end();
172
                }
173
                finally
174
                {
175
                    context.setState(ExecuteMap.Initial);
176

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

    
182
                }
183
            }
184
            else
185
            {
186
                super.addOption(context, s);
187
            }
188

    
189
            return;
190
        }
191

    
192
    //-----------------------------------------------------------
193
    // Inner classse.
194
    //
195

    
196

    
197
        private static final class ExecuteMap_Initial
198
            extends ExecuteMap_Default
199
        {
200
        //-------------------------------------------------------
201
        // Member methods.
202
        //
203

    
204
            private ExecuteMap_Initial(String name, int id)
205
            {
206
                super (name, id);
207
            }
208

    
209
            protected void Entry(RectangleCADToolContext context)
210
            {
211
                RectangleCADTool ctxt = context.getOwner();
212

    
213
                ctxt.setQuestion("RECTANGULO" + "\n" +
214
                "Insertar primer punto de esquina");
215
                ctxt.setDescription(new String[]{"Cancelar"});
216
                return;
217
            }
218

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

    
223

    
224
                (context.getState()).Exit(context);
225
                context.clearState();
226
                try
227
                {
228
                    ctxt.setQuestion("Insertar punto de esquina opuesta o Cuadrado[C]");
229
                    ctxt.setDescription(new String[]{"Cuadrado", "Cancelar"});
230
                    ctxt.addPoint(pointX, pointY);
231
                }
232
                finally
233
                {
234
                    context.setState(ExecuteMap.First);
235
                    (context.getState()).Entry(context);
236
                }
237
                return;
238
            }
239

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

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

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

    
257
            protected void addOption(RectangleCADToolContext context, String s)
258
            {
259
                RectangleCADTool ctxt = context.getOwner();
260

    
261
                if (s.equals("c") || s.equals("C") || s.equals("Cuadrado"))
262
                {
263

    
264
                    (context.getState()).Exit(context);
265
                    context.clearState();
266
                    try
267
                    {
268
                        ctxt.setQuestion("Insertar esquina opuesta");
269
                        ctxt.setDescription(new String[]{"Cancelar"});
270
                        ctxt.addOption(s);
271
                    }
272
                    finally
273
                    {
274
                        context.setState(ExecuteMap.Second);
275
                        (context.getState()).Entry(context);
276
                    }
277
                }
278
                else
279
                {
280
                    super.addOption(context, s);
281
                }
282

    
283
                return;
284
            }
285

    
286
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY)
287
            {
288
                RectangleCADTool ctxt = context.getOwner();
289

    
290

    
291
                (context.getState()).Exit(context);
292
                context.clearState();
293
                try
294
                {
295
                    ctxt.addPoint(pointX, pointY);
296
                    ctxt.end();
297
                }
298
                finally
299
                {
300
                    context.setState(ExecuteMap.Third);
301
                    (context.getState()).Entry(context);
302
                }
303
                return;
304
            }
305

    
306
        //-------------------------------------------------------
307
        // Member data.
308
        //
309
        }
310

    
311
        private static final class ExecuteMap_Second
312
            extends ExecuteMap_Default
313
        {
314
        //-------------------------------------------------------
315
        // Member methods.
316
        //
317

    
318
            private ExecuteMap_Second(String name, int id)
319
            {
320
                super (name, id);
321
            }
322

    
323
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY)
324
            {
325
                RectangleCADTool ctxt = context.getOwner();
326

    
327

    
328
                (context.getState()).Exit(context);
329
                context.clearState();
330
                try
331
                {
332
                    ctxt.addPoint(pointX, pointY);
333
                    ctxt.end();
334
                }
335
                finally
336
                {
337
                    context.setState(ExecuteMap.Fourth);
338
                    (context.getState()).Entry(context);
339
                }
340
                return;
341
            }
342

    
343
        //-------------------------------------------------------
344
        // Member data.
345
        //
346
        }
347

    
348
        private static final class ExecuteMap_Third
349
            extends ExecuteMap_Default
350
        {
351
        //-------------------------------------------------------
352
        // Member methods.
353
        //
354

    
355
            private ExecuteMap_Third(String name, int id)
356
            {
357
                super (name, id);
358
            }
359

    
360
        //-------------------------------------------------------
361
        // Member data.
362
        //
363
        }
364

    
365
        private static final class ExecuteMap_Fourth
366
            extends ExecuteMap_Default
367
        {
368
        //-------------------------------------------------------
369
        // Member methods.
370
        //
371

    
372
            private ExecuteMap_Fourth(String name, int id)
373
            {
374
                super (name, id);
375
            }
376

    
377
        //-------------------------------------------------------
378
        // Member data.
379
        //
380
        }
381

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