Statistics
| Revision:

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

History | View | Annotate | Download (8.99 KB)

1 3782 caballero
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.ArcCADTool;
9
10
public final class ArcCADToolContext
11
    extends statemap.FSMContext
12
{
13
//---------------------------------------------------------------
14
// Member methods.
15
//
16
17
    public ArcCADToolContext(ArcCADTool owner)
18
    {
19
        super();
20
21
        _owner = owner;
22
        setState(ExecuteMap.Initial);
23
        ExecuteMap.Initial.Entry(this);
24
    }
25
26 3883 caballero
    public void addOption(String s)
27
    {
28
        _transition = "addOption";
29
        getState().addOption(this, s);
30
        _transition = "";
31
        return;
32
    }
33
34 3832 caballero
    public void addPoint(double pointX, double pointY)
35 3782 caballero
    {
36
        _transition = "addPoint";
37 3832 caballero
        getState().addPoint(this, pointX, pointY);
38 3782 caballero
        _transition = "";
39
        return;
40
    }
41
42
    public ArcCADToolState getState()
43
        throws statemap.StateUndefinedException
44
    {
45
        if (_state == null)
46
        {
47
            throw(
48
                new statemap.StateUndefinedException());
49
        }
50
51
        return ((ArcCADToolState) _state);
52
    }
53
54
    protected ArcCADTool getOwner()
55
    {
56
        return (_owner);
57
    }
58
59
//---------------------------------------------------------------
60
// Member data.
61
//
62
63
    transient private ArcCADTool _owner;
64
65
//---------------------------------------------------------------
66
// Inner classes.
67
//
68
69
    public static abstract class ArcCADToolState
70
        extends statemap.State
71
    {
72
    //-----------------------------------------------------------
73
    // Member methods.
74
    //
75
76
        protected ArcCADToolState(String name, int id)
77
        {
78
            super (name, id);
79
        }
80
81
        protected void Entry(ArcCADToolContext context) {}
82
        protected void Exit(ArcCADToolContext context) {}
83
84 3883 caballero
        protected void addOption(ArcCADToolContext context, String s)
85
        {
86
            Default(context);
87
        }
88
89 3832 caballero
        protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
90 3782 caballero
        {
91
            Default(context);
92
        }
93
94
        protected void Default(ArcCADToolContext 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
        private static ExecuteMap_Default Default;
127
128
        static
129
        {
130
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
131
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
132
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
133
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
134
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
135
        }
136
137
    }
138
139
    protected static class ExecuteMap_Default
140
        extends ArcCADToolState
141
    {
142
    //-----------------------------------------------------------
143
    // Member methods.
144
    //
145
146
        protected ExecuteMap_Default(String name, int id)
147
        {
148
            super (name, id);
149
        }
150
151 3883 caballero
        protected void addOption(ArcCADToolContext context, String s)
152
        {
153
            ArcCADTool ctxt = context.getOwner();
154
155
            if (s.equals("Cancelar"))
156
            {
157
                boolean loopbackFlag =
158
                    context.getState().getName().equals(
159
                        ExecuteMap.Initial.getName());
160
161
                if (loopbackFlag == false)
162
                {
163
                    (context.getState()).Exit(context);
164
                }
165
166
                context.clearState();
167
                try
168
                {
169
                    ctxt.end();
170
                }
171
                finally
172
                {
173
                    context.setState(ExecuteMap.Initial);
174
175
                    if (loopbackFlag == false)
176
                    {
177
                        (context.getState()).Entry(context);
178
                    }
179
180
                }
181
            }
182
            else
183
            {
184
                super.addOption(context, s);
185
            }
186
187
            return;
188
        }
189
190 3782 caballero
    //-----------------------------------------------------------
191
    // Inner classse.
192
    //
193
194
195
        private static final class ExecuteMap_Initial
196
            extends ExecuteMap_Default
197
        {
198
        //-------------------------------------------------------
199
        // Member methods.
200
        //
201
202
            private ExecuteMap_Initial(String name, int id)
203
            {
204
                super (name, id);
205
            }
206
207
            protected void Entry(ArcCADToolContext context)
208
            {
209
                ArcCADTool ctxt = context.getOwner();
210
211 3847 caballero
                ctxt.setQuestion("ARCO" + "\n"+
212
                "Insertar primer punto");
213 3883 caballero
                ctxt.setDescription(new String[]{"Cancelar"});
214 3782 caballero
                return;
215
            }
216
217 3832 caballero
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
218 3782 caballero
            {
219
                ArcCADTool ctxt = context.getOwner();
220
221
222
                (context.getState()).Exit(context);
223
                context.clearState();
224
                try
225
                {
226
                    ctxt.setQuestion("Insertar segundo punto");
227 3883 caballero
                    ctxt.setDescription(new String[]{"Cancelar"});
228 3832 caballero
                    ctxt.addPoint(pointX, pointY);
229 3782 caballero
                }
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 3832 caballero
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
256 3782 caballero
            {
257
                ArcCADTool ctxt = context.getOwner();
258
259
260
                (context.getState()).Exit(context);
261
                context.clearState();
262
                try
263
                {
264
                    ctxt.setQuestion("Insertar ultimo punto");
265 3883 caballero
                    ctxt.setDescription(new String[]{"Cancelar"});
266 3832 caballero
                    ctxt.addPoint(pointX, pointY);
267 3782 caballero
                }
268
                finally
269
                {
270
                    context.setState(ExecuteMap.Second);
271
                    (context.getState()).Entry(context);
272
                }
273
                return;
274
            }
275
276
        //-------------------------------------------------------
277
        // Member data.
278
        //
279
        }
280
281
        private static final class ExecuteMap_Second
282
            extends ExecuteMap_Default
283
        {
284
        //-------------------------------------------------------
285
        // Member methods.
286
        //
287
288
            private ExecuteMap_Second(String name, int id)
289
            {
290
                super (name, id);
291
            }
292
293 3832 caballero
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
294 3782 caballero
            {
295
                ArcCADTool ctxt = context.getOwner();
296
297
298
                (context.getState()).Exit(context);
299
                context.clearState();
300
                try
301
                {
302 3832 caballero
                    ctxt.addPoint(pointX, pointY);
303 3782 caballero
                    ctxt.end();
304
                }
305
                finally
306
                {
307
                    context.setState(ExecuteMap.Third);
308
                    (context.getState()).Entry(context);
309
                }
310
                return;
311
            }
312
313
        //-------------------------------------------------------
314
        // Member data.
315
        //
316
        }
317
318
        private static final class ExecuteMap_Third
319
            extends ExecuteMap_Default
320
        {
321
        //-------------------------------------------------------
322
        // Member methods.
323
        //
324
325
            private ExecuteMap_Third(String name, int id)
326
            {
327
                super (name, id);
328
            }
329
330
        //-------------------------------------------------------
331
        // Member data.
332
        //
333
        }
334
335
    //-----------------------------------------------------------
336
    // Member data.
337
    //
338
    }
339
}