Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / EllipseCADToolContext.java @ 10626

History | View | Annotate | Download (12.2 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

    
6
package com.iver.cit.gvsig.gui.cad.tools.smc;
7

    
8
import java.awt.event.InputEvent;
9

    
10
import com.iver.andami.PluginServices;
11
import com.iver.cit.gvsig.gui.cad.tools.EllipseCADTool;
12

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

    
20
    public EllipseCADToolContext(EllipseCADTool owner)
21
    {
22
        super();
23

    
24
        _owner = owner;
25
        setState(Ellipse.FirstPointAxis);
26
        Ellipse.FirstPointAxis.Entry(this);
27
    }
28

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

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

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

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

    
62
        return ((EllipseCADToolState) _state);
63
    }
64

    
65
    protected EllipseCADTool getOwner()
66
    {
67
        return (_owner);
68
    }
69

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

    
74
    transient private EllipseCADTool _owner;
75

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

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

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

    
92
        protected void Entry(EllipseCADToolContext context) {}
93
        protected void Exit(EllipseCADToolContext context) {}
94

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

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

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

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

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

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

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

    
135
        //-------------------------------------------------------
136
        // Statics.
137
        //
138
        /* package */ static Ellipse_Default.Ellipse_FirstPointAxis FirstPointAxis;
139
        /* package */ static Ellipse_Default.Ellipse_SecondPointAxis SecondPointAxis;
140
        /* package */ static Ellipse_Default.Ellipse_DistanceOtherAxis DistanceOtherAxis;
141
        private static Ellipse_Default Default;
142

    
143
        static
144
        {
145
            FirstPointAxis = new Ellipse_Default.Ellipse_FirstPointAxis("Ellipse.FirstPointAxis", 0);
146
            SecondPointAxis = new Ellipse_Default.Ellipse_SecondPointAxis("Ellipse.SecondPointAxis", 1);
147
            DistanceOtherAxis = new Ellipse_Default.Ellipse_DistanceOtherAxis("Ellipse.DistanceOtherAxis", 2);
148
            Default = new Ellipse_Default("Ellipse.Default", -1);
149
        }
150

    
151
    }
152

    
153
    protected static class Ellipse_Default
154
        extends EllipseCADToolState
155
    {
156
    //-----------------------------------------------------------
157
    // Member methods.
158
    //
159

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

    
165
        protected void addOption(EllipseCADToolContext context, String s)
166
        {
167
            EllipseCADTool ctxt = context.getOwner();
168

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

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

    
180
                context.clearState();
181
                try
182
                {
183
                    ctxt.end();
184
                }
185
                finally
186
                {
187
                    context.setState(Ellipse.FirstPointAxis);
188

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

    
194
                }
195
            }
196
            else
197
            {
198
                boolean loopbackFlag =
199
                    context.getState().getName().equals(
200
                        Ellipse.FirstPointAxis.getName());
201

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

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

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

    
221
                }
222
            }
223

    
224
            return;
225
        }
226

    
227
        protected void addValue(EllipseCADToolContext context, double d)
228
        {
229
            EllipseCADTool ctxt = context.getOwner();
230

    
231
            boolean loopbackFlag =
232
                context.getState().getName().equals(
233
                    Ellipse.FirstPointAxis.getName());
234

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

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

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

    
254
            }
255
            return;
256
        }
257

    
258
        protected void addPoint(EllipseCADToolContext context, double pointX, double pointY, InputEvent event)
259
        {
260
            EllipseCADTool ctxt = context.getOwner();
261

    
262
            boolean loopbackFlag =
263
                context.getState().getName().equals(
264
                    Ellipse.FirstPointAxis.getName());
265

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

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

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

    
285
            }
286
            return;
287
        }
288

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

    
293

    
294
        private static final class Ellipse_FirstPointAxis
295
            extends Ellipse_Default
296
        {
297
        //-------------------------------------------------------
298
        // Member methods.
299
        //
300

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

    
306
            protected void Entry(EllipseCADToolContext context)
307
            {
308
                EllipseCADTool ctxt = context.getOwner();
309

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

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

    
319

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

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

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

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

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

    
357

    
358
                (context.getState()).Exit(context);
359
                context.clearState();
360
                try
361
                {
362
                    ctxt.setQuestion(PluginServices.getText(this,"insert_distance_another_axis"));
363
                    ctxt.setDescription(new String[]{"cancel"});
364
                    ctxt.addPoint(pointX, pointY, event);
365
                }
366
                finally
367
                {
368
                    context.setState(Ellipse.DistanceOtherAxis);
369
                    (context.getState()).Entry(context);
370
                }
371
                return;
372
            }
373

    
374
        //-------------------------------------------------------
375
        // Member data.
376
        //
377
        }
378

    
379
        private static final class Ellipse_DistanceOtherAxis
380
            extends Ellipse_Default
381
        {
382
        //-------------------------------------------------------
383
        // Member methods.
384
        //
385

    
386
            private Ellipse_DistanceOtherAxis(String name, int id)
387
            {
388
                super (name, id);
389
            }
390

    
391
            protected void addPoint(EllipseCADToolContext context, double pointX, double pointY, InputEvent event)
392
            {
393
                EllipseCADTool ctxt = context.getOwner();
394

    
395

    
396
                (context.getState()).Exit(context);
397
                context.clearState();
398
                try
399
                {
400
                    ctxt.addPoint(pointX, pointY, event);
401
                    ctxt.end();
402
                }
403
                finally
404
                {
405
                    context.setState(Ellipse.FirstPointAxis);
406
                    (context.getState()).Entry(context);
407
                }
408
                return;
409
            }
410

    
411
            protected void addValue(EllipseCADToolContext context, double d)
412
            {
413
                EllipseCADTool ctxt = context.getOwner();
414

    
415

    
416
                (context.getState()).Exit(context);
417
                context.clearState();
418
                try
419
                {
420
                    ctxt.addValue(d);
421
                    ctxt.end();
422
                }
423
                finally
424
                {
425
                    context.setState(Ellipse.FirstPointAxis);
426
                    (context.getState()).Entry(context);
427
                }
428
                return;
429
            }
430

    
431
        //-------------------------------------------------------
432
        // Member data.
433
        //
434
        }
435

    
436
    //-----------------------------------------------------------
437
    // Member data.
438
    //
439
    }
440
}