Statistics
| Revision:

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

History | View | Annotate | Download (8.73 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

    
6
package org.gvsig.editing.gui.cad.tools.smc;
7

    
8
import java.awt.event.InputEvent;
9

    
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.editing.gui.cad.tools.PointCADTool;
12

    
13

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

    
21
    public PointCADToolContext(PointCADTool owner)
22
    {
23
        super();
24

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

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

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

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

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

    
63
        return ((PointCADToolState) _state);
64
    }
65

    
66
    protected PointCADTool getOwner()
67
    {
68
        return (_owner);
69
    }
70

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

    
75
    transient private PointCADTool _owner;
76

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

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

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

    
93
        protected void Entry(PointCADToolContext context) {}
94
        protected void Exit(PointCADToolContext context) {}
95

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

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

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

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

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

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

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

    
136
        //-------------------------------------------------------
137
        // Statics.
138
        //
139
        /* package */ static Point_Default.Point_FirstPoint FirstPoint;
140
        private static Point_Default Default;
141

    
142
        static
143
        {
144
            FirstPoint = new Point_Default.Point_FirstPoint("Point.FirstPoint", 0);
145
            Default = new Point_Default("Point.Default", -1);
146
        }
147

    
148
    }
149

    
150
    protected static class Point_Default
151
        extends PointCADToolState
152
    {
153
    //-----------------------------------------------------------
154
    // Member methods.
155
    //
156

    
157
        protected Point_Default(String name, int id)
158
        {
159
            super (name, id);
160
        }
161

    
162
        protected void addOption(PointCADToolContext context, String s)
163
        {
164
            PointCADTool ctxt = context.getOwner();
165

    
166
            if (s.equals(PluginServices.getText(this,"cancel")))
167
            {
168
                boolean loopbackFlag =
169
                    context.getState().getName().equals(
170
                        Point.FirstPoint.getName());
171

    
172
                if (loopbackFlag == false)
173
                {
174
                    (context.getState()).Exit(context);
175
                }
176

    
177
                context.clearState();
178
                try
179
                {
180
                    ctxt.end();
181
                }
182
                finally
183
                {
184
                    context.setState(Point.FirstPoint);
185

    
186
                    if (loopbackFlag == false)
187
                    {
188
                        (context.getState()).Entry(context);
189
                    }
190

    
191
                }
192
            }
193
            else
194
            {
195
                boolean loopbackFlag =
196
                    context.getState().getName().equals(
197
                        Point.FirstPoint.getName());
198

    
199
                if (loopbackFlag == false)
200
                {
201
                    (context.getState()).Exit(context);
202
                }
203

    
204
                context.clearState();
205
                try
206
                {
207
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
208
                }
209
                finally
210
                {
211
                    context.setState(Point.FirstPoint);
212

    
213
                    if (loopbackFlag == false)
214
                    {
215
                        (context.getState()).Entry(context);
216
                    }
217

    
218
                }
219
            }
220

    
221
            return;
222
        }
223

    
224
        protected void addValue(PointCADToolContext context, double d)
225
        {
226
            PointCADTool ctxt = context.getOwner();
227

    
228
            boolean loopbackFlag =
229
                context.getState().getName().equals(
230
                    Point.FirstPoint.getName());
231

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

    
237
            context.clearState();
238
            try
239
            {
240
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
241
            }
242
            finally
243
            {
244
                context.setState(Point.FirstPoint);
245

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

    
251
            }
252
            return;
253
        }
254

    
255
        protected void addPoint(PointCADToolContext context, double pointX, double pointY, InputEvent event)
256
        {
257
            PointCADTool ctxt = context.getOwner();
258

    
259
            boolean loopbackFlag =
260
                context.getState().getName().equals(
261
                    Point.FirstPoint.getName());
262

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

    
268
            context.clearState();
269
            try
270
            {
271
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
272
            }
273
            finally
274
            {
275
                context.setState(Point.FirstPoint);
276

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

    
282
            }
283
            return;
284
        }
285

    
286
    //-----------------------------------------------------------
287
    // Inner classse.
288
    //
289

    
290

    
291
        private static final class Point_FirstPoint
292
            extends Point_Default
293
        {
294
        //-------------------------------------------------------
295
        // Member methods.
296
        //
297

    
298
            private Point_FirstPoint(String name, int id)
299
            {
300
                super (name, id);
301
            }
302

    
303
            protected void Entry(PointCADToolContext context)
304
            {
305
                PointCADTool ctxt = context.getOwner();
306

    
307
                ctxt.setQuestion(PluginServices.getText(this,"define_point"));
308
                ctxt.setDescription(new String[]{"cancel"});
309
                return;
310
            }
311

    
312
            protected void addPoint(PointCADToolContext context, double pointX, double pointY, InputEvent event)
313
            {
314
                PointCADTool ctxt = context.getOwner();
315

    
316
                PointCADToolState endState = context.getState();
317

    
318
                context.clearState();
319
                try
320
                {
321
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point"));
322
                    ctxt.setDescription(new String[]{"cancel"});
323
                    ctxt.addPoint(pointX, pointY, event);
324
                }
325
                finally
326
                {
327
                    context.setState(endState);
328
                }
329
                return;
330
            }
331

    
332
        //-------------------------------------------------------
333
        // Member data.
334
        //
335
        }
336

    
337
    //-----------------------------------------------------------
338
    // Member data.
339
    //
340
    }
341
}