Statistics
| Revision:

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

History | View | Annotate | Download (12.8 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 org.gvsig.editing.gui.cad.tools.smc;
10

    
11
import java.awt.event.InputEvent;
12

    
13
import org.gvsig.andami.PluginServices;
14
import org.gvsig.editing.gui.cad.tools.SplitGeometryCADTool;
15

    
16

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

    
24
    public SplitGeometryCADToolContext(SplitGeometryCADTool owner)
25
    {
26
        super();
27

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

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

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

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

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

    
66
        return ((SplitGeometryCADToolState) _state);
67
    }
68

    
69
    protected SplitGeometryCADTool getOwner()
70
    {
71
        return (_owner);
72
    }
73

    
74
//---------------------------------------------------------------
75
// Member data.
76
//
77

    
78
    transient private SplitGeometryCADTool _owner;
79

    
80
//---------------------------------------------------------------
81
// Inner classes.
82
//
83

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

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

    
96
        protected void Entry(SplitGeometryCADToolContext context) {}
97
        protected void Exit(SplitGeometryCADToolContext context) {}
98

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

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

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

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

    
124
    //-----------------------------------------------------------
125
    // Member data.
126
    //
127
    }
128

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

    
135
    //-----------------------------------------------------------
136
    // Member data.
137
    //
138

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

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

    
153
    }
154

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
253
                }
254
            }
255

    
256
            return;
257
        }
258

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

    
263
            boolean loopbackFlag =
264
                context.getState().getName().equals(
265
                    SplitGeometry.FirstPoint.getName());
266

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

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

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

    
286
            }
287
            return;
288
        }
289

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

    
294
            boolean loopbackFlag =
295
                context.getState().getName().equals(
296
                    SplitGeometry.FirstPoint.getName());
297

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

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

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

    
317
            }
318
            return;
319
        }
320

    
321
    //-----------------------------------------------------------
322
    // Inner classse.
323
    //
324

    
325

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

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

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

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

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

    
351

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

    
368
        //-------------------------------------------------------
369
        // Member data.
370
        //
371
        }
372

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

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

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

    
389
                if (s.equalsIgnoreCase(PluginServices.getText(this,"SplitGeometryCADTool.end")) || s.equalsIgnoreCase(PluginServices.getText(this,"terminate")))
390
                {
391

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

    
411
                return;
412
            }
413

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

    
418
                SplitGeometryCADToolState endState = context.getState();
419

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

    
437
        //-------------------------------------------------------
438
        // Member data.
439
        //
440
        }
441

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