Statistics
| Revision:

root / tags / v1_0_2_Build_916 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / BreakCADToolContext.java @ 12327

History | View | Annotate | Download (13.1 KB)

1 5388 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.BreakCADTool;
9
import java.awt.event.InputEvent;
10
import com.iver.andami.PluginServices;
11
12
public final class BreakCADToolContext
13
    extends statemap.FSMContext
14
{
15
//---------------------------------------------------------------
16
// Member methods.
17
//
18
19
    public BreakCADToolContext(BreakCADTool owner)
20
    {
21
        super();
22
23
        _owner = owner;
24
        setState(Break.FirstPoint);
25
        Break.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 5735 caballero
    public void addValue(double d)
45
    {
46
        _transition = "addValue";
47
        getState().addValue(this, d);
48
        _transition = "";
49
        return;
50
    }
51
52 5388 caballero
    public BreakCADToolState getState()
53
        throws statemap.StateUndefinedException
54
    {
55
        if (_state == null)
56
        {
57
            throw(
58
                new statemap.StateUndefinedException());
59
        }
60
61
        return ((BreakCADToolState) _state);
62
    }
63
64
    protected BreakCADTool getOwner()
65
    {
66
        return (_owner);
67
    }
68
69
//---------------------------------------------------------------
70
// Member data.
71
//
72
73
    transient private BreakCADTool _owner;
74
75
//---------------------------------------------------------------
76
// Inner classes.
77
//
78
79
    public static abstract class BreakCADToolState
80
        extends statemap.State
81
    {
82
    //-----------------------------------------------------------
83
    // Member methods.
84
    //
85
86
        protected BreakCADToolState(String name, int id)
87
        {
88
            super (name, id);
89
        }
90
91
        protected void Entry(BreakCADToolContext context) {}
92
        protected void Exit(BreakCADToolContext context) {}
93
94
        protected void addOption(BreakCADToolContext context, String s)
95
        {
96
            Default(context);
97
        }
98
99
        protected void addPoint(BreakCADToolContext context, double pointX, double pointY, InputEvent event)
100
        {
101
            Default(context);
102
        }
103
104 5735 caballero
        protected void addValue(BreakCADToolContext context, double d)
105
        {
106
            Default(context);
107
        }
108
109 5388 caballero
        protected void Default(BreakCADToolContext 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 Break
125
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129
130
    //-----------------------------------------------------------
131
    // Member data.
132
    //
133
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137
        /* package */ static Break_Default.Break_FirstPoint FirstPoint;
138
        /* package */ static Break_Default.Break_SecondPoint SecondPoint;
139
        private static Break_Default Default;
140
141
        static
142
        {
143
            FirstPoint = new Break_Default.Break_FirstPoint("Break.FirstPoint", 0);
144
            SecondPoint = new Break_Default.Break_SecondPoint("Break.SecondPoint", 1);
145
            Default = new Break_Default("Break.Default", -1);
146
        }
147
148
    }
149
150
    protected static class Break_Default
151
        extends BreakCADToolState
152
    {
153
    //-----------------------------------------------------------
154
    // Member methods.
155
    //
156
157
        protected Break_Default(String name, int id)
158
        {
159
            super (name, id);
160
        }
161
162
        protected void addOption(BreakCADToolContext context, String s)
163
        {
164
            BreakCADTool ctxt = context.getOwner();
165
166
            if (s.equals(PluginServices.getText(this,"cancel")))
167
            {
168
                boolean loopbackFlag =
169
                    context.getState().getName().equals(
170
                        Break.FirstPoint.getName());
171
172
                if (loopbackFlag == false)
173
                {
174
                    (context.getState()).Exit(context);
175
                }
176
177
                context.clearState();
178
                try
179
                {
180
                    ctxt.end();
181
                }
182
                finally
183
                {
184
                    context.setState(Break.FirstPoint);
185
186
                    if (loopbackFlag == false)
187
                    {
188
                        (context.getState()).Entry(context);
189
                    }
190
191
                }
192
            }
193
            else
194
            {
195 5735 caballero
                boolean loopbackFlag =
196
                    context.getState().getName().equals(
197
                        Break.FirstPoint.getName());
198
199
                if (loopbackFlag == false)
200
                {
201
                    (context.getState()).Exit(context);
202
                }
203
204
                context.clearState();
205
                try
206
                {
207
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
208
                }
209
                finally
210
                {
211
                    context.setState(Break.FirstPoint);
212
213
                    if (loopbackFlag == false)
214
                    {
215
                        (context.getState()).Entry(context);
216
                    }
217
218
                }
219 5388 caballero
            }
220
221
            return;
222
        }
223
224 5735 caballero
        protected void addValue(BreakCADToolContext context, double d)
225
        {
226
            BreakCADTool ctxt = context.getOwner();
227
228
            boolean loopbackFlag =
229
                context.getState().getName().equals(
230
                    Break.FirstPoint.getName());
231
232
            if (loopbackFlag == false)
233
            {
234
                (context.getState()).Exit(context);
235
            }
236
237
            context.clearState();
238
            try
239
            {
240
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
241
            }
242
            finally
243
            {
244
                context.setState(Break.FirstPoint);
245
246
                if (loopbackFlag == false)
247
                {
248
                    (context.getState()).Entry(context);
249
                }
250
251
            }
252
            return;
253
        }
254
255
        protected void addPoint(BreakCADToolContext context, double pointX, double pointY, InputEvent event)
256
        {
257
            BreakCADTool ctxt = context.getOwner();
258
259
            boolean loopbackFlag =
260
                context.getState().getName().equals(
261
                    Break.FirstPoint.getName());
262
263
            if (loopbackFlag == false)
264
            {
265
                (context.getState()).Exit(context);
266
            }
267
268
            context.clearState();
269
            try
270
            {
271
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
272
            }
273
            finally
274
            {
275
                context.setState(Break.FirstPoint);
276
277
                if (loopbackFlag == false)
278
                {
279
                    (context.getState()).Entry(context);
280
                }
281
282
            }
283
            return;
284
        }
285
286 5388 caballero
    //-----------------------------------------------------------
287
    // Inner classse.
288
    //
289
290
291
        private static final class Break_FirstPoint
292
            extends Break_Default
293
        {
294
        //-------------------------------------------------------
295
        // Member methods.
296
        //
297
298
            private Break_FirstPoint(String name, int id)
299
            {
300
                super (name, id);
301
            }
302
303
            protected void Entry(BreakCADToolContext context)
304
            {
305
                BreakCADTool ctxt = context.getOwner();
306
307
                ctxt.selection();
308
                ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
309
                ctxt.setDescription(new String[]{"cancel"});
310
                return;
311
            }
312
313
            protected void addOption(BreakCADToolContext context, String s)
314
            {
315
                BreakCADTool ctxt = context.getOwner();
316
317
                BreakCADToolState endState = context.getState();
318
319
                context.clearState();
320
                try
321
                {
322
                    ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
323
                    ctxt.setDescription(new String[]{"cancel"});
324
                    ctxt.addOption(s);
325
                }
326
                finally
327
                {
328
                    context.setState(endState);
329
                }
330
                return;
331
            }
332
333
            protected void addPoint(BreakCADToolContext context, double pointX, double pointY, InputEvent event)
334
            {
335
                BreakCADTool ctxt = context.getOwner();
336
337
                if (ctxt.intersects(pointX,pointY))
338
                {
339
340
                    (context.getState()).Exit(context);
341
                    context.clearState();
342
                    try
343
                    {
344
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
345
                        ctxt.setDescription(new String[]{"cancel"});
346
                        ctxt.addPoint(pointX, pointY, event);
347
                    }
348
                    finally
349
                    {
350
                        context.setState(Break.SecondPoint);
351
                        (context.getState()).Entry(context);
352
                    }
353
                }
354
                else if (!ctxt.intersects(pointX,pointY))
355
                {
356
                    BreakCADToolState endState = context.getState();
357
358
                    context.clearState();
359
                    try
360
                    {
361
                        ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
362
                        ctxt.setDescription(new String[]{"cancel"});
363
                    }
364
                    finally
365
                    {
366
                        context.setState(endState);
367
                    }
368
                }                else
369
                {
370
                    super.addPoint(context, pointX, pointY, event);
371
                }
372
373
                return;
374
            }
375
376
        //-------------------------------------------------------
377
        // Member data.
378
        //
379
        }
380
381
        private static final class Break_SecondPoint
382
            extends Break_Default
383
        {
384
        //-------------------------------------------------------
385
        // Member methods.
386
        //
387
388
            private Break_SecondPoint(String name, int id)
389
            {
390
                super (name, id);
391
            }
392
393
            protected void addOption(BreakCADToolContext context, String s)
394
            {
395
                BreakCADTool ctxt = context.getOwner();
396
397
398
                (context.getState()).Exit(context);
399
                context.clearState();
400
                try
401
                {
402
                    ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
403
                    ctxt.setDescription(new String[]{"cancel"});
404
                    ctxt.addOption(s);
405
                }
406
                finally
407
                {
408
                    context.setState(Break.FirstPoint);
409
                    (context.getState()).Entry(context);
410
                }
411
                return;
412
            }
413
414
            protected void addPoint(BreakCADToolContext context, double pointX, double pointY, InputEvent event)
415
            {
416
                BreakCADTool ctxt = context.getOwner();
417
418
                if (ctxt.intersects(pointX,pointY))
419
                {
420
421
                    (context.getState()).Exit(context);
422
                    context.clearState();
423
                    try
424
                    {
425
                        ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
426
                        ctxt.setDescription(new String[]{"cancel"});
427
                        ctxt.addPoint(pointX, pointY, event);
428
                        ctxt.end();
429
                    }
430
                    finally
431
                    {
432
                        context.setState(Break.FirstPoint);
433
                        (context.getState()).Entry(context);
434
                    }
435
                }
436
                else if (!ctxt.intersects(pointX,pointY))
437
                {
438
                    BreakCADToolState endState = context.getState();
439
440
                    context.clearState();
441
                    try
442
                    {
443
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
444
                        ctxt.setDescription(new String[]{"cancel"});
445
                    }
446
                    finally
447
                    {
448
                        context.setState(endState);
449
                    }
450
                }                else
451
                {
452
                    super.addPoint(context, pointX, pointY, event);
453
                }
454
455
                return;
456
            }
457
458
        //-------------------------------------------------------
459
        // Member data.
460
        //
461
        }
462
463
    //-----------------------------------------------------------
464
    // Member data.
465
    //
466
    }
467
}