Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / smc / RotateCADToolContext.java @ 29616

History | View | Annotate | Download (10.8 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

    
6
package org.gvsig.editing.gui.cad.tools.smc;
7

    
8
import java.awt.event.InputEvent;
9

    
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.editing.gui.cad.tools.RotateCADTool;
12

    
13

    
14
public final class RotateCADToolContext
15
    extends statemap.FSMContext
16
{
17
//---------------------------------------------------------------
18
// Member methods.
19
//
20

    
21
    public RotateCADToolContext(RotateCADTool owner)
22
    {
23
        super();
24

    
25
        _owner = owner;
26
        setState(Rotate.PointMain);
27
        Rotate.PointMain.Entry(this);
28
    }
29

    
30
    public void addOption(String s)
31
    {
32
        _transition = "addOption";
33
        getState().addOption(this, s);
34
        _transition = "";
35
        return;
36
    }
37

    
38
    public void addPoint(double pointX, double pointY, InputEvent event)
39
    {
40
        _transition = "addPoint";
41
        getState().addPoint(this, pointX, pointY, event);
42
        _transition = "";
43
        return;
44
    }
45

    
46
    public void addValue(double d)
47
    {
48
        _transition = "addValue";
49
        getState().addValue(this, d);
50
        _transition = "";
51
        return;
52
    }
53

    
54
    public RotateCADToolState getState()
55
        throws statemap.StateUndefinedException
56
    {
57
        if (_state == null)
58
        {
59
            throw(
60
                new statemap.StateUndefinedException());
61
        }
62

    
63
        return ((RotateCADToolState) _state);
64
    }
65

    
66
    protected RotateCADTool getOwner()
67
    {
68
        return (_owner);
69
    }
70

    
71
//---------------------------------------------------------------
72
// Member data.
73
//
74

    
75
    transient private RotateCADTool _owner;
76

    
77
//---------------------------------------------------------------
78
// Inner classes.
79
//
80

    
81
    public static abstract class RotateCADToolState
82
        extends statemap.State
83
    {
84
    //-----------------------------------------------------------
85
    // Member methods.
86
    //
87

    
88
        protected RotateCADToolState(String name, int id)
89
        {
90
            super (name, id);
91
        }
92

    
93
        protected void Entry(RotateCADToolContext context) {}
94
        protected void Exit(RotateCADToolContext context) {}
95

    
96
        protected void addOption(RotateCADToolContext context, String s)
97
        {
98
            Default(context);
99
        }
100

    
101
        protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
102
        {
103
            Default(context);
104
        }
105

    
106
        protected void addValue(RotateCADToolContext context, double d)
107
        {
108
            Default(context);
109
        }
110

    
111
        protected void Default(RotateCADToolContext context)
112
        {
113
            throw (
114
                new statemap.TransitionUndefinedException(
115
                    "State: " +
116
                    context.getState().getName() +
117
                    ", Transition: " +
118
                    context.getTransition()));
119
        }
120

    
121
    //-----------------------------------------------------------
122
    // Member data.
123
    //
124
    }
125

    
126
    /* package */ static abstract class Rotate
127
    {
128
    //-----------------------------------------------------------
129
    // Member methods.
130
    //
131

    
132
    //-----------------------------------------------------------
133
    // Member data.
134
    //
135

    
136
        //-------------------------------------------------------
137
        // Statics.
138
        //
139
        /* package */ static Rotate_Default.Rotate_PointMain PointMain;
140
        /* package */ static Rotate_Default.Rotate_AngleOrPoint AngleOrPoint;
141
        private static Rotate_Default Default;
142

    
143
        static
144
        {
145
            PointMain = new Rotate_Default.Rotate_PointMain("Rotate.PointMain", 0);
146
            AngleOrPoint = new Rotate_Default.Rotate_AngleOrPoint("Rotate.AngleOrPoint", 1);
147
            Default = new Rotate_Default("Rotate.Default", -1);
148
        }
149

    
150
    }
151

    
152
    protected static class Rotate_Default
153
        extends RotateCADToolState
154
    {
155
    //-----------------------------------------------------------
156
    // Member methods.
157
    //
158

    
159
        protected Rotate_Default(String name, int id)
160
        {
161
            super (name, id);
162
        }
163

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

    
168
            if (s.equals(PluginServices.getText(this,"cancel")))
169
            {
170
                boolean loopbackFlag =
171
                    context.getState().getName().equals(
172
                        Rotate.PointMain.getName());
173

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

    
179
                context.clearState();
180
                try
181
                {
182
                    ctxt.end();
183
                }
184
                finally
185
                {
186
                    context.setState(Rotate.PointMain);
187

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

    
193
                }
194
            }
195
            else
196
            {
197
                boolean loopbackFlag =
198
                    context.getState().getName().equals(
199
                        Rotate.PointMain.getName());
200

    
201
                if (loopbackFlag == false)
202
                {
203
                    (context.getState()).Exit(context);
204
                }
205

    
206
                context.clearState();
207
                try
208
                {
209
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
210
                }
211
                finally
212
                {
213
                    context.setState(Rotate.PointMain);
214

    
215
                    if (loopbackFlag == false)
216
                    {
217
                        (context.getState()).Entry(context);
218
                    }
219

    
220
                }
221
            }
222

    
223
            return;
224
        }
225

    
226
        protected void addValue(RotateCADToolContext context, double d)
227
        {
228
            RotateCADTool ctxt = context.getOwner();
229

    
230
            boolean loopbackFlag =
231
                context.getState().getName().equals(
232
                    Rotate.PointMain.getName());
233

    
234
            if (loopbackFlag == false)
235
            {
236
                (context.getState()).Exit(context);
237
            }
238

    
239
            context.clearState();
240
            try
241
            {
242
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
243
            }
244
            finally
245
            {
246
                context.setState(Rotate.PointMain);
247

    
248
                if (loopbackFlag == false)
249
                {
250
                    (context.getState()).Entry(context);
251
                }
252

    
253
            }
254
            return;
255
        }
256

    
257
        protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
258
        {
259
            RotateCADTool ctxt = context.getOwner();
260

    
261
            boolean loopbackFlag =
262
                context.getState().getName().equals(
263
                    Rotate.PointMain.getName());
264

    
265
            if (loopbackFlag == false)
266
            {
267
                (context.getState()).Exit(context);
268
            }
269

    
270
            context.clearState();
271
            try
272
            {
273
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
274
            }
275
            finally
276
            {
277
                context.setState(Rotate.PointMain);
278

    
279
                if (loopbackFlag == false)
280
                {
281
                    (context.getState()).Entry(context);
282
                }
283

    
284
            }
285
            return;
286
        }
287

    
288
    //-----------------------------------------------------------
289
    // Inner classse.
290
    //
291

    
292

    
293
        private static final class Rotate_PointMain
294
            extends Rotate_Default
295
        {
296
        //-------------------------------------------------------
297
        // Member methods.
298
        //
299

    
300
            private Rotate_PointMain(String name, int id)
301
            {
302
                super (name, id);
303
            }
304

    
305
            protected void Entry(RotateCADToolContext context)
306
            {
307
                RotateCADTool ctxt = context.getOwner();
308

    
309
                ctxt.selection();
310
                ctxt.setQuestion(PluginServices.getText(this,"insert_basis_point"));
311
                ctxt.setDescription(new String[]{"cancel"});
312
                return;
313
            }
314

    
315
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
316
            {
317
                RotateCADTool ctxt = context.getOwner();
318

    
319

    
320
                (context.getState()).Exit(context);
321
                context.clearState();
322
                try
323
                {
324
                    ctxt.setQuestion(PluginServices.getText(this,"insert_rotation_angle"));
325
                    ctxt.setDescription(new String[]{"cancel"});
326
                    ctxt.addPoint(pointX, pointY, event);
327
                }
328
                finally
329
                {
330
                    context.setState(Rotate.AngleOrPoint);
331
                    (context.getState()).Entry(context);
332
                }
333
                return;
334
            }
335

    
336
        //-------------------------------------------------------
337
        // Member data.
338
        //
339
        }
340

    
341
        private static final class Rotate_AngleOrPoint
342
            extends Rotate_Default
343
        {
344
        //-------------------------------------------------------
345
        // Member methods.
346
        //
347

    
348
            private Rotate_AngleOrPoint(String name, int id)
349
            {
350
                super (name, id);
351
            }
352

    
353
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
354
            {
355
                RotateCADTool ctxt = context.getOwner();
356

    
357

    
358
                (context.getState()).Exit(context);
359
                context.clearState();
360
                try
361
                {
362
                    ctxt.setDescription(new String[]{"cancel"});
363
                    ctxt.addPoint(pointX, pointY, event);
364
                    ctxt.end();
365
                    ctxt.refresh();
366
                }
367
                finally
368
                {
369
                    context.setState(Rotate.PointMain);
370
                    (context.getState()).Entry(context);
371
                }
372
                return;
373
            }
374

    
375
            protected void addValue(RotateCADToolContext context, double d)
376
            {
377
                RotateCADTool ctxt = context.getOwner();
378

    
379

    
380
                (context.getState()).Exit(context);
381
                context.clearState();
382
                try
383
                {
384
                    ctxt.setDescription(new String[]{"cancel"});
385
                    ctxt.addValue(d);
386
                    ctxt.end();
387
                    ctxt.refresh();
388
                }
389
                finally
390
                {
391
                    context.setState(Rotate.PointMain);
392
                    (context.getState()).Entry(context);
393
                }
394
                return;
395
            }
396

    
397
        //-------------------------------------------------------
398
        // Member data.
399
        //
400
        }
401

    
402
    //-----------------------------------------------------------
403
    // Member data.
404
    //
405
    }
406
}