Statistics
| Revision:

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

History | View | Annotate | Download (9.19 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
    //-----------------------------------------------------------
154
    // Inner classse.
155
    //
156

    
157

    
158
        private static final class ExecuteMap_Initial
159
            extends ExecuteMap_Default
160
        {
161
        //-------------------------------------------------------
162
        // Member methods.
163
        //
164

    
165
            private ExecuteMap_Initial(String name, int id)
166
            {
167
                super (name, id);
168
            }
169

    
170
            protected void Entry(RectangleCADToolContext context)
171
            {
172
                RectangleCADTool ctxt = context.getOwner();
173

    
174
                ctxt.init();
175
                ctxt.setQuestion("RECTANGULO" + "\n" +
176
                "Insertar primer punto de esquina");
177
                return;
178
            }
179

    
180
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY)
181
            {
182
                RectangleCADTool ctxt = context.getOwner();
183

    
184

    
185
                (context.getState()).Exit(context);
186
                context.clearState();
187
                try
188
                {
189
                    ctxt.setQuestion("Insertar punto de esquina opuesta o Cuadrado[C]");
190
                    ctxt.addPoint(pointX, pointY);
191
                }
192
                finally
193
                {
194
                    context.setState(ExecuteMap.First);
195
                    (context.getState()).Entry(context);
196
                }
197
                return;
198
            }
199

    
200
        //-------------------------------------------------------
201
        // Member data.
202
        //
203
        }
204

    
205
        private static final class ExecuteMap_First
206
            extends ExecuteMap_Default
207
        {
208
        //-------------------------------------------------------
209
        // Member methods.
210
        //
211

    
212
            private ExecuteMap_First(String name, int id)
213
            {
214
                super (name, id);
215
            }
216

    
217
            protected void addOption(RectangleCADToolContext context, String s)
218
            {
219
                RectangleCADTool ctxt = context.getOwner();
220

    
221

    
222
                (context.getState()).Exit(context);
223
                context.clearState();
224
                try
225
                {
226
                    ctxt.setQuestion("Insertar esquina opuesta");
227
                    ctxt.addOption(s);
228
                }
229
                finally
230
                {
231
                    context.setState(ExecuteMap.Second);
232
                    (context.getState()).Entry(context);
233
                }
234
                return;
235
            }
236

    
237
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY)
238
            {
239
                RectangleCADTool ctxt = context.getOwner();
240

    
241

    
242
                (context.getState()).Exit(context);
243
                context.clearState();
244
                try
245
                {
246
                    ctxt.addPoint(pointX, pointY);
247
                    ctxt.end();
248
                }
249
                finally
250
                {
251
                    context.setState(ExecuteMap.Third);
252
                    (context.getState()).Entry(context);
253
                }
254
                return;
255
            }
256

    
257
        //-------------------------------------------------------
258
        // Member data.
259
        //
260
        }
261

    
262
        private static final class ExecuteMap_Second
263
            extends ExecuteMap_Default
264
        {
265
        //-------------------------------------------------------
266
        // Member methods.
267
        //
268

    
269
            private ExecuteMap_Second(String name, int id)
270
            {
271
                super (name, id);
272
            }
273

    
274
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY)
275
            {
276
                RectangleCADTool ctxt = context.getOwner();
277

    
278

    
279
                (context.getState()).Exit(context);
280
                context.clearState();
281
                try
282
                {
283
                    ctxt.addPoint(pointX, pointY);
284
                    ctxt.end();
285
                }
286
                finally
287
                {
288
                    context.setState(ExecuteMap.Fourth);
289
                    (context.getState()).Entry(context);
290
                }
291
                return;
292
            }
293

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

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

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

    
311
        //-------------------------------------------------------
312
        // Member data.
313
        //
314
        }
315

    
316
        private static final class ExecuteMap_Fourth
317
            extends ExecuteMap_Default
318
        {
319
        //-------------------------------------------------------
320
        // Member methods.
321
        //
322

    
323
            private ExecuteMap_Fourth(String name, int id)
324
            {
325
                super (name, id);
326
            }
327

    
328
        //-------------------------------------------------------
329
        // Member data.
330
        //
331
        }
332

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