Statistics
| Revision:

svn-gvsig-desktop / tags / v1_9_Build_1223 / extensions / extTopology / sm / SplitGeometryCADToolContext.java @ 43637

History | View | Annotate | Download (12.7 KB)

1

    
2
/**
3
 Finite state machine, generated with fsm tool
4
 (http://smc.sourceforge.net)
5
 @author Alvaro Zabala
6
*/
7

    
8

    
9
package com.iver.cit.gvsig.cad.sm;
10

    
11
import com.iver.cit.gvsig.cad.SplitGeometryCADTool;
12
import java.awt.event.InputEvent;
13
import com.iver.andami.PluginServices;
14

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

    
22
    public SplitGeometryCADToolContext(SplitGeometryCADTool owner)
23
    {
24
        super();
25

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

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

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

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

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

    
64
        return ((SplitGeometryCADToolState) _state);
65
    }
66

    
67
    protected SplitGeometryCADTool getOwner()
68
    {
69
        return (_owner);
70
    }
71

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

    
76
    transient private SplitGeometryCADTool _owner;
77

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

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

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

    
94
        protected void Entry(SplitGeometryCADToolContext context) {}
95
        protected void Exit(SplitGeometryCADToolContext context) {}
96

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

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

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

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

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

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

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

    
137
        //-------------------------------------------------------
138
        // Statics.
139
        //
140
        /* package */ static SplitGeometry_Default.SplitGeometry_FirstPoint FirstPoint;
141
        /* package */ static SplitGeometry_Default.SplitGeometry_DigitizingLine DigitizingLine;
142
        private static SplitGeometry_Default Default;
143

    
144
        static
145
        {
146
            FirstPoint = new SplitGeometry_Default.SplitGeometry_FirstPoint("SplitGeometry.FirstPoint", 0);
147
            DigitizingLine = new SplitGeometry_Default.SplitGeometry_DigitizingLine("SplitGeometry.DigitizingLine", 1);
148
            Default = new SplitGeometry_Default("SplitGeometry.Default", -1);
149
        }
150

    
151
    }
152

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

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

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

    
169
            if (s.equals(""))
170
            {
171
                boolean loopbackFlag =
172
                    context.getState().getName().equals(
173
                        SplitGeometry.FirstPoint.getName());
174

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

    
180
                context.clearState();
181
                try
182
                {
183
                    ctxt.restorePreviousTool();
184
                    ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
185
                    ctxt.setDescription(new String[]{"cancel"});
186
                    ctxt.end();
187
                }
188
                finally
189
                {
190
                    context.setState(SplitGeometry.FirstPoint);
191

    
192
                    if (loopbackFlag == false)
193
                    {
194
                        (context.getState()).Entry(context);
195
                    }
196

    
197
                }
198
            }
199
            else if (s.equals(PluginServices.getText(this,"cancel")))
200
            {
201
                boolean loopbackFlag =
202
                    context.getState().getName().equals(
203
                        SplitGeometry.FirstPoint.getName());
204

    
205
                if (loopbackFlag == false)
206
                {
207
                    (context.getState()).Exit(context);
208
                }
209

    
210
                context.clearState();
211
                try
212
                {
213
                    ctxt.end();
214
                }
215
                finally
216
                {
217
                    context.setState(SplitGeometry.FirstPoint);
218

    
219
                    if (loopbackFlag == false)
220
                    {
221
                        (context.getState()).Entry(context);
222
                    }
223

    
224
                }
225
            }
226
            else
227
            {
228
                boolean loopbackFlag =
229
                    context.getState().getName().equals(
230
                        SplitGeometry.FirstPoint.getName());
231

    
232
                if (loopbackFlag == false)
233
                {
234
                    (context.getState()).Exit(context);
235
                }
236

    
237
                context.clearState();
238
                try
239
                {
240
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
241
                }
242
                finally
243
                {
244
                    context.setState(SplitGeometry.FirstPoint);
245

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

    
251
                }
252
            }
253

    
254
            return;
255
        }
256

    
257
        protected void addValue(SplitGeometryCADToolContext context, double d)
258
        {
259
            SplitGeometryCADTool ctxt = context.getOwner();
260

    
261
            boolean loopbackFlag =
262
                context.getState().getName().equals(
263
                    SplitGeometry.FirstPoint.getName());
264

    
265
            if (loopbackFlag == false)
266
            {
267
                (context.getState()).Exit(context);
268
            }
269

    
270
            context.clearState();
271
            try
272
            {
273
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
274
            }
275
            finally
276
            {
277
                context.setState(SplitGeometry.FirstPoint);
278

    
279
                if (loopbackFlag == false)
280
                {
281
                    (context.getState()).Entry(context);
282
                }
283

    
284
            }
285
            return;
286
        }
