Statistics
| Revision:

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

History | View | Annotate | Download (11.2 KB)

1

    
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
import java.awt.event.InputEvent;
10
import com.iver.andami.PluginServices;
11

    
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
        setState(Arc.FirstPoint);
25
        Arc.FirstPoint.Entry(this);
26
    }
27

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

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

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

    
52
    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
        protected void addOption(ArcCADToolContext context, String s)
95
        {
96
            Default(context);
97
        }
98

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

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

    
109
        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
    /* package */ static abstract class Arc
125
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129

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

    
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137
        /* 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

    
142
        static
143
        {
144
            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
        }
149

    
150
    }
151

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

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

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

    
168
            if (s.equals(PluginServices.getText(this,"cancel")))
169
            {
170
                boolean loopbackFlag =
171
                    context.getState().getName().equals(
172
                        Arc.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(Arc.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
                        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
            }
222

    
223
            return;
224
        }
225

    
226
        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
    //-----------------------------------------------------------
289
    // Inner classse.
290
    //
291

    
292

    
293
        private static final class Arc_FirstPoint
294
            extends Arc_Default
295
        {
296
        //-------------------------------------------------------
297
        // Member methods.
298
        //
299

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

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

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

    
314
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
315
            {
316
                ArcCADTool ctxt = context.getOwner();
317

    
318

    
319
                (context.getState()).Exit(context);
320
                context.clearState();
321
                try
322
                {
323
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
324
                    ctxt.setDescription(new String[]{"cancel"});
325
                    ctxt.addPoint(pointX, pointY, event);
326
                }
327
                finally
328
                {
329
                    context.setState(Arc.SecondPoint);
330
                    (context.getState()).Entry(context);
331
                }
332
                return;
333
            }
334

    
335
        //-------------------------------------------------------
336
        // Member data.
337
        //
338
        }
339

    
340
        private static final class Arc_SecondPoint
341
            extends Arc_Default
342
        {
343
        //-------------------------------------------------------
344
        // Member methods.
345
        //
346

    
347
            private Arc_SecondPoint(String name, int id)
348
            {
349
                super (name, id);
350
            }
351

    
352
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
353
            {
354
                ArcCADTool ctxt = context.getOwner();
355

    
356

    
357
                (context.getState()).Exit(context);
358
                context.clearState();
359
                try
360
                {
361
                    ctxt.setQuestion(PluginServices.getText(this,"insert_last_point"));
362
                    ctxt.setDescription(new String[]{"cancel"});
363
                    ctxt.addPoint(pointX, pointY, event);
364
                }
365
                finally
366
                {
367
                    context.setState(Arc.ThirdPoint);
368
                    (context.getState()).Entry(context);
369
                }
370
                return;
371
            }
372

    
373
        //-------------------------------------------------------
374
        // Member data.
375
        //
376
        }
377

    
378
        private static final class Arc_ThirdPoint
379
            extends Arc_Default
380
        {
381
        //-------------------------------------------------------
382
        // Member methods.
383
        //
384

    
385
            private Arc_ThirdPoint(String name, int id)
386
            {
387
                super (name, id);
388
            }
389

    
390
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
391
            {
392
                ArcCADTool ctxt = context.getOwner();
393

    
394

    
395
                (context.getState()).Exit(context);
396
                context.clearState();
397
                try
398
                {
399
                    ctxt.addPoint(pointX, pointY, event);
400
                    ctxt.end();
401
                }
402
                finally
403
                {
404
                    context.setState(Arc.FirstPoint);
405
                    (context.getState()).Entry(context);
406
                }
407
                return;
408
            }
409

    
410
        //-------------------------------------------------------
411
        // Member data.
412
        //
413
        }
414

    
415
    //-----------------------------------------------------------
416
    // Member data.
417
    //
418
    }
419
}