Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_905 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / ArcCADToolContext.java @ 10767

History | View | Annotate | Download (11.2 KB)

1 3782 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.ArcCADTool;
9 4324 caballero
import java.awt.event.InputEvent;
10 4584 caballero
import com.iver.andami.PluginServices;
11 3782 caballero
12
public final class ArcCADToolContext
13
    extends statemap.FSMContext
14
{
15
//---------------------------------------------------------------
16
// Member methods.
17
//
18
19
    public ArcCADToolContext(ArcCADTool owner)
20
    {
21
        super();
22
23
        _owner = owner;
24 3978 caballero
        setState(Arc.FirstPoint);
25
        Arc.FirstPoint.Entry(this);
26 3782 caballero
    }
27
28 3883 caballero
    public void addOption(String s)
29
    {
30
        _transition = "addOption";
31
        getState().addOption(this, s);
32
        _transition = "";
33
        return;
34
    }
35
36 4324 caballero
    public void addPoint(double pointX, double pointY, InputEvent event)
37 3782 caballero
    {
38
        _transition = "addPoint";
39 4324 caballero
        getState().addPoint(this, pointX, pointY, event);
40 3782 caballero
        _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 3782 caballero
    public ArcCADToolState getState()
53
        throws statemap.StateUndefinedException
54
    {
55
        if (_state == null)
56
        {
57
            throw(
58
                new statemap.StateUndefinedException());
59
        }
60
61
        return ((ArcCADToolState) _state);
62
    }
63
64
    protected ArcCADTool getOwner()
65
    {
66
        return (_owner);
67
    }
68
69
//---------------------------------------------------------------
70
// Member data.
71
//
72
73
    transient private ArcCADTool _owner;
74
75
//---------------------------------------------------------------
76
// Inner classes.
77
//
78
79
    public static abstract class ArcCADToolState
80
        extends statemap.State
81
    {
82
    //-----------------------------------------------------------
83
    // Member methods.
84
    //
85
86
        protected ArcCADToolState(String name, int id)
87
        {
88
            super (name, id);
89
        }
90
91
        protected void Entry(ArcCADToolContext context) {}
92
        protected void Exit(ArcCADToolContext context) {}
93
94 3883 caballero
        protected void addOption(ArcCADToolContext context, String s)
95
        {
96
            Default(context);
97
        }
98
99 4324 caballero
        protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
100 3782 caballero
        {
101
            Default(context);
102
        }
103
104 5735 caballero
        protected void addValue(ArcCADToolContext context, double d)
105
        {
106
            Default(context);
107
        }
108
109 3782 caballero
        protected void Default(ArcCADToolContext 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 3978 caballero
    /* package */ static abstract class Arc
125 3782 caballero
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129
130
    //-----------------------------------------------------------
131
    // Member data.
132
    //
133
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137 3978 caballero
        /* package */ static Arc_Default.Arc_FirstPoint FirstPoint;
138
        /* package */ static Arc_Default.Arc_SecondPoint SecondPoint;
139
        /* package */ static Arc_Default.Arc_ThirdPoint ThirdPoint;
140
        private static Arc_Default Default;
141 3782 caballero
142
        static
143
        {
144 3978 caballero
            FirstPoint = new Arc_Default.Arc_FirstPoint("Arc.FirstPoint", 0);
145
            SecondPoint = new Arc_Default.Arc_SecondPoint("Arc.SecondPoint", 1);
146
            ThirdPoint = new Arc_Default.Arc_ThirdPoint("Arc.ThirdPoint", 2);
147
            Default = new Arc_Default("Arc.Default", -1);
148 3782 caballero
        }
149
150
    }
151
152 3978 caballero
    protected static class Arc_Default
153 3782 caballero
        extends ArcCADToolState
154
    {
155
    //-----------------------------------------------------------
156
    // Member methods.
157
    //
158
159 3978 caballero
        protected Arc_Default(String name, int id)
160 3782 caballero
        {
161
            super (name, id);
162
        }
163
164 3883 caballero
        protected void addOption(ArcCADToolContext context, String s)
165
        {
166
            ArcCADTool ctxt = context.getOwner();
167
168 4584 caballero
            if (s.equals(PluginServices.getText(this,"cancel")))
169 3883 caballero
            {
170
                boolean loopbackFlag =
171
                    context.getState().getName().equals(
172 3978 caballero
                        Arc.FirstPoint.getName());
173 3883 caballero
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 3978 caballero
                    context.setState(Arc.FirstPoint);
187 3883 caballero
188
                    if (loopbackFlag == false)
189
                    {
190
                        (context.getState()).Entry(context);
191
                    }
192
193
                }
194
            }
195
            else
196
            {
197 5735 caballero
                boolean loopbackFlag =
198
                    context.getState().getName().equals(
199
                        Arc.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(Arc.FirstPoint);
214
215
                    if (loopbackFlag == false)
216
                    {
217
                        (context.getState()).Entry(context);
218
                    }
219
220
                }
221 3883 caballero
            }
222
223
            return;
224
        }
225
226 5735 caballero
        protected void addValue(ArcCADToolContext context, double d)
227
        {
228
            ArcCADTool ctxt = context.getOwner();
229
230
            boolean loopbackFlag =
231
                context.getState().getName().equals(
232
                    Arc.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(Arc.FirstPoint);
247
248
                if (loopbackFlag == false)
249
                {
250
                    (context.getState()).Entry(context);
251
                }
252
253
            }
254
            return;
255
        }
256
257
        protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
258
        {
259
            ArcCADTool ctxt = context.getOwner();
260
261
            boolean loopbackFlag =
262
                context.getState().getName().equals(
263
                    Arc.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(Arc.FirstPoint);
278
279
                if (loopbackFlag == false)
280
                {
281
                    (context.getState()).Entry(context);
282
                }
283
284
            }
285
            return;
286
        }
287
288 3782 caballero
    //-----------------------------------------------------------
289
    // Inner classse.
290
    //
291
292
293 3978 caballero
        private static final class Arc_FirstPoint
294
            extends Arc_Default
295 3782 caballero
        {
296
        //-------------------------------------------------------
297
        // Member methods.
298
        //
299
300 3978 caballero
            private Arc_FirstPoint(String name, int id)
301 3782 caballero
            {
302
                super (name, id);
303
            }
304
305
            protected void Entry(ArcCADToolContext context)
306
            {
307
                ArcCADTool ctxt = context.getOwner();
308
309 4892 caballero
                ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
310 4584 caballero
                ctxt.setDescription(new String[]{"cancel"});
311 3782 caballero
                return;
312
            }
313
314 4324 caballero
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
315 3782 caballero
            {
316
                ArcCADTool ctxt = context.getOwner();
317
318
319
                (context.getState()).Exit(context);
320
                context.clearState();
321
                try
322
                {
323 4584 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
324
                    ctxt.setDescription(new String[]{"cancel"});
325 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
326 3782 caballero
                }
327
                finally
328
                {
329 3978 caballero
                    context.setState(Arc.SecondPoint);
330 3782 caballero
                    (context.getState()).Entry(context);
331
                }
332
                return;
333
            }
334
335
        //-------------------------------------------------------
336
        // Member data.
337
        //
338
        }
339
340 3978 caballero
        private static final class Arc_SecondPoint
341
            extends Arc_Default
342 3782 caballero
        {
343
        //-------------------------------------------------------
344
        // Member methods.
345
        //
346
347 3978 caballero
            private Arc_SecondPoint(String name, int id)
348 3782 caballero
            {
349
                super (name, id);
350
            }
351
352 4324 caballero
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
353 3782 caballero
            {
354
                ArcCADTool ctxt = context.getOwner();
355
356
357
                (context.getState()).Exit(context);
358
                context.clearState();
359
                try
360
                {
361 4584 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"insert_last_point"));
362
                    ctxt.setDescription(new String[]{"cancel"});
363 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
364 3782 caballero
                }
365
                finally
366
                {
367 3978 caballero
                    context.setState(Arc.ThirdPoint);
368 3782 caballero
                    (context.getState()).Entry(context);
369
                }
370
                return;
371
            }
372
373
        //-------------------------------------------------------
374
        // Member data.
375
        //
376
        }
377
378 3978 caballero
        private static final class Arc_ThirdPoint
379
            extends Arc_Default
380 3782 caballero
        {
381
        //-------------------------------------------------------
382
        // Member methods.
383
        //
384
385 3978 caballero
            private Arc_ThirdPoint(String name, int id)
386 3782 caballero
            {
387
                super (name, id);
388
            }
389
390 4324 caballero
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
391 3782 caballero
            {
392
                ArcCADTool ctxt = context.getOwner();
393
394
395
                (context.getState()).Exit(context);
396
                context.clearState();
397
                try
398
                {
399 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
400 3782 caballero
                    ctxt.end();
401
                }
402
                finally
403
                {
404 3978 caballero
                    context.setState(Arc.FirstPoint);
405 3782 caballero
                    (context.getState()).Entry(context);
406
                }
407
                return;
408
            }
409
410
        //-------------------------------------------------------
411
        // Member data.
412
        //
413
        }
414
415
    //-----------------------------------------------------------
416
    // Member data.
417
    //
418
    }
419
}