287

    
288
        protected void addPoint(SplitGeometryCADToolContext context, double pointX, double pointY, InputEvent event)
289
        {
290
            SplitGeometryCADTool ctxt = context.getOwner();
291

    
292
            boolean loopbackFlag =
293
                context.getState().getName().equals(
294
                    SplitGeometry.FirstPoint.getName());
295

    
296
            if (loopbackFlag == false)
297
            {
298
                (context.getState()).Exit(context);
299
            }
300

    
301
            context.clearState();
302
            try
303
            {
304
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
305
            }
306
            finally
307
            {
308
                context.setState(SplitGeometry.FirstPoint);
309

    
310
                if (loopbackFlag == false)
311
                {
312
                    (context.getState()).Entry(context);
313
                }
314

    
315
            }
316
            return;
317
        }
318

    
319
    //-----------------------------------------------------------
320
    // Inner classse.
321
    //
322

    
323

    
324
        private static final class SplitGeometry_FirstPoint
325
            extends SplitGeometry_Default
326
        {
327
        //-------------------------------------------------------
328
        // Member methods.
329
        //
330

    
331
            private SplitGeometry_FirstPoint(String name, int id)
332
            {
333
                super (name, id);
334
            }
335

    
336
            protected void Entry(SplitGeometryCADToolContext context)
337
            {
338
                SplitGeometryCADTool ctxt = context.getOwner();
339

    
340
                ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
341
                ctxt.setDescription(new String[]{"cancel"});
342
                return;
343
            }
344

    
345
            protected void addPoint(SplitGeometryCADToolContext context, double pointX, double pointY, InputEvent event)
346
            {
347
                SplitGeometryCADTool ctxt = context.getOwner();
348

    
349

    
350
                (context.getState()).Exit(context);
351
                context.clearState();
352
                try
353
                {
354
                    ctxt.setQuestion(PluginServices.getText(this,"insert_more_points_or_finish"));
355
                    ctxt.setDescription(new String[]{"cancel"});
356
                    ctxt.addPoint(pointX, pointY, event);
357
                }
358
                finally
359
                {
360
                    context.setState(SplitGeometry.DigitizingLine);
361
                    (context.getState()).Entry(context);
362
                }
363
                return;
364
            }
365

    
366
        //-------------------------------------------------------
367
        // Member data.
368
        //
369
        }
370

    
371
        private static final class SplitGeometry_DigitizingLine
372
            extends SplitGeometry_Default
373
        {
374
        //-------------------------------------------------------
375
        // Member methods.
376
        //
377

    
378
            private SplitGeometry_DigitizingLine(String name, int id)
379
            {
380
                super (name, id);
381
            }
382

    
383
            protected void addOption(SplitGeometryCADToolContext context, String s)
384
            {
385
                SplitGeometryCADTool ctxt = context.getOwner();
386

    
387
                if (s.equalsIgnoreCase(PluginServices.getText(this,"PolylineCADTool.end"))))
388
                {
389

    
390
                    (context.getState()).Exit(context);
391
                    context.clearState();
392
                    try
393
                    {
394
                        ctxt.finishDigitizedLine();
395
                        ctxt.splitSelectedGeometryWithDigitizedLine();
396
                        ctxt.end();
397
                    }
398
                    finally
399
                    {
400
                        context.setState(SplitGeometry.FirstPoint);
401
                        (context.getState()).Entry(context);
402
                    }
403
                }
404
                else
405
                {
406
                    super.addOption(context, s);
407
                }
408

    
409
                return;
410
            }
411

    
412
            protected void addPoint(SplitGeometryCADToolContext context, double pointX, double pointY, InputEvent event)
413
            {
414
                SplitGeometryCADTool ctxt = context.getOwner();
415

    
416
                SplitGeometryCADToolState endState = context.getState();
417

    
418
                context.clearState();
419
                try
420
                {
421
                    ctxt.setQuestion(PluginServices.getText(this,"insert_next_point")+
422
                                PluginServices.getText(this,"cad.or")+" "+
423
                                PluginServices.getText(this,"end")+
424
                                "["+PluginServices.getText(this,"PolylineCADTool.end")+"]");
425
                    ctxt.setDescription(new String[]{"inter_arc", "terminate", "cancel"});
426
                    ctxt.addPoint(pointX, pointY, event);
427
                }
428
                finally
429
                {
430
                    context.setState(endState);
431
                }
432
                return;
433
            }
434

    
435
        //-------------------------------------------------------
436
        // Member data.
437
        //
438
        }
439

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