Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_892 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / PolygonCADToolContext.java @ 10278

History | View | Annotate | Download (16.5 KB)

1 3782 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.PolygonCADTool;
9 4324 caballero
import java.awt.event.InputEvent;
10 4584 caballero
import com.iver.andami.PluginServices;
11 3782 caballero
12
public final class PolygonCADToolContext
13
    extends statemap.FSMContext
14
{
15
//---------------------------------------------------------------
16
// Member methods.
17
//
18
19
    public PolygonCADToolContext(PolygonCADTool owner)
20
    {
21
        super();
22
23
        _owner = owner;
24 3978 caballero
        setState(Polygon.NumberOrCenterPoint);
25
        Polygon.NumberOrCenterPoint.Entry(this);
26 3782 caballero
    }
27
28 3832 caballero
    public void addOption(String s)
29 3782 caballero
    {
30
        _transition = "addOption";
31 3832 caballero
        getState().addOption(this, s);
32 3782 caballero
        _transition = "";
33
        return;
34
    }
35
36 4324 caballero
    public void addPoint(double pointX, double pointY, InputEvent event)
37 3782 caballero
    {
38
        _transition = "addPoint";
39 4324 caballero
        getState().addPoint(this, pointX, pointY, event);
40 3782 caballero
        _transition = "";
41
        return;
42
    }
43
44 3832 caballero
    public void addValue(double d)
45 3782 caballero
    {
46
        _transition = "addValue";
47 3832 caballero
        getState().addValue(this, d);
48 3782 caballero
        _transition = "";
49
        return;
50
    }
51
52
    public PolygonCADToolState getState()
53
        throws statemap.StateUndefinedException
54
    {
55
        if (_state == null)
56
        {
57
            throw(
58
                new statemap.StateUndefinedException());
59
        }
60
61
        return ((PolygonCADToolState) _state);
62
    }
63
64
    protected PolygonCADTool getOwner()
65
    {
66
        return (_owner);
67
    }
68
69
//---------------------------------------------------------------
70
// Member data.
71
//
72
73
    transient private PolygonCADTool _owner;
74
75
//---------------------------------------------------------------
76
// Inner classes.
77
//
78
79
    public static abstract class PolygonCADToolState
80
        extends statemap.State
81
    {
82
    //-----------------------------------------------------------
83
    // Member methods.
84
    //
85
86
        protected PolygonCADToolState(String name, int id)
87
        {
88
            super (name, id);
89
        }
90
91
        protected void Entry(PolygonCADToolContext context) {}
92
        protected void Exit(PolygonCADToolContext context) {}
93
94 3832 caballero
        protected void addOption(PolygonCADToolContext context, String s)
95 3782 caballero
        {
96
            Default(context);
97
        }
98
99 4324 caballero
        protected void addPoint(PolygonCADToolContext context, double pointX, double pointY, InputEvent event)
100 3782 caballero
        {
101
            Default(context);
102
        }
103
104 3832 caballero
        protected void addValue(PolygonCADToolContext context, double d)
105 3782 caballero
        {
106
            Default(context);
107
        }
108
109
        protected void Default(PolygonCADToolContext 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 Polygon
125 3782 caballero
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129
130
    //-----------------------------------------------------------
131
    // Member data.
132
    //
133
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137 3978 caballero
        /* package */ static Polygon_Default.Polygon_NumberOrCenterPoint NumberOrCenterPoint;
138
        /* package */ static Polygon_Default.Polygon_CenterPoint CenterPoint;
139
        /* package */ static Polygon_Default.Polygon_OptionOrRadiusOrPoint OptionOrRadiusOrPoint;
140
        /* package */ static Polygon_Default.Polygon_RadiusOrPoint RadiusOrPoint;
141
        private static Polygon_Default Default;
142 3782 caballero
143
        static
144
        {
145 3978 caballero
            NumberOrCenterPoint = new Polygon_Default.Polygon_NumberOrCenterPoint("Polygon.NumberOrCenterPoint", 0);
146
            CenterPoint = new Polygon_Default.Polygon_CenterPoint("Polygon.CenterPoint", 1);
147
            OptionOrRadiusOrPoint = new Polygon_Default.Polygon_OptionOrRadiusOrPoint("Polygon.OptionOrRadiusOrPoint", 2);
148
            RadiusOrPoint = new Polygon_Default.Polygon_RadiusOrPoint("Polygon.RadiusOrPoint", 3);
149
            Default = new Polygon_Default("Polygon.Default", -1);
150 3782 caballero
        }
151
152
    }
153
154 3978 caballero
    protected static class Polygon_Default
155 3782 caballero
        extends PolygonCADToolState
156
    {
157
    //-----------------------------------------------------------
158
    // Member methods.
159
    //
160
161 3978 caballero
        protected Polygon_Default(String name, int id)
162 3782 caballero
        {
163
            super (name, id);
164
        }
165
166 3883 caballero
        protected void addOption(PolygonCADToolContext context, String s)
167
        {
168
            PolygonCADTool ctxt = context.getOwner();
169
170 4584 caballero
            if (s.equals(PluginServices.getText(this,"cancel")))
171 3883 caballero
            {
172
                boolean loopbackFlag =
173
                    context.getState().getName().equals(
174 3978 caballero
                        Polygon.NumberOrCenterPoint.getName());
175 3883 caballero
176
                if (loopbackFlag == false)
177
                {
178
                    (context.getState()).Exit(context);
179
                }
180
181
                context.clearState();
182
                try
183
                {
184
                    ctxt.end();
185
                }
186
                finally
187
                {
188 3978 caballero
                    context.setState(Polygon.NumberOrCenterPoint);
189 3883 caballero
190
                    if (loopbackFlag == false)
191
                    {
192
                        (context.getState()).Entry(context);
193
                    }
194
195
                }
196
            }
197
            else
198
            {
199 5735 caballero
                boolean loopbackFlag =
200
                    context.getState().getName().equals(
201
                        Polygon.NumberOrCenterPoint.getName());
202
203
                if (loopbackFlag == false)
204
                {
205
                    (context.getState()).Exit(context);
206
                }
207
208
                context.clearState();
209
                try
210
                {
211
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
212
                }
213
                finally
214
                {
215
                    context.setState(Polygon.NumberOrCenterPoint);
216
217
                    if (loopbackFlag == false)
218
                    {
219
                        (context.getState()).Entry(context);
220
                    }
221
222
                }
223 3883 caballero
            }
224
225
            return;
226
        }
227
228 5735 caballero
        protected void addValue(PolygonCADToolContext context, double d)
229
        {
230
            PolygonCADTool ctxt = context.getOwner();
231
232
            boolean loopbackFlag =
233
                context.getState().getName().equals(
234
                    Polygon.NumberOrCenterPoint.getName());
235
236
            if (loopbackFlag == false)
237
            {
238
                (context.getState()).Exit(context);
239
            }
240
241
            context.clearState();
242
            try
243
            {
244
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
245
            }
246
            finally
247
            {
248
                context.setState(Polygon.NumberOrCenterPoint);
249
250
                if (loopbackFlag == false)
251
                {
252
                    (context.getState()).Entry(context);
253
                }
254
255
            }
256
            return;
257
        }
258
259
        protected void addPoint(PolygonCADToolContext context, double pointX, double pointY, InputEvent event)
260
        {
261
            PolygonCADTool ctxt = context.getOwner();
262
263
            boolean loopbackFlag =
264
                context.getState().getName().equals(
265
                    Polygon.NumberOrCenterPoint.getName());
266
267
            if (loopbackFlag == false)
268
            {
269
                (context.getState()).Exit(context);
270
            }
271
272
            context.clearState();
273
            try
274
            {
275
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
276
            }
277
            finally
278
            {
279
                context.setState(Polygon.NumberOrCenterPoint);
280
281
                if (loopbackFlag == false)
282
                {
283
                    (context.getState()).Entry(context);
284
                }
285
286
            }
287
            return;
288
        }
289
290 3782 caballero
    //-----------------------------------------------------------
291
    // Inner classse.
292
    //
293
294
295 3978 caballero
        private static final class Polygon_NumberOrCenterPoint
296
            extends Polygon_Default
297 3782 caballero
        {
298
        //-------------------------------------------------------
299
        // Member methods.
300
        //
301
302 3978 caballero
            private Polygon_NumberOrCenterPoint(String name, int id)
303 3782 caballero
            {
304
                super (name, id);
305
            }
306
307
            protected void Entry(PolygonCADToolContext context)
308
            {
309
                PolygonCADTool ctxt = context.getOwner();
310
311 4892 caballero
                ctxt.setQuestion(PluginServices.getText(this,"insert_number_sides"));
312 4584 caballero
                ctxt.setDescription(new String[]{"cancel"});
313 3782 caballero
                return;
314
            }
315
316 4324 caballero
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY, InputEvent event)
317 3782 caballero
            {
318
                PolygonCADTool ctxt = context.getOwner();
319
320
321
                (context.getState()).Exit(context);
322
                context.clearState();
323
                try
324
                {
325 4584 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"into_circle_or_circumscribed"));
326
                    ctxt.setDescription(new String[]{"into_circle", "circumscribed", "cancel"});
327 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
328 3782 caballero
                }
329
                finally
330
                {
331 3978 caballero
                    context.setState(Polygon.OptionOrRadiusOrPoint);
332 3782 caballero
                    (context.getState()).Entry(context);
333
                }
334
                return;
335
            }
336
337 3832 caballero
            protected void addValue(PolygonCADToolContext context, double d)
338 3782 caballero
            {
339
                PolygonCADTool ctxt = context.getOwner();
340
341 5735 caballero
                if (d<3)
342
                {
343
                    PolygonCADToolState endState = context.getState();
344 3782 caballero
345 5735 caballero
                    context.clearState();
346
                    try
347
                    {
348
                        ctxt.throwValueException(PluginServices.getText(this,"num_lados_insuficiente"), d);
349
                    }
350
                    finally
351
                    {
352
                        context.setState(endState);
353
                    }
354 3782 caballero
                }
355 5735 caballero
                else if (d>2)
356 3782 caballero
                {
357 5735 caballero
358
                    (context.getState()).Exit(context);
359
                    context.clearState();
360
                    try
361
                    {
362
                        ctxt.setQuestion(PluginServices.getText(this,"insert_central_point_polygon"));
363
                        ctxt.setDescription(new String[]{"cancel"});
364
                        ctxt.addValue(d);
365
                    }
366
                    finally
367
                    {
368
                        context.setState(Polygon.CenterPoint);
369
                        (context.getState()).Entry(context);
370
                    }
371
                }                else
372
                {
373
                    super.addValue(context, d);
374 3782 caballero
                }
375 5735 caballero
376 3782 caballero
                return;
377
            }
378
379
        //-------------------------------------------------------
380
        // Member data.
381
        //
382
        }
