Statistics
| Revision:

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

History | View | Annotate | Download (15.6 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.CircleCADTool;
12

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

    
20
    public CircleCADToolContext(CircleCADTool owner)
21
    {
22
        super();
23

    
24
        _owner = owner;
25
        setState(Circle.CenterPointOr3p);
26
        Circle.CenterPointOr3p.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 CircleCADToolState getState()
54
        throws statemap.StateUndefinedException
55
    {
56
        if (_state == null)
57
        {
58
            throw(
59
                new statemap.StateUndefinedException());
60
        }
61

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

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

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

    
74
    transient private CircleCADTool _owner;
75

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

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

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

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

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

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

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

    
110
        protected void Default(CircleCADToolContext 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 Circle
126
    {
127
    //-----------------------------------------------------------
128
    // Member methods.
129
    //
130

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

    
135
        //-------------------------------------------------------
136
        // Statics.
137
        //
138
        /* package */ static Circle_Default.Circle_CenterPointOr3p CenterPointOr3p;
139
        /* package */ static Circle_Default.Circle_PointOrRadius PointOrRadius;
140
        /* package */ static Circle_Default.Circle_SecondPoint SecondPoint;
141
        /* package */ static Circle_Default.Circle_ThirdPoint ThirdPoint;
142
        /* package */ static Circle_Default.Circle_FirstPoint FirstPoint;
143
        private static Circle_Default Default;
144

    
145
        static
146
        {
147
            CenterPointOr3p = new Circle_Default.Circle_CenterPointOr3p("Circle.CenterPointOr3p", 0);
148
            PointOrRadius = new Circle_Default.Circle_PointOrRadius("Circle.PointOrRadius", 1);
149
            SecondPoint = new Circle_Default.Circle_SecondPoint("Circle.SecondPoint", 2);
150
            ThirdPoint = new Circle_Default.Circle_ThirdPoint("Circle.ThirdPoint", 3);
151
            FirstPoint = new Circle_Default.Circle_FirstPoint("Circle.FirstPoint", 4);
152
            Default = new Circle_Default("Circle.Default", -1);
153
        }
154

    
155
    }
156

    
157
    protected static class Circle_Default
158
        extends CircleCADToolState
159
    {
160
    //-----------------------------------------------------------
161
    // Member methods.
162
    //
163

    
164
        protected Circle_Default(String name, int id)
165
        {
166
            super (name, id);
167
        }
168

    
169
        protected void addOption(CircleCADToolContext context, String s)
170
        {
171
            CircleCADTool ctxt = context.getOwner();
172

    
173
            if (s.equals(PluginServices.getText(this,"cancel")))
174
            {
175
                boolean loopbackFlag =
176
                    context.getState().getName().equals(
177
                        Circle.CenterPointOr3p.getName());
178

    
179
                if (loopbackFlag == false)
180
                {
181
                    (context.getState()).Exit(context);
182
                }
183

    
184
                context.clearState();
185
                try
186
                {
187
                    ctxt.end();
188
                }
189
                finally
190
                {
191
                    context.setState(Circle.CenterPointOr3p);
192

    
193
                    if (loopbackFlag == false)
194
                    {
195
                        (context.getState()).Entry(context);
196
                    }
197

    
198
                }
199
            }
200
            else
201
            {
202
                boolean loopbackFlag =
203
                    context.getState().getName().equals(
204
                        Circle.CenterPointOr3p.getName());
205

    
206
                if (loopbackFlag == false)
207
                {
208
                    (context.getState()).Exit(context);
209
                }
210

    
211
                context.clearState();
212
                try
213
                {
214
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
215
                }
216
                finally
217
                {
218
                    context.setState(Circle.CenterPointOr3p);
219

    
220
                    if (loopbackFlag == false)
221
                    {
222
                        (context.getState()).Entry(context);
223
                    }
224

    
225
                }
226
            }
227

    
228
            return;
229
        }
230

    
231
        protected void addValue(CircleCADToolContext context, double d)
232
        {
233
            CircleCADTool ctxt = context.getOwner();
234

    
235
            boolean loopbackFlag =
236
                context.getState().getName().equals(
237
                    Circle.CenterPointOr3p.getName());
238

    
239
            if (loopbackFlag == false)
240
            {
241
                (context.getState()).Exit(context);
242
            }
243

    
244
            context.clearState();
245
            try
246
            {
247
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
248
            }
249
            finally
250
            {
251
                context.setState(Circle.CenterPointOr3p);
252

    
253
                if (loopbackFlag == false)
254
                {
255
                    (context.getState()).Entry(context);
256
                }
257

    
258
            }
259
            return;
260
        }
261

    
262
        protected void addPoint(CircleCADToolContext context, double pointX, double pointY, InputEvent event)
263
        {
264
            CircleCADTool ctxt = context.getOwner();
265

    
266
            boolean loopbackFlag =
267
                context.getState().getName().equals(
268
                    Circle.CenterPointOr3p.getName());
269

    
270
            if (loopbackFlag == false)
271
            {
272
                (context.getState()).Exit(context);
273
            }
274

    
275
            context.clearState();
276
            try
277
            {
278
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
279
            }
280
            finally
281
            {
282
                context.setState(Circle.CenterPointOr3p);
283

    
284
                if (loopbackFlag == false)
285
                {
286
                    (context.getState()).Entry(context);
287
                }
288

    
289
            }
290
            return;
291
        }
292

    
293
    //-----------------------------------------------------------
294
    // Inner classse.
295
    //
296

    
297

    
298
        private static final class Circle_CenterPointOr3p
299
            extends Circle_Default
300
        {
301
        //-------------------------------------------------------
302
        // Member methods.
303
        //
304

    
305
            private Circle_CenterPointOr3p(String name, int id)
306
            {
307
                super (name, id);
308
            }
309

    
310
            protected void Entry(CircleCADToolContext context)
311
            {
312
                CircleCADTool ctxt = context.getOwner();
313

    
314
                ctxt.setQuestion(PluginServices.getText(this,"insert_central_point_or_3p")+
315
                "["+PluginServices.getText(this,"CircleCADTool.3p")+"]");
316
                ctxt.setDescription(new String[]{"cancel", "3P"});
317
                return;
318
            }
319

    
320
            protected void addOption(CircleCADToolContext context, String s)
321
            {
322
                CircleCADTool ctxt = context.getOwner();
323

    
324
                if (s.equalsIgnoreCase(PluginServices.getText(this,"CircleCADTool.3p")))
325
                {
326

    
327
                    (context.getState()).Exit(context);
328
                    context.clearState();
329
                    try
330
                    {
331
                        ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
332
                        ctxt.setDescription(new String[]{"cancel"});
333
                        ctxt.addOption(s);
334
                    }
335
                    finally
336
                    {
337
                        context.setState(Circle.FirstPoint);
338
                        (context.getState()).Entry(context);
339
                    }
340
                }
341
                else
342
                {
343
                    super.addOption(context, s);
344
                }
345

    
346
                return;
347
            }
348

    
349
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY, InputEvent event)
350
            {
351
                CircleCADTool ctxt = context.getOwner();
352

    
353

    
354
                (context.getState()).Exit(context);
355
                context.clearState();
356
                try
357
                {
358
                    ctxt.setQuestion(PluginServices.getText(this,"insert_radius_or_second_point"));
359
                    ctxt.setDescription(new String[]{"cancel"});
360
                    ctxt.addPoint(pointX, pointY, event);
361
                }
362
                finally
363
                {
364
                    context.setState(Circle.PointOrRadius);
365
                    (context.getState()).Entry(context);
366
                }
367
                return;
368
            }
369

    
370
        //-------------------------------------------------------
371
        // Member data.
372
        //
373
        }
374

    
375
        private static final class Circle_PointOrRadius
376
            extends Circle_Default
377
        {
378
        //-------------------------------------------------------
379
        // Member methods.
380
        //
381

    
382
            private Circle_PointOrRadius(String name, int id)
383
            {
384
                super (name, id);
385
            }
386

    
387
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY, InputEvent event)
388
            {
389
                CircleCADTool ctxt = context.getOwner();
390

    
391

    
392
                (context.getState()).Exit(context);
393
                context.clearState();
394
                try
395
                {
396
                    ctxt.addPoint(pointX, pointY, event);
397
                    ctxt.end();
398
                }
399
                finally
400
                {
401
                    context.setState(Circle.CenterPointOr3p);
402
                    (context.getState()).Entry(context);
403
                }
404
                return;
405
            }
406

    
407
            protected void addValue(CircleCADToolContext context, double d)
408
            {
409
                CircleCADTool ctxt = context.getOwner();
410

    
411

    
412
                (context.getState()).Exit(context);
413
                context.clearState();
414
                try
415
                {
416
                    ctxt.addValue(d);
417
                    ctxt.end();
418
                }
419
                finally
420
                {
421
                    context.setState(Circle.CenterPointOr3p);
422
                    (context.getState()).Entry(context);
423
                }
424
                return;
425
            }
426

    
427
        //-------------------------------------------------------
428
        // Member data.
429
        //
430
        }
431

    
432
        private static final class Circle_SecondPoint
433
            extends Circle_Default
434
        {
435
        //-------------------------------------------------------
436
        // Member methods.
437
        //
438

    
439
            private Circle_SecondPoint(String name, int id)
440
            {
441
                super (name, id);
442
            }
443

    
444
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY, InputEvent event)
445
            {
446
                CircleCADTool ctxt = context.getOwner();
447

    
448

    
449
                (context.getState()).Exit(context);
450
                context.clearState();
451
                try
452
                {
453
                    ctxt.setQuestion(PluginServices.getText(this,"insert_third_point"));
454
                    ctxt.setDescription(new String[]{"cancel"});
455
                    ctxt.addPoint(pointX, pointY, event);
456
                }
457
                finally
458
                {
459
                    context.setState(Circle.ThirdPoint);
460
                    (context.getState()).Entry(context);
461
                }
462
                return;
463
            }
464

    
465
        //-------------------------------------------------------
466
        // Member data.
467
        //
468
        }
469

    
470
        private static final class Circle_ThirdPoint
471
            extends Circle_Default
472
        {
473
        //-------------------------------------------------------
474
        // Member methods.
475
        //
476

    
477
            private Circle_ThirdPoint(String name, int id)
478
            {
479
                super (name, id);
480
            }
481

    
482
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY, InputEvent event)
483
            {
484
                CircleCADTool ctxt = context.getOwner();
485

    
486

    
487
                (context.getState()).Exit(context);
488
                context.clearState();
489
                try
490
                {
491
                    ctxt.addPoint(pointX, pointY, event);
492
                    ctxt.end();
493
                }
494
                finally
495
                {
496
                    context.setState(Circle.CenterPointOr3p);
497
                    (context.getState()).Entry(context);
498
                }
499
                return;
500
            }
501

    
502
        //-------------------------------------------------------
503
        // Member data.
504
        //
505
        }
506

    
507
        private static final class Circle_FirstPoint
508
            extends Circle_Default
509
        {
510
        //-------------------------------------------------------
511
        // Member methods.
512
        //
513

    
514
            private Circle_FirstPoint(String name, int id)
515
            {
516
                super (name, id);
517
            }
518

    
519
            protected void addPoint(CircleCADToolContext context, double pointX, double pointY, InputEvent event)
520
            {
521
                CircleCADTool ctxt = context.getOwner();
522

    
523

    
524
                (context.getState()).Exit(context);
525
                context.clearState();
526
                try
527
                {
528
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
529
                    ctxt.setDescription(new String[]{"cancel"});
530
                    ctxt.addPoint(pointX, pointY, event);
531
                }
532
                finally
533
                {
534
                    context.setState(Circle.SecondPoint);
535
                    (context.getState()).Entry(context);
536
                }
537
                return;
538
            }
539

    
540
        //-------------------------------------------------------
541
        // Member data.
542
        //
543
        }
544

    
545
    //-----------------------------------------------------------
546
    // Member data.
547
    //
548
    }
549
}