Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / com / iver / cit / gvsig / gui / cad / tools / smc / LineCADToolContext.java @ 26069

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

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

    
20
    public LineCADToolContext(LineCADTool owner)
21
    {
22
        super();
23

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

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

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

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

    
74
    transient private LineCADTool _owner;
75

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

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

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

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

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

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

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

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

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

    
135
        //-------------------------------------------------------
136
        // Statics.
137
        //
138
        /* package */ static Line_Default.Line_FirstPoint FirstPoint;
139
        /* package */ static Line_Default.Line_SecondPointOrAngle SecondPointOrAngle;
140
        /* package */ static Line_Default.Line_LenghtOrPoint LenghtOrPoint;
141
        private static Line_Default Default;
142

    
143
        static
144
        {
145
            FirstPoint = new Line_Default.Line_FirstPoint("Line.FirstPoint", 0);
146
            SecondPointOrAngle = new Line_Default.Line_SecondPointOrAngle("Line.SecondPointOrAngle", 1);
147
            LenghtOrPoint = new Line_Default.Line_LenghtOrPoint("Line.LenghtOrPoint", 2);
148
            Default = new Line_Default("Line.Default", -1);
149
        }
150

    
151
    }
152

    
153
    protected static class Line_Default
154
        extends LineCADToolState