383
384 3978 caballero
        private static final class Polygon_CenterPoint
385
            extends Polygon_Default
386 3782 caballero
        {
387
        //-------------------------------------------------------
388
        // Member methods.
389
        //
390
391 3978 caballero
            private Polygon_CenterPoint(String name, int id)
392 3782 caballero
            {
393
                super (name, id);
394
            }
395
396 4324 caballero
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY, InputEvent event)
397 3782 caballero
            {
398
                PolygonCADTool ctxt = context.getOwner();
399
400
401
                (context.getState()).Exit(context);
402
                context.clearState();
403
                try
404
                {
405 4584 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"into_circle_or_circumscribed"));
406
                    ctxt.setDescription(new String[]{"into_circle", "circumscribed", "cancel"});
407 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
408 3782 caballero
                }
409
                finally
410
                {
411 3978 caballero
                    context.setState(Polygon.OptionOrRadiusOrPoint);
412 3782 caballero
                    (context.getState()).Entry(context);
413
                }
414
                return;
415
            }
416
417
        //-------------------------------------------------------
418
        // Member data.
419
        //
420
        }
421
422 3978 caballero
        private static final class Polygon_OptionOrRadiusOrPoint
423
            extends Polygon_Default
424 3782 caballero
        {
425
        //-------------------------------------------------------
426
        // Member methods.
427
        //
428
429 3978 caballero
            private Polygon_OptionOrRadiusOrPoint(String name, int id)
430 3782 caballero
            {
431
                super (name, id);
432
            }
433
434 3832 caballero
            protected void addOption(PolygonCADToolContext context, String s)
435 3782 caballero
            {
436
                PolygonCADTool ctxt = context.getOwner();
437
438 9251 caballero
                if (!s.equals(PluginServices.getText(this,"cancel")))
439
                {
440 3782 caballero
441 9251 caballero
                    (context.getState()).Exit(context);
442
                    context.clearState();
443
                    try
444
                    {
445
                        ctxt.setQuestion(PluginServices.getText(this,"insert_radius"));
446
                        ctxt.setDescription(new String[]{"cancel"});
447
                        ctxt.addOption(s);
448
                    }
449
                    finally
450
                    {
451
                        context.setState(Polygon.RadiusOrPoint);
452
                        (context.getState()).Entry(context);
453
                    }
454 3782 caballero
                }
455 9251 caballero
                else
456 3782 caballero
                {
457 9251 caballero
                    super.addOption(context, s);
458 3782 caballero
                }
459 9251 caballero
460 3782 caballero
                return;
461
            }
462
463 4324 caballero
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY, InputEvent event)
464 3782 caballero
            {
465
                PolygonCADTool ctxt = context.getOwner();
466
467
468
                (context.getState()).Exit(context);
469
                context.clearState();
470
                try
471
                {
472 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
473 3782 caballero
                    ctxt.end();
474
                }
475
                finally
476
                {
477 3978 caballero
                    context.setState(Polygon.NumberOrCenterPoint);
478 3782 caballero
                    (context.getState()).Entry(context);
479
                }
480
                return;
481
            }
