Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / RectangleCADToolContext.java @ 9121

History | View | Annotate | Download (12.8 KB)

1

    
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.RectangleCADTool;
9
import java.awt.event.InputEvent;
10
import com.iver.andami.PluginServices;
11

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

    
19
    public RectangleCADToolContext(RectangleCADTool owner)
20
    {
21
        super();
22

    
23
        _owner = owner;
24
        setState(Rectangle.FirstPoint);
25
        Rectangle.FirstPoint.Entry(this);
26
    }
27

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

    
36
    public void addPoint(double pointX, double pointY, InputEvent event)
37
    {
38
        _transition = "addPoint";
39
        getState().addPoint(this, pointX, pointY, event);
40
        _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 RectangleCADToolState getState()
53
        throws statemap.StateUndefinedException
54
    {
55
        if (_state == null)
56
        {
57
            throw(
58
                new statemap.StateUndefinedException());
59
        }
60

    
61
        return ((RectangleCADToolState) _state);
62
    }
63

    
64
    protected RectangleCADTool getOwner()
65
    {
66
        return (_owner);
67
    }
68

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

    
73
    transient private RectangleCADTool _owner;
74

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

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

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

    
91
        protected void Entry(RectangleCADToolContext context) {}
92
        protected void Exit(RectangleCADToolContext context) {}
93

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

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

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

    
109
        protected void Default(RectangleCADToolContext 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
    /* package */ static abstract class Rectangle
125
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129

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

    
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137
        /* package */ static Rectangle_Default.Rectangle_FirstPoint FirstPoint;
138
        /* package */ static Rectangle_Default.Rectangle_SecondPointOrSquare SecondPointOrSquare;
139
        /* package */ static Rectangle_Default.Rectangle_SecondPointSquare SecondPointSquare;
140
        private static Rectangle_Default Default;
141

    
142
        static
143
        {
144
            FirstPoint = new Rectangle_Default.Rectangle_FirstPoint("Rectangle.FirstPoint", 0);
145
            SecondPointOrSquare = new Rectangle_Default.Rectangle_SecondPointOrSquare("Rectangle.SecondPointOrSquare", 1);
146
            SecondPointSquare = new Rectangle_Default.Rectangle_SecondPointSquare("Rectangle.SecondPointSquare", 2);
147
            Default = new Rectangle_Default("Rectangle.Default", -1);
148
        }
149

    
150
    }
151

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

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

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

    
168
            if (s.equals(PluginServices.getText(this,"cancel")))
169
            {
170
                boolean loopbackFlag =
171
                    context.getState().getName().equals(
172
                        Rectangle.FirstPoint.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(Rectangle.FirstPoint);
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
                        Rectangle.FirstPoint.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(Rectangle.FirstPoint);
214

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

    
220
                }
221
            }
222

    
223
            return;
224
        }
225

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

    
230
            boolean loopbackFlag =
231
                context.getState().getName().equals(
232
                    Rectangle.FirstPoint.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(Rectangle.FirstPoint);
247

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

    
253
            }
254
            return;
255
        }
256

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

    
261
            boolean loopbackFlag =
262
                context.getState().getName().equals(
263
                    Rectangle.FirstPoint.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(Rectangle.FirstPoint);
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 Rectangle_FirstPoint
294
            extends Rectangle_Default
295
        {
296
        //-------------------------------------------------------
297
        // Member methods.
298
        //
299

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

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

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

    
314
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event)
315
            {
316
                RectangleCADTool ctxt = context.getOwner();
317

    
318

    
319
                (context.getState()).Exit(context);
320
                context.clearState();
321
                try
322
                {
323
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_corner")+" "+
324
                                        PluginServices.getText(this,"cad.or")+" "+
325
                                        PluginServices.getText(this,"square")+" "+
326
                                        "["+PluginServices.getText(this,"RectangleCADTool.square")+"]");
327
                    ctxt.setDescription(new String[]{"square", "cancel"});
328
                    ctxt.addPoint(pointX, pointY, event);
329
                }
330
                finally
331
                {
332
                    context.setState(Rectangle.SecondPointOrSquare);
333
                    (context.getState()).Entry(context);
334
                }
335
                return;
336
            }
337

    
338
        //-------------------------------------------------------
339
        // Member data.
340
        //
341
        }
342

    
343
        private static final class Rectangle_SecondPointOrSquare
344
            extends Rectangle_Default
345
        {
346
        //-------------------------------------------------------
347
        // Member methods.
348
        //
349

    
350
            private Rectangle_SecondPointOrSquare(String name, int id)
351
            {
352
                super (name, id);
353
            }
354

    
355
            protected void addOption(RectangleCADToolContext context, String s)
356
            {
357
                RectangleCADTool ctxt = context.getOwner();
358

    
359
                if (s.equalsIgnoreCase(PluginServices.getText(this,"RectangleCADTool.square")) || s.equals(PluginServices.getText(this,"square")))
360
                {
361

    
362
                    (context.getState()).Exit(context);
363
                    context.clearState();
364
                    try
365
                    {
366
                        ctxt.setQuestion(PluginServices.getText(this,"insert_opposited_corner"));
367
                        ctxt.setDescription(new String[]{"cancel"});
368
                        ctxt.addOption(s);
369
                    }
370
                    finally
371
                    {
372
                        context.setState(Rectangle.SecondPointSquare);
373
                        (context.getState()).Entry(context);
374
                    }
375
                }
376
                else
377
                {
378
                    super.addOption(context, s);
379
                }
380

    
381
                return;
382
            }
383

    
384
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event)
385
            {
386
                RectangleCADTool ctxt = context.getOwner();
387

    
388

    
389
                (context.getState()).Exit(context);
390
                context.clearState();
391
                try
392
                {
393
                    ctxt.addPoint(pointX, pointY, event);
394
                    ctxt.end();
395
                }
396
                finally
397
                {
398
                    context.setState(Rectangle.FirstPoint);
399
                    (context.getState()).Entry(context);
400
                }
401
                return;
402
            }
403

    
404
        //-------------------------------------------------------
405
        // Member data.
406
        //
407
        }
408

    
409
        private static final class Rectangle_SecondPointSquare
410
            extends Rectangle_Default
411
        {
412
        //-------------------------------------------------------
413
        // Member methods.
414
        //
415

    
416
            private Rectangle_SecondPointSquare(String name, int id)
417
            {
418
                super (name, id);
419
            }
420

    
421
            protected void addPoint(RectangleCADToolContext context, double pointX, double pointY, InputEvent event)
422
            {
423
                RectangleCADTool ctxt = context.getOwner();
424

    
425

    
426
                (context.getState()).Exit(context);
427
                context.clearState();
428
                try
429
                {
430
                    ctxt.addPoint(pointX, pointY, event);
431
                    ctxt.end();
432
                }
433
                finally
434
                {
435
                    context.setState(Rectangle.FirstPoint);
436
                    (context.getState()).Entry(context);
437
                }
438
                return;
439
            }
440

    
441
        //-------------------------------------------------------
442
        // Member data.
443
        //
444
        }
445

    
446
    //-----------------------------------------------------------
447
    // Member data.
448
    //
449
    }
450
}