Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / smc / PointCADToolContext.java @ 40557

History | View | Annotate | Download (9.69 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
//
26
// Vicente Caballero Navarro
27

    
28

    
29
package org.gvsig.editing.gui.cad.tools.smc;
30

    
31
import java.awt.event.InputEvent;
32

    
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.editing.gui.cad.tools.PointCADTool;
35

    
36

    
37
public final class PointCADToolContext
38
    extends statemap.FSMContext
39
{
40
//---------------------------------------------------------------
41
// Member methods.
42
//
43

    
44
    public PointCADToolContext(PointCADTool owner)
45
    {
46
        super();
47

    
48
        _owner = owner;
49
        setState(Point.FirstPoint);
50
        Point.FirstPoint.Entry(this);
51
    }
52

    
53
    public void addOption(String s)
54
    {
55
        _transition = "addOption";
56
        getState().addOption(this, s);
57
        _transition = "";
58
        return;
59
    }
60

    
61
    public void addPoint(double pointX, double pointY, InputEvent event)
62
    {
63
        _transition = "addPoint";
64
        getState().addPoint(this, pointX, pointY, event);
65
        _transition = "";
66
        return;
67
    }
68

    
69
    public void addValue(double d)
70
    {
71
        _transition = "addValue";
72
        getState().addValue(this, d);
73
        _transition = "";
74
        return;
75
    }
76

    
77
    public PointCADToolState getState()
78
        throws statemap.StateUndefinedException
79
    {
80
        if (_state == null)
81
        {
82
            throw(
83
                new statemap.StateUndefinedException());
84
        }
85

    
86
        return ((PointCADToolState) _state);
87
    }
88

    
89
    protected PointCADTool getOwner()
90
    {
91
        return (_owner);
92
    }
93

    
94
//---------------------------------------------------------------
95
// Member data.
96
//
97

    
98
    transient private PointCADTool _owner;
99

    
100
//---------------------------------------------------------------
101
// Inner classes.
102
//
103

    
104
    public static abstract class PointCADToolState
105
        extends statemap.State
106
    {
107
    //-----------------------------------------------------------
108
    // Member methods.
109
    //
110

    
111
        protected PointCADToolState(String name, int id)
112
        {
113
            super (name, id);
114
        }
115

    
116
        protected void Entry(PointCADToolContext context) {}
117
        protected void Exit(PointCADToolContext context) {}
118

    
119
        protected void addOption(PointCADToolContext context, String s)
120
        {
121
            Default(context);
122
        }
123

    
124
        protected void addPoint(PointCADToolContext context, double pointX, double pointY, InputEvent event)
125
        {
126
            Default(context);
127
        }
128

    
129
        protected void addValue(PointCADToolContext context, double d)
130
        {
131
            Default(context);
132
        }
133

    
134
        protected void Default(PointCADToolContext context)
135
        {
136
            throw (
137
                new statemap.TransitionUndefinedException(
138
                    "State: " +
139
                    context.getState().getName() +
140
                    ", Transition: " +
141
                    context.getTransition()));
142
        }
143

    
144
    //-----------------------------------------------------------
145
    // Member data.
146
    //
147
    }
148

    
149
    /* package */ static abstract class Point
150
    {
151
    //-----------------------------------------------------------
152
    // Member methods.
153
    //
154

    
155
    //-----------------------------------------------------------
156
    // Member data.
157
    //
158

    
159
        //-------------------------------------------------------
160
        // Statics.
161
        //
162
        /* package */ static Point_Default.Point_FirstPoint FirstPoint;
163
        private static Point_Default Default;
164

    
165
        static
166
        {
167
            FirstPoint = new Point_Default.Point_FirstPoint("Point.FirstPoint", 0);
168
            Default = new Point_Default("Point.Default", -1);
169
        }
170

    
171
    }
172

    
173
    protected static class Point_Default
174
        extends PointCADToolState
175
    {
176
    //-----------------------------------------------------------
177
    // Member methods.
178
    //
179

    
180
        protected Point_Default(String name, int id)
181
        {
182
            super (name, id);
183
        }
184

    
185
        protected void addOption(PointCADToolContext context, String s)
186
        {
187
            PointCADTool ctxt = context.getOwner();
188

    
189
            if (s.equals(PluginServices.getText(this,"cancel")))
190
            {
191
                boolean loopbackFlag =
192
                    context.getState().getName().equals(
193
                        Point.FirstPoint.getName());
194

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

    
200
                context.clearState();
201
                try
202
                {
203
                    ctxt.end();
204
                }
205
                finally
206
                {
207
                    context.setState(Point.FirstPoint);
208

    
209
                    if (loopbackFlag == false)
210
                    {
211
                        (context.getState()).Entry(context);
212
                    }
213

    
214
                }
215
            }
216
            else
217
            {
218
                boolean loopbackFlag =
219
                    context.getState().getName().equals(
220
                        Point.FirstPoint.getName());
221

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

    
227
                context.clearState();
228
                try
229
                {
230
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
231
                }
232
                finally
233
                {
234
                    context.setState(Point.FirstPoint);
235

    
236
                    if (loopbackFlag == false)
237
                    {
238
                        (context.getState()).Entry(context);
239
                    }
240

    
241
                }
242
            }
243

    
244
            return;
245
        }
246

    
247
        protected void addValue(PointCADToolContext context, double d)
248
        {
249
            PointCADTool ctxt = context.getOwner();
250

    
251
            boolean loopbackFlag =
252
                context.getState().getName().equals(
253
                    Point.FirstPoint.getName());
254

    
255
            if (loopbackFlag == false)
256
            {
257
                (context.getState()).Exit(context);
258
            }
259

    
260
            context.clearState();
261
            try
262
            {
263
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
264
            }
265
            finally
266
            {
267
                context.setState(Point.FirstPoint);
268

    
269
                if (loopbackFlag == false)
270
                {
271
                    (context.getState()).Entry(context);
272
                }
273

    
274
            }
275
            return;
276
        }
277

    
278
        protected void addPoint(PointCADToolContext context, double pointX, double pointY, InputEvent event)
279
        {
280
            PointCADTool ctxt = context.getOwner();
281

    
282
            boolean loopbackFlag =
283
                context.getState().getName().equals(
284
                    Point.FirstPoint.getName());
285

    
286
            if (loopbackFlag == false)
287
            {
288
                (context.getState()).Exit(context);
289
            }
290

    
291
            context.clearState();
292
            try
293
            {
294
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
295
            }
296
            finally
297
            {
298
                context.setState(Point.FirstPoint);
299

    
300
                if (loopbackFlag == false)
301
                {
302
                    (context.getState()).Entry(context);
303
                }
304

    
305
            }
306
            return;
307
        }
308

    
309
    //-----------------------------------------------------------
310
    // Inner classse.
311
    //
312

    
313

    
314
        private static final class Point_FirstPoint
315
            extends Point_Default
316
        {
317
        //-------------------------------------------------------
318
        // Member methods.
319
        //
320

    
321
            private Point_FirstPoint(String name, int id)
322
            {
323
                super (name, id);
324
            }
325

    
326
            protected void Entry(PointCADToolContext context)
327
            {
328
                PointCADTool ctxt = context.getOwner();
329

    
330
                ctxt.setQuestion(PluginServices.getText(this,"define_point"));
331
                ctxt.setDescription(new String[]{"cancel"});
332
                return;
333
            }
334

    
335
            protected void addPoint(PointCADToolContext context, double pointX, double pointY, InputEvent event)
336
            {
337
                PointCADTool ctxt = context.getOwner();
338

    
339
                PointCADToolState endState = context.getState();
340

    
341
                context.clearState();
342
                try
343
                {
344
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point"));
345
                    ctxt.setDescription(new String[]{"cancel"});
346
                    ctxt.addPoint(pointX, pointY, event);
347
                }
348
                finally
349
                {
350
                    context.setState(endState);
351
                }
352
                return;
353
            }
354

    
355
        //-------------------------------------------------------
356
        // Member data.
357
        //
358
        }
359

    
360
    //-----------------------------------------------------------
361
    // Member data.
362
    //
363
    }
364
}