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

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

    
36

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

    
44
    public LineCADToolContext(LineCADTool owner)
45
    {
46
        super();
47

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

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

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

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

    
98
    transient private LineCADTool _owner;
99

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

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

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

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

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

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

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

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

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

    
159
        //-------------------------------------------------------
160
        // Statics.
161
        //
162
        /* package */ static Line_Default.Line_FirstPoint FirstPoint;
163
        /* package */ static Line_Default.Line_SecondPointOrAngle SecondPointOrAngle;
164
        /* package */ static Line_Default.Line_LenghtOrPoint LenghtOrPoint;
165
        private static Line_Default Default;
166

    
167
        static
168
        {
169
            FirstPoint = new Line_Default.Line_FirstPoint("Line.FirstPoint", 0);
170
            SecondPointOrAngle = new Line_Default.Line_SecondPointOrAngle("Line.SecondPointOrAngle", 1);
171
            LenghtOrPoint = new Line_Default.Line_LenghtOrPoint("Line.LenghtOrPoint", 2);
172
            Default = new Line_Default("Line.Default", -1);
173
        }
174

    
175
    }
176

    
177
    protected static class Line_Default
178
        extends LineCADToolState
179
    {
180
    //-----------------------------------------------------------
181
    // Member methods.
182
    //
183

    
184
        protected Line_Default(String name, int id)
185
        {
186
            super (name, id);
187
        }
188

    
189
        protected void addOption(LineCADToolContext context, String s)
190
        {
191
            LineCADTool ctxt = context.getOwner();
192

    
193
            if (s.equals(PluginServices.getText(this,"cancel")))
194
            {
195
                boolean loopbackFlag =
196
                    context.getState().getName().equals(
197
                        Line.FirstPoint.getName());
198

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

    
204
                context.clearState();
205
                try
206
                {
207
                    ctxt.end();
208
                }
209
                finally
210
                {
211
                    context.setState(Line.FirstPoint);
212

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

    
218
                }
219
            }
220
            else if (s.equals(""))
221
            {
222
                boolean loopbackFlag =
223
                    context.getState().getName().equals(
224
                        Line.FirstPoint.getName());
225

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

    
231
                context.clearState();
232
                try
233
                {
234
                    ctxt.end();
235
                }
236
                finally
237
                {
238
                    context.setState(Line.FirstPoint);
239

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

    
245
                }
246
            }
247
            else
248
            {
249
                boolean loopbackFlag =
250
                    context.getState().getName().equals(
251
                        Line.FirstPoint.getName());
252

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

    
258
                context.clearState();
259
                try
260
                {
261
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
262
                }
263
                finally
264
                {
265
                    context.setState(Line.FirstPoint);
266

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

    
272
                }
273
            }
274

    
275
            return;
276
        }
277

    
278
        protected void addValue(LineCADToolContext context, double d)
279
        {
280
            LineCADTool ctxt = context.getOwner();
281

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

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

    
291
            context.clearState();
292
            try
293
            {
294
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
295
            }
296
            finally
297
            {
298
                context.setState(Line.FirstPoint);
299

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

    
305
            }
306
            return;
307
        }
308

    
309
        protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
310
        {
311
            LineCADTool ctxt = context.getOwner();
312

    
313
            boolean loopbackFlag =
314
                context.getState().getName().equals(
315
                    Line.FirstPoint.getName());
316

    
317
            if (loopbackFlag == false)
318
            {
319
                (context.getState()).Exit(context);
320
            }
321

    
322
            context.clearState();
323
            try
324
            {
325
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
326
            }
327
            finally
328
            {
329
                context.setState(Line.FirstPoint);
330

    
331
                if (loopbackFlag == false)
332
                {
333
                    (context.getState()).Entry(context);
334
                }
335

    
336
            }
337
            return;
338
        }
339

    
340
    //-----------------------------------------------------------
341
    // Inner classse.
342
    //
343

    
344

    
345
        private static final class Line_FirstPoint
346
            extends Line_Default
347
        {
348
        //-------------------------------------------------------
349
        // Member methods.
350
        //
351

    
352
            private Line_FirstPoint(String name, int id)
353
            {
354
                super (name, id);
355
            }
356

    
357
            protected void Entry(LineCADToolContext context)
358
            {
359
                LineCADTool ctxt = context.getOwner();
360

    
361
                ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
362
                ctxt.setDescription(new String[]{"cancel"});
363
                return;
364
            }
365

    
366
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
367
            {
368
                LineCADTool ctxt = context.getOwner();
369

    
370

    
371
                (context.getState()).Exit(context);
372
                context.clearState();
373
                try
374
                {
375
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
376
                    ctxt.setDescription(new String[]{"cancel"});
377
                    ctxt.addPoint(pointX, pointY, event);
378
                }
379
                finally
380
                {
381
                    context.setState(Line.SecondPointOrAngle);
382
                    (context.getState()).Entry(context);
383
                }
384
                return;
385
            }
386

    
387
        //-------------------------------------------------------
388
        // Member data.
389
        //
390
        }
391

    
392
        private static final class Line_SecondPointOrAngle
393
            extends Line_Default
394
        {
395
        //-------------------------------------------------------
396
        // Member methods.
397
        //
398

    
399
            private Line_SecondPointOrAngle(String name, int id)
400
            {
401
                super (name, id);
402
            }
403

    
404
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
405
            {
406
                LineCADTool ctxt = context.getOwner();
407

    
408
                LineCADToolState endState = context.getState();
409

    
410
                context.clearState();
411
                try
412
                {
413
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
414
                    ctxt.setDescription(new String[]{"cancel"});
415
                    ctxt.addPoint(pointX, pointY, event);
416
                }
417
                finally
418
                {
419
                    context.setState(endState);
420
                }
421
                return;
422
            }
423

    
424
            protected void addValue(LineCADToolContext context, double d)
425
            {
426
                LineCADTool ctxt = context.getOwner();
427

    
428

    
429
                (context.getState()).Exit(context);
430
                context.clearState();
431
                try
432
                {
433
                    ctxt.setQuestion(PluginServices.getText(this,"insert_length_or_point"));
434
                    ctxt.setDescription(new String[]{"cancel"});
435
                    ctxt.addValue(d);
436
                }
437
                finally
438
                {
439
                    context.setState(Line.LenghtOrPoint);
440
                    (context.getState()).Entry(context);
441
                }
442
                return;
443
            }
444

    
445
        //-------------------------------------------------------
446
        // Member data.
447
        //
448
        }
449

    
450
        private static final class Line_LenghtOrPoint
451
            extends Line_Default
452
        {
453
        //-------------------------------------------------------
454
        // Member methods.
455
        //
456

    
457
            private Line_LenghtOrPoint(String name, int id)
458
            {
459
                super (name, id);
460
            }
461

    
462
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
463
            {
464
                LineCADTool ctxt = context.getOwner();
465

    
466

    
467
                (context.getState()).Exit(context);
468
                context.clearState();
469
                try
470
                {
471
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
472
                    ctxt.setDescription(new String[]{"cancel"});
473
                    ctxt.addPoint(pointX, pointY, event);
474
                }
475
                finally
476
                {
477
                    context.setState(Line.SecondPointOrAngle);
478
                    (context.getState()).Entry(context);
479
                }
480
                return;
481
            }
482

    
483
            protected void addValue(LineCADToolContext context, double d)
484
            {
485
                LineCADTool ctxt = context.getOwner();
486

    
487

    
488
                (context.getState()).Exit(context);
489
                context.clearState();
490
                try
491
                {
492
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point_angle"));
493
                    ctxt.setDescription(new String[]{"cancel"});
494
                    ctxt.addValue(d);
495
                }
496
                finally
497
                {
498
                    context.setState(Line.SecondPointOrAngle);
499
                    (context.getState()).Entry(context);
500
                }
501
                return;
502
            }
503

    
504
        //-------------------------------------------------------
505
        // Member data.
506
        //
507
        }
508

    
509
    //-----------------------------------------------------------
510
    // Member data.
511
    //
512
    }
513
}