Statistics
| Revision:

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

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

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

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

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

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

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

    
71
    transient private RotateCADTool _owner;
72

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

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

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

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

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

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

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

    
107
        protected void Default(RotateCADToolContext 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
        private static ExecuteMap_Default Default;
139

    
140
        static
141
        {
142
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
143
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
144
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
145
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
146
        }
147

    
148
    }
149

    
150
    protected static class ExecuteMap_Default
151
        extends RotateCADToolState
152
    {
153
    //-----------------------------------------------------------
154
    // Member methods.
155
    //
156

    
157
        protected ExecuteMap_Default(String name, int id)
158
        {
159
            super (name, id);
160
        }
161

    
162
        protected void addOption(RotateCADToolContext context, String s)
163
        {
164
            RotateCADTool ctxt = context.getOwner();
165

    
166
            if (s.equals("Cancelar"))
167
            {
168
                boolean loopbackFlag =
169
                    context.getState().getName().equals(
170
                        ExecuteMap.Initial.getName());
171

    
172
                if (loopbackFlag == false)
173
                {
174
                    (context.getState()).Exit(context);
175
                }
176

    
177
                context.clearState();
178
                try
179
                {
180
                    ctxt.end();
181
                }
182
                finally
183
                {
184
                    context.setState(ExecuteMap.Initial);
185

    
186
                    if (loopbackFlag == false)
187
                    {
188
                        (context.getState()).Entry(context);
189
                    }
190

    
191
                }
192
            }
193
            else
194
            {
195
                super.addOption(context, s);
196
            }
197

    
198
            return;
199
        }
200

    
201
    //-----------------------------------------------------------
202
    // Inner classse.
203
    //
204

    
205

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

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

    
218
            protected void Entry(RotateCADToolContext context)
219
            {
220
                RotateCADTool ctxt = context.getOwner();
221

    
222
                ctxt.selection();
223
                ctxt.setQuestion("ROTAR" + "\n" +
224
                "Precise punto base");
225
                ctxt.setDescription(new String[]{"Cancelar"});
226
                return;
227
            }
228

    
229
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY)
230
            {
231
                RotateCADTool ctxt = context.getOwner();
232

    
233

    
234
                (context.getState()).Exit(context);
235
                context.clearState();
236
                try
237
                {
238
                    ctxt.setQuestion("Precise angulo de rotacion");
239
                    ctxt.setDescription(new String[]{"Cancelar"});
240
                    ctxt.addPoint(pointX, pointY);
241
                }
242
                finally
243
                {
244
                    context.setState(ExecuteMap.First);
245
                    (context.getState()).Entry(context);
246
                }
247
                return;
248
            }
249

    
250
        //-------------------------------------------------------
251
        // Member data.
252
        //
253
        }
254

    
255
        private static final class ExecuteMap_First
256
            extends ExecuteMap_Default
257
        {
258
        //-------------------------------------------------------
259
        // Member methods.
260
        //
261

    
262
            private ExecuteMap_First(String name, int id)
263
            {
264
                super (name, id);
265
            }
266

    
267
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY)
268
            {
269
                RotateCADTool ctxt = context.getOwner();
270

    
271

    
272
                (context.getState()).Exit(context);
273
                context.clearState();
274
                try
275
                {
276
                    ctxt.setDescription(new String[]{"Cancelar"});
277
                    ctxt.addPoint(pointX, pointY);
278
                    ctxt.end();
279
                    ctxt.refresh();
280
                }
281
                finally
282
                {
283
                    context.setState(ExecuteMap.Second);
284
                    (context.getState()).Entry(context);
285
                }
286
                return;
287
            }
288

    
289
            protected void addValue(RotateCADToolContext context, double d)
290
            {
291
                RotateCADTool ctxt = context.getOwner();
292

    
293

    
294
                (context.getState()).Exit(context);
295
                context.clearState();
296
                try
297
                {
298
                    ctxt.setDescription(new String[]{"Cancelar"});
299
                    ctxt.addValue(d);
300
                    ctxt.end();
301
                    ctxt.refresh();
302
                }
303
                finally
304
                {
305
                    context.setState(ExecuteMap.Second);
306
                    (context.getState()).Entry(context);
307
                }
308
                return;
309
            }
310

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

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

    
323
            private ExecuteMap_Second(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
}