482
483 3832 caballero
            protected void addValue(PolygonCADToolContext context, double d)
484 3782 caballero
            {
485
                PolygonCADTool ctxt = context.getOwner();
486
487
488
                (context.getState()).Exit(context);
489
                context.clearState();
490
                try
491
                {
492 3832 caballero
                    ctxt.addValue(d);
493 3782 caballero
                    ctxt.end();
494
                }
495
                finally
496
                {
497 3978 caballero
                    context.setState(Polygon.NumberOrCenterPoint);
498 3782 caballero
                    (context.getState()).Entry(context);
499
                }
500
                return;
501
            }
502
503
        //-------------------------------------------------------
504
        // Member data.
505
        //
506
        }
507
508 3978 caballero
        private static final class Polygon_RadiusOrPoint
509
            extends Polygon_Default
510 3782 caballero
        {
511
        //-------------------------------------------------------
512
        // Member methods.
513
        //
514
515 3978 caballero
            private Polygon_RadiusOrPoint(String name, int id)
516 3782 caballero
            {
517
                super (name, id);
518
            }
519
520 4324 caballero
            protected void addPoint(PolygonCADToolContext context, double pointX, double pointY, InputEvent event)
521 3782 caballero
            {
522
                PolygonCADTool ctxt = context.getOwner();
523
524
525
                (context.getState()).Exit(context);
526
                context.clearState();
527
                try
528
                {
529 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
530 3782 caballero
                    ctxt.end();
531
                }
532
                finally
533
                {
534 3978 caballero
                    context.setState(Polygon.NumberOrCenterPoint);
535 3782 caballero
                    (context.getState()).Entry(context);
536
                }
537
                return;
538
            }
539
540 3832 caballero
            protected void addValue(PolygonCADToolContext context, double d)
541 3782 caballero
            {
542
                PolygonCADTool ctxt = context.getOwner();
543
544
545
                (context.getState()).Exit(context);
546
                context.clearState();
547
                try
548
                {
549 3832 caballero
                    ctxt.addValue(d);
550 3782 caballero
                    ctxt.end();
551
                }
552
                finally
553
                {
554 3978 caballero
                    context.setState(Polygon.NumberOrCenterPoint);
555 3782 caballero
                    (context.getState()).Entry(context);
556
                }
557
                return;
558
            }
559
560
        //-------------------------------------------------------
561
        // Member data.
562
        //
563
        }
564
565
    //-----------------------------------------------------------
566
    // Member data.
567
    //
568
    }
569
}