Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / smc / BreakCADToolContext.java @ 29616

History | View | Annotate | Download (13.1 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

    
6
package org.gvsig.editing.gui.cad.tools.smc;
7

    
8
import java.awt.event.InputEvent;
9

    
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.editing.gui.cad.tools.BreakCADTool;
12

    
13

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

    
21
    public BreakCADToolContext(BreakCADTool owner)
22
    {
23
        super();
24

    
25
        _owner = owner;
26
        setState(Break.FirstPoint);
27
        Break.FirstPoint.Entry(this);
28
    }
29

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

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

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

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

    
63
        return ((BreakCADToolState) _state);
64
    }
65

    
66
    protected BreakCADTool getOwner()
67
    {
68
        return (_owner);
69
    }
70

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

    
75
    transient private BreakCADTool _owner;
76

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

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

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

    
93
        protected void Entry(BreakCADToolContext context) {}
94
        protected void Exit(BreakCADToolContext context) {}
95

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

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

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

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

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

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

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

    
136
        //-------------------------------------------------------
137
        // Statics.
138
        //
139
        /* package */ static Break_Default.Break_FirstPoint FirstPoint;
140
        /* package */ static Break_Default.Break_SecondPoint SecondPoint;
141
        private static Break_Default Default;
142

    
143
        static
144
        {
145
            FirstPoint = new Break_Default.Break_FirstPoint("Break.FirstPoint", 0);
146
            SecondPoint = new Break_Default.Break_SecondPoint("Break.SecondPoint", 1);
147
            Default = new Break_Default("Break.Default", -1);
148
        }
149

    
150
    }
151

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

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

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

    
168
            if (s.equals(PluginServices.getText(this,"cancel")))
169
            {
170
                boolean loopbackFlag =
171
                    context.getState().getName().equals(
172
                        Break.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(Break.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
                        Break.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(Break.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(BreakCADToolContext context, double d)
227
        {
228
            BreakCADTool ctxt = context.getOwner();
229

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

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

    
253
            }
254
            return;
255
        }
256

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

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

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

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

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

    
315
            protected void addOption(BreakCADToolContext context, String s)
316
            {
317
                BreakCADTool ctxt = context.getOwner();
318

    
319
                BreakCADToolState endState = context.getState();
320

    
321
                context.clearState();
322
                try
323
                {
324
                    ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
325
                    ctxt.setDescription(new String[]{"cancel"});
326
                    ctxt.addOption(s);
327
                }
328
                finally
329
                {
330
                    context.setState(endState);
331
                }
332
                return;
333
            }
334

    
335
            protected void addPoint(BreakCADToolContext context, double pointX, double pointY, InputEvent event)
336
            {
337
                BreakCADTool ctxt = context.getOwner();
338

    
339
                if (ctxt.intersects(pointX,pointY))
340
                {
341

    
342
                    (context.getState()).Exit(context);
343
                    context.clearState();
344
                    try
345
                    {
346
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
347
                        ctxt.setDescription(new String[]{"cancel"});
348
                        ctxt.addPoint(pointX, pointY, event);
349
                    }
350
                    finally
351
                    {
352
                        context.setState(Break.SecondPoint);
353
                        (context.getState()).Entry(context);
354
                    }
355
                }
356
                else if (!ctxt.intersects(pointX,pointY))
357
                {
358
                    BreakCADToolState endState = context.getState();
359

    
360
                    context.clearState();
361
                    try
362
                    {
363
                        ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
364
                        ctxt.setDescription(new String[]{"cancel"});
365
                    }
366
                    finally
367
                    {
368
                        context.setState(endState);
369
                    }
370
                }                else
371
                {
372
                    super.addPoint(context, pointX, pointY, event);
373
                }
374

    
375
                return;
376
            }
377

    
378
        //-------------------------------------------------------
379
        // Member data.
380
        //
381
        }
382

    
383
        private static final class Break_SecondPoint
384
            extends Break_Default
385
        {
386
        //-------------------------------------------------------
387
        // Member methods.
388
        //
389

    
390
            private Break_SecondPoint(String name, int id)
391
            {
392
                super (name, id);
393
            }
394

    
395
            protected void addOption(BreakCADToolContext context, String s)
396
            {
397
                BreakCADTool ctxt = context.getOwner();
398

    
399

    
400
                (context.getState()).Exit(context);
401
                context.clearState();
402
                try
403
                {
404
                    ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
405
                    ctxt.setDescription(new String[]{"cancel"});
406
                    ctxt.addOption(s);
407
                }
408
                finally
409
                {
410
                    context.setState(Break.FirstPoint);
411
                    (context.getState()).Entry(context);
412
                }
413
                return;
414
            }
415

    
416
            protected void addPoint(BreakCADToolContext context, double pointX, double pointY, InputEvent event)
417
            {
418
                BreakCADTool ctxt = context.getOwner();
419

    
420
                if (ctxt.intersects(pointX,pointY))
421
                {
422

    
423
                    (context.getState()).Exit(context);
424
                    context.clearState();
425
                    try
426
                    {
427
                        ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
428
                        ctxt.setDescription(new String[]{"cancel"});
429
                        ctxt.addPoint(pointX, pointY, event);
430
                        ctxt.end();
431
                    }
432
                    finally
433
                    {
434
                        context.setState(Break.FirstPoint);
435
                        (context.getState()).Entry(context);
436
                    }
437
                }
438
                else if (!ctxt.intersects(pointX,pointY))
439
                {
440
                    BreakCADToolState endState = context.getState();
441

    
442
                    context.clearState();
443
                    try
444
                    {
445
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
446
                        ctxt.setDescription(new String[]{"cancel"});
447
                    }
448
                    finally
449
                    {
450
                        context.setState(endState);
451
                    }
452
                }                else
453
                {
454
                    super.addPoint(context, pointX, pointY, event);
455
                }
456

    
457
                return;
458
            }
459

    
460
        //-------------------------------------------------------
461
        // Member data.
462
        //
463
        }
464

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