Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_902 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / RotateCADToolContext.java @ 10681

History | View | Annotate | Download (10.8 KB)

1 3883 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.RotateCADTool;
9 4324 caballero
import java.awt.event.InputEvent;
10 4584 caballero
import com.iver.andami.PluginServices;
11 3883 caballero
12
public final class RotateCADToolContext
13
    extends statemap.FSMContext
14
{
15
//---------------------------------------------------------------
16
// Member methods.
17
//
18
19
    public RotateCADToolContext(RotateCADTool owner)
20
    {
21
        super();
22
23
        _owner = owner;
24 3978 caballero
        setState(Rotate.PointMain);
25
        Rotate.PointMain.Entry(this);
26 3883 caballero
    }
27
28
    public void addOption(String s)
29
    {
30
        _transition = "addOption";
31
        getState().addOption(this, s);
32
        _transition = "";
33
        return;
34
    }
35
36 4324 caballero
    public void addPoint(double pointX, double pointY, InputEvent event)
37 3883 caballero
    {
38
        _transition = "addPoint";
39 4324 caballero
        getState().addPoint(this, pointX, pointY, event);
40 3883 caballero
        _transition = "";
41
        return;
42
    }
43
44
    public void addValue(double d)
45
    {
46
        _transition = "addValue";
47
        getState().addValue(this, d);
48
        _transition = "";
49
        return;
50
    }
51
52
    public RotateCADToolState getState()
53
        throws statemap.StateUndefinedException
54
    {
55
        if (_state == null)
56
        {
57
            throw(
58
                new statemap.StateUndefinedException());
59
        }
60
61
        return ((RotateCADToolState) _state);
62
    }
63
64
    protected RotateCADTool getOwner()
65
    {
66
        return (_owner);
67
    }
68
69
//---------------------------------------------------------------
70
// Member data.
71
//
72
73
    transient private RotateCADTool _owner;
74
75
//---------------------------------------------------------------
76
// Inner classes.
77
//
78
79
    public static abstract class RotateCADToolState
80
        extends statemap.State
81
    {
82
    //-----------------------------------------------------------
83
    // Member methods.
84
    //
85
86
        protected RotateCADToolState(String name, int id)
87
        {
88
            super (name, id);
89
        }
90
91
        protected void Entry(RotateCADToolContext context) {}
92
        protected void Exit(RotateCADToolContext context) {}
93
94
        protected void addOption(RotateCADToolContext context, String s)
95
        {
96
            Default(context);
97
        }
98
99 4324 caballero
        protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
100 3883 caballero
        {
101
            Default(context);
102
        }
103
104
        protected void addValue(RotateCADToolContext context, double d)
105
        {
106
            Default(context);
107
        }
108
109
        protected void Default(RotateCADToolContext context)
110
        {
111
            throw (
112
                new statemap.TransitionUndefinedException(
113
                    "State: " +
114
                    context.getState().getName() +
115
                    ", Transition: " +
116
                    context.getTransition()));
117
        }
118
119
    //-----------------------------------------------------------
120
    // Member data.
121
    //
122
    }
123
124 3978 caballero
    /* package */ static abstract class Rotate
125 3883 caballero
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129
130
    //-----------------------------------------------------------
131
    // Member data.
132
    //
133
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137 3978 caballero
        /* package */ static Rotate_Default.Rotate_PointMain PointMain;
138
        /* package */ static Rotate_Default.Rotate_AngleOrPoint AngleOrPoint;
139
        private static Rotate_Default Default;
140 3883 caballero
141
        static
142
        {
143 3978 caballero
            PointMain = new Rotate_Default.Rotate_PointMain("Rotate.PointMain", 0);
144
            AngleOrPoint = new Rotate_Default.Rotate_AngleOrPoint("Rotate.AngleOrPoint", 1);
145
            Default = new Rotate_Default("Rotate.Default", -1);
146 3883 caballero
        }
147
148
    }
149
150 3978 caballero
    protected static class Rotate_Default
151 3883 caballero
        extends RotateCADToolState
152
    {
153
    //-----------------------------------------------------------
154
    // Member methods.
155
    //
156
157 3978 caballero
        protected Rotate_Default(String name, int id)
158 3883 caballero
        {
159
            super (name, id);
160
        }
161
162
        protected void addOption(RotateCADToolContext context, String s)
163
        {
164
            RotateCADTool ctxt = context.getOwner();
165
166 4584 caballero
            if (s.equals(PluginServices.getText(this,"cancel")))
167 3883 caballero
            {
168
                boolean loopbackFlag =
169
                    context.getState().getName().equals(
170 3978 caballero
                        Rotate.PointMain.getName());
171 3883 caballero
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 3978 caballero
                    context.setState(Rotate.PointMain);
185 3883 caballero
186
                    if (loopbackFlag == false)
187
                    {
188
                        (context.getState()).Entry(context);
189
                    }
190
191
                }
192
            }
193
            else
194
            {
195 5735 caballero
                boolean loopbackFlag =
196
                    context.getState().getName().equals(
197
                        Rotate.PointMain.getName());
198
199
                if (loopbackFlag == false)
200
                {
201
                    (context.getState()).Exit(context);
202
                }
203
204
                context.clearState();
205
                try
206
                {
207
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
208
                }
209
                finally
210
                {
211
                    context.setState(Rotate.PointMain);
212
213
                    if (loopbackFlag == false)
214
                    {
215
                        (context.getState()).Entry(context);
216
                    }
217
218
                }
219 3883 caballero
            }
220
221
            return;
222
        }