155
    {
156
    //-----------------------------------------------------------
157
    // Member methods.
158
    //
159

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

    
165
        protected void addOption(LineCADToolContext context, String s)
166
        {
167
            LineCADTool ctxt = context.getOwner();
168

    
169
            if (s.equals(PluginServices.getText(this,"cancel")))
170
            {
171
                boolean loopbackFlag =
172
                    context.getState().getName().equals(
173
                        Line.FirstPoint.getName());
174

    
175
                if (loopbackFlag == false)
176
                {
177
                    (context.getState()).Exit(context);
178
                }
179

    
180
                context.clearState();
181
                try
182
                {
183
                    ctxt.end();
184
                }
185
                finally
186
                {
187
                    context.setState(Line.FirstPoint);
188

    
189
                    if (loopbackFlag == false)
190
                    {
191
                        (context.getState()).Entry(context);
192
                    }
193

    
194
                }
195
            }
196
            else if (s.equals(""))
197
            {
198
                boolean loopbackFlag =
199
                    context.getState().getName().equals(
200
                        Line.FirstPoint.getName());
201

    
202
                if (loopbackFlag == false)
203
                {
204
                    (context.getState()).Exit(context);
205
                }
206

    
207
                context.clearState();
208
                try
209
                {
210
                    ctxt.end();
211
                }
212
                finally
213
                {
214
                    context.setState(Line.FirstPoint);
215

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

    
221
                }
222
            }
223
            else
224
            {
225
                boolean loopbackFlag =
226
                    context.getState().getName().equals(
227
                        Line.FirstPoint.getName());
228

    
229
                if (loopbackFlag == false)
230
                {
231
                    (context.getState()).Exit(context);
232
                }
233

    
234
                context.clearState();
235
                try
236
                {
237
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
238
                }
239
                finally
240
                {
241
                    context.setState(Line.FirstPoint);
242

    
243
                    if (loopbackFlag == false)
244
                    {
245
                        (context.getState()).Entry(context);
246
                    }
247

    
248
                }
249
            }
250

    
251
            return;
252
        }
253

    
254
        protected void addValue(LineCADToolContext context, double d)
255
        {
256
            LineCADTool ctxt = context.getOwner();
257

    
258
            boolean loopbackFlag =
259
                context.getState().getName().equals(
260
                    Line.FirstPoint.getName());
261

    
262
            if (loopbackFlag == false)
263
            {
264
                (context.getState()).Exit(context);
265
            }
266

    
267
            context.clearState();
268
            try
269
            {
270
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
271
            }
272
            finally
273
            {
274
                context.setState(Line.FirstPoint);
275

    
276
                if (loopbackFlag == false)
277
                {
278
                    (context.getState()).Entry(context);
279
                }
280

    
281
            }
282
            return;
283
        }
284

    
285
        protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
286
        {
287
            LineCADTool ctxt = context.getOwner();
288

    
289
            boolean loopbackFlag =
290
                context.getState().getName().equals(
291
                    Line.FirstPoint.getName());
292

    
293
            if (loopbackFlag == false)
294
            {
295
                (context.getState()).Exit(context);
296
            }
297

    
298
            context.clearState();
299
            try
300
            {
301
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
302
            }
303
            finally
304
            {
305
                context.setState(Line.FirstPoint);
306

    
307
                if (loopbackFlag == false)
308
                {
309
                    (context.getState()).Entry(context);
310
                }
311

    
312
            }
313
            return;
314
        }
315

    
316
    //-----------------------------------------------------------
317
    // Inner classse.
318
    //
319

    
320

    
321
        private static final class Line_FirstPoint
322
            extends Line_Default
323
        {
324
        //-------------------------------------------------------
325
        // Member methods.
326
        //
327

    
328
            private Line_FirstPoint(String name, int id)
329
            {
330
                super (name, id);
331
            }
332

    
333
            protected void Entry(LineCADToolContext context)
334
            {
335
                LineCADTool ctxt = context.getOwner();
336

    
337
                ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
338
                ctxt.setDescription(new String[]{"cancel"});
339
                return;
340
            }
341

    
342
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
343
            {
344
                LineCADTool ctxt = context.getOwner();
345

    
346

    
347
                (context.getState()).Exit(context);
348
                context.clearState();
349
                try
350
                {
351
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
352
                    ctxt.setDescription(new String[]{"cancel"});
353
                    ctxt.addPoint(pointX, pointY, event);
354
                }
355
                finally
356
                {
357
                    context.setState(Line.SecondPointOrAngle);
358
                    (context.getState()).Entry(context);
359
                }
360
                return;
361
            }
362

    
363
        //-------------------------------------------------------
364
        // Member data.
365
        //
366
        }
367

    
368
        private static final class Line_SecondPointOrAngle
369
            extends Line_Default
370
        {
371
        //-------------------------------------------------------
372
        // Member methods.
373
        //
374

    
375
            private Line_SecondPointOrAngle(String name, int id)
376
            {
377
                super (name, id);
378
            }
379

    
380
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
381
            {
382
                LineCADTool ctxt = context.getOwner();
383

    
384
                LineCADToolState endState = context.getState();
385

    
386
                context.clearState();
387
                try
388
                {
389
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
390
                    ctxt.setDescription(new String[]{"cancel"});
391
                    ctxt.addPoint(pointX, pointY, event);
392
                }
393
                finally
394
                {
395
                    context.setState(endState);
396
                }
397
                return;
398
            }
399

    
400
            protected void addValue(LineCADToolContext context, double d)
401
            {
402
                LineCADTool ctxt = context.getOwner();
403

    
404

    
405
                (context.getState()).Exit(context);
406
                context.clearState();
407
                try
408
                {
409
                    ctxt.setQuestion(PluginServices.getText(this,"insert_length_or_point"));
410
                    ctxt.setDescription(new String[]{"cancel"});
411
                    ctxt.addValue(d);
412
                }
413
                finally
414
                {
415
                    context.setState(Line.LenghtOrPoint);
416
                    (context.getState()).Entry(context);
417
                }
418
                return;
419
            }
420

    
421
        //-------------------------------------------------------
422
        // Member data.
423
        //
424
        }
425

    
426
        private static final class Line_LenghtOrPoint
427
            extends Line_Default
428
        {
429
        //-------------------------------------------------------
430
        // Member methods.
431
        //
432

    
433
            private Line_LenghtOrPoint(String name, int id)
434
            {
435
                super (name, id);
436
            }
437

    
438
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
439
            {
440
                LineCADTool ctxt = context.getOwner();
441

    
442

    
443
                (context.getState()).Exit(context);
444
                context.clearState();
445
                try
446
                {
447
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
448
                    ctxt.setDescription(new String[]{"cancel"});
449
                    ctxt.addPoint(pointX, pointY, event);
450
                }
451
                finally
452
                {
453
                    context.setState(Line.SecondPointOrAngle);
454
                    (context.getState()).Entry(context);
455
                }
456
                return;
457
            }
458

    
459
            protected void addValue(LineCADToolContext context, double d)
460
            {
461
                LineCADTool ctxt = context.getOwner();
462

    
463

    
464
                (context.getState()).Exit(context);
465
                context.clearState();
466
                try
467
                {
468
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
469
                    ctxt.setDescription(new String[]{"cancel"});
470
                    ctxt.addValue(d);
471
                }
472
                finally
473
                {
474
                    context.setState(Line.SecondPointOrAngle);
475
                    (context.getState()).Entry(context);
476
                }
477
                return;
478
            }
479

    
480
        //-------------------------------------------------------
481
        // Member data.
482
        //
483
        }
484

    
485
    //-----------------------------------------------------------
486
    // Member data.
487
    //
488
    }
489
}