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 / RotateCADToolContext.java @ 40557

History | View | Annotate | Download (11.8 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.RotateCADTool;
35

    
36

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

    
44
    public RotateCADToolContext(RotateCADTool owner)
45
    {
46
        super();
47

    
48
        _owner = owner;
49
        setState(Rotate.PointMain);
50
        Rotate.PointMain.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 RotateCADToolState getState()
78
        throws statemap.StateUndefinedException
79
    {
80
        if (_state == null)
81
        {
82
            throw(
83
                new statemap.StateUndefinedException());
84
        }
85

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

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

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

    
98
    transient private RotateCADTool _owner;
99

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

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

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

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

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

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

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

    
134
        protected void Default(RotateCADToolContext 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 Rotate
150
    {
151
    //-----------------------------------------------------------
152
    // Member methods.
153
    //
154

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

    
159
        //-------------------------------------------------------
160
        // Statics.
161
        //
162
        /* package */ static Rotate_Default.Rotate_PointMain PointMain;
163
        /* package */ static Rotate_Default.Rotate_AngleOrPoint AngleOrPoint;
164
        private static Rotate_Default Default;
165

    
166
        static
167
        {
168
            PointMain = new Rotate_Default.Rotate_PointMain("Rotate.PointMain", 0);
169
            AngleOrPoint = new Rotate_Default.Rotate_AngleOrPoint("Rotate.AngleOrPoint", 1);
170
            Default = new Rotate_Default("Rotate.Default", -1);
171
        }
172

    
173
    }
174

    
175
    protected static class Rotate_Default
176
        extends RotateCADToolState
177
    {
178
    //-----------------------------------------------------------
179
    // Member methods.
180
    //
181

    
182
        protected Rotate_Default(String name, int id)
183
        {
184
            super (name, id);
185
        }
186

    
187
        protected void addOption(RotateCADToolContext context, String s)
188
        {
189
            RotateCADTool ctxt = context.getOwner();
190

    
191
            if (s.equals(PluginServices.getText(this,"cancel")))
192
            {
193
                boolean loopbackFlag =
194
                    context.getState().getName().equals(
195
                        Rotate.PointMain.getName());
196

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

    
202
                context.clearState();
203
                try
204
                {
205
                    ctxt.end();
206
                }
207
                finally
208
                {
209
                    context.setState(Rotate.PointMain);
210

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

    
216
                }
217
            }
218
            else
219
            {
220
                boolean loopbackFlag =
221
                    context.getState().getName().equals(
222
                        Rotate.PointMain.getName());
223

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

    
229
                context.clearState();
230
                try
231
                {
232
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
233
                }
234
                finally
235
                {
236
                    context.setState(Rotate.PointMain);
237

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

    
243
                }
244
            }
245

    
246
            return;
247
        }
248

    
249
        protected void addValue(RotateCADToolContext context, double d)
250
        {
251
            RotateCADTool ctxt = context.getOwner();
252

    
253
            boolean loopbackFlag =
254
                context.getState().getName().equals(
255
                    Rotate.PointMain.getName());
256

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

    
262
            context.clearState();
263
            try
264
            {
265
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
266
            }
267
            finally
268
            {
269
                context.setState(Rotate.PointMain);
270

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

    
276
            }
277
            return;
278
        }
279

    
280
        protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
281
        {
282
            RotateCADTool ctxt = context.getOwner();
283

    
284
            boolean loopbackFlag =
285
                context.getState().getName().equals(
286
                    Rotate.PointMain.getName());
287

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

    
293
            context.clearState();
294
            try
295
            {
296
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
297
            }
298
            finally
299
            {
300
                context.setState(Rotate.PointMain);
301

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

    
307
            }
308
            return;
309
        }
310

    
311
    //-----------------------------------------------------------
312
    // Inner classse.
313
    //
314

    
315

    
316
        private static final class Rotate_PointMain
317
            extends Rotate_Default
318
        {
319
        //-------------------------------------------------------
320
        // Member methods.
321
        //
322

    
323
            private Rotate_PointMain(String name, int id)
324
            {
325
                super (name, id);
326
            }
327

    
328
            protected void Entry(RotateCADToolContext context)
329
            {
330
                RotateCADTool ctxt = context.getOwner();
331

    
332
                ctxt.selection();
333
                ctxt.setQuestion(PluginServices.getText(this,"insert_basis_point"));
334
                ctxt.setDescription(new String[]{"cancel"});
335
                return;
336
            }
337

    
338
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
339
            {
340
                RotateCADTool ctxt = context.getOwner();
341

    
342

    
343
                (context.getState()).Exit(context);
344
                context.clearState();
345
                try
346
                {
347
                    ctxt.setQuestion(PluginServices.getText(this,"insert_rotation_angle"));
348
                    ctxt.setDescription(new String[]{"cancel"});
349
                    ctxt.addPoint(pointX, pointY, event);
350
                }
351
                finally
352
                {
353
                    context.setState(Rotate.AngleOrPoint);
354
                    (context.getState()).Entry(context);
355
                }
356
                return;
357
            }
358

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

    
364
        private static final class Rotate_AngleOrPoint
365
            extends Rotate_Default
366
        {
367
        //-------------------------------------------------------
368
        // Member methods.
369
        //
370

    
371
            private Rotate_AngleOrPoint(String name, int id)
372
            {
373
                super (name, id);
374
            }
375

    
376
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
377
            {
378
                RotateCADTool ctxt = context.getOwner();
379

    
380

    
381
                (context.getState()).Exit(context);
382
                context.clearState();
383
                try
384
                {
385
                    ctxt.setDescription(new String[]{"cancel"});
386
                    ctxt.addPoint(pointX, pointY, event);
387
                    ctxt.end();
388
                    ctxt.refresh();
389
                }
390
                finally
391
                {
392
                    context.setState(Rotate.PointMain);
393
                    (context.getState()).Entry(context);
394
                }
395
                return;
396
            }
397

    
398
            protected void addValue(RotateCADToolContext context, double d)
399
            {
400
                RotateCADTool ctxt = context.getOwner();
401

    
402

    
403
                (context.getState()).Exit(context);
404
                context.clearState();
405
                try
406
                {
407
                    ctxt.setDescription(new String[]{"cancel"});
408
                    ctxt.addValue(d);
409
                    ctxt.end();
410
                    ctxt.refresh();
411
                }
412
                finally
413
                {
414
                    context.setState(Rotate.PointMain);
415
                    (context.getState()).Entry(context);
416
                }
417
                return;
418
            }
419

    
420
        //-------------------------------------------------------
421
        // Member data.
422
        //
423
        }
424

    
425
    //-----------------------------------------------------------
426
    // Member data.
427
    //
428
    }
429
}