223
224 5735 caballero
        protected void addValue(RotateCADToolContext context, double d)
225
        {
226
            RotateCADTool ctxt = context.getOwner();
227
228
            boolean loopbackFlag =
229
                context.getState().getName().equals(
230
                    Rotate.PointMain.getName());
231
232
            if (loopbackFlag == false)
233
            {
234
                (context.getState()).Exit(context);
235
            }
236
237
            context.clearState();
238
            try
239
            {
240
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
241
            }
242
            finally
243
            {
244
                context.setState(Rotate.PointMain);
245
246
                if (loopbackFlag == false)
247
                {
248
                    (context.getState()).Entry(context);
249
                }
250
251
            }
252
            return;
253
        }
254
255
        protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
256
        {
257
            RotateCADTool ctxt = context.getOwner();
258
259
            boolean loopbackFlag =
260
                context.getState().getName().equals(
261
                    Rotate.PointMain.getName());
262
263
            if (loopbackFlag == false)
264
            {
265
                (context.getState()).Exit(context);
266
            }
267
268
            context.clearState();
269
            try
270
            {
271
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
272
            }
273
            finally
274
            {
275
                context.setState(Rotate.PointMain);
276
277
                if (loopbackFlag == false)
278
                {
279
                    (context.getState()).Entry(context);
280
                }
281
282
            }
283
            return;
284
        }
285
286 3883 caballero
    //-----------------------------------------------------------
287
    // Inner classse.
288
    //
289
290
291 3978 caballero
        private static final class Rotate_PointMain
292
            extends Rotate_Default
293 3883 caballero
        {
294
        //-------------------------------------------------------
295
        // Member methods.
296
        //
297
298 3978 caballero
            private Rotate_PointMain(String name, int id)
299 3883 caballero
            {
300
                super (name, id);
301
            }
302
303
            protected void Entry(RotateCADToolContext context)
304
            {
305
                RotateCADTool ctxt = context.getOwner();
306
307
                ctxt.selection();
308 4892 caballero
                ctxt.setQuestion(PluginServices.getText(this,"insert_basis_point"));
309 4584 caballero
                ctxt.setDescription(new String[]{"cancel"});
310 3883 caballero
                return;
311
            }
312
313 4324 caballero
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
314 3883 caballero
            {
315
                RotateCADTool ctxt = context.getOwner();
316
317
318
                (context.getState()).Exit(context);
319
                context.clearState();
320
                try
321
                {
322 4584 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"insert_rotation_angle"));
323
                    ctxt.setDescription(new String[]{"cancel"});
324 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
325 3883 caballero
                }
326
                finally
327
                {
328 3978 caballero
                    context.setState(Rotate.AngleOrPoint);
329 3883 caballero
                    (context.getState()).Entry(context);
330
                }
331
                return;
332
            }
333
334
        //-------------------------------------------------------
335
        // Member data.
336
        //
337
        }
338
339 3978 caballero
        private static final class Rotate_AngleOrPoint
340
            extends Rotate_Default
341 3883 caballero
        {
342
        //-------------------------------------------------------
343
        // Member methods.
344
        //
345
346 3978 caballero
            private Rotate_AngleOrPoint(String name, int id)
347 3883 caballero
            {
348
                super (name, id);
349
            }
350
351 4324 caballero
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
352 3883 caballero
            {
353
                RotateCADTool ctxt = context.getOwner();
354
355
356
                (context.getState()).Exit(context);
357
                context.clearState();
358
                try
359
                {
360 4584 caballero
                    ctxt.setDescription(new String[]{"cancel"});
361 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
362 3883 caballero
                    ctxt.end();
363
                    ctxt.refresh();
364
                }
365
                finally
366
                {
367 3978 caballero
                    context.setState(Rotate.PointMain);
368 3883 caballero
                    (context.getState()).Entry(context);
369
                }
370
                return;
371
            }
372
373
            protected void addValue(RotateCADToolContext context, double d)
374
            {
375
                RotateCADTool ctxt = context.getOwner();
376
377
378
                (context.getState()).Exit(context);
379
                context.clearState();
380
                try
381
                {
382 4584 caballero
                    ctxt.setDescription(new String[]{"cancel"});
383 3883 caballero
                    ctxt.addValue(d);
384
                    ctxt.end();
385
                    ctxt.refresh();
386
                }
387
                finally
388
                {
389 3978 caballero
                    context.setState(Rotate.PointMain);
390 3883 caballero
                    (context.getState()).Entry(context);
391
                }
392
                return;
393
            }
394
395
        //-------------------------------------------------------
396
        // Member data.
397
        //
398
        }
399
400
    //-----------------------------------------------------------
401
    // Member data.
402
    //
403
    }
404
}