Statistics
| Revision:

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

History | View | Annotate | Download (19 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.SelectionCADTool;
12

    
13

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

    
21
    public SelectionCADToolContext(SelectionCADTool owner)
22
    {
23
        super();
24

    
25
        _owner = owner;
26
        setState(Selection.FirstPoint);
27
        Selection.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 SelectionCADToolState getState()
55
        throws statemap.StateUndefinedException
56
    {
57
        if (_state == null)
58
        {
59
            throw(
60
                new statemap.StateUndefinedException());
61
        }
62

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

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

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

    
75
    transient private SelectionCADTool _owner;
76

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

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

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

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

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

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

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

    
111
        protected void Default(SelectionCADToolContext 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 Selection
127
    {
128
    //-----------------------------------------------------------
129
    // Member methods.
130
    //
131

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

    
136
        //-------------------------------------------------------
137
        // Statics.
138
        //
139
        /* package */ static Selection_Default.Selection_FirstPoint FirstPoint;
140
        /* package */ static Selection_Default.Selection_SecondPoint SecondPoint;
141
        /* package */ static Selection_Default.Selection_WithSelectedFeatures WithSelectedFeatures;
142
        /* package */ static Selection_Default.Selection_WithHandlers WithHandlers;
143
        private static Selection_Default Default;
144

    
145
        static
146
        {
147
            FirstPoint = new Selection_Default.Selection_FirstPoint("Selection.FirstPoint", 0);
148
            SecondPoint = new Selection_Default.Selection_SecondPoint("Selection.SecondPoint", 1);
149
            WithSelectedFeatures = new Selection_Default.Selection_WithSelectedFeatures("Selection.WithSelectedFeatures", 2);
150
            WithHandlers = new Selection_Default.Selection_WithHandlers("Selection.WithHandlers", 3);
151
            Default = new Selection_Default("Selection.Default", -1);
152
        }
153

    
154
    }
155

    
156
    protected static class Selection_Default
157
        extends SelectionCADToolState
158
    {
159
    //-----------------------------------------------------------
160
    // Member methods.
161
    //
162

    
163
        protected Selection_Default(String name, int id)
164
        {
165
            super (name, id);
166
        }
167

    
168
        protected void addOption(SelectionCADToolContext context, String s)
169
        {
170
            SelectionCADTool ctxt = context.getOwner();
171

    
172
            if (s.equals(""))
173
            {
174
                boolean loopbackFlag =
175
                    context.getState().getName().equals(
176
                        Selection.FirstPoint.getName());
177

    
178
                if (loopbackFlag == false)
179
                {
180
                    (context.getState()).Exit(context);
181
                }
182

    
183
                context.clearState();
184
                try
185
                {
186
                    ctxt.restorePreviousTool();
187
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
188
                    ctxt.setDescription(new String[]{"cancel"});
189
                    ctxt.end();
190
                }
191
                finally
192
                {
193
                    context.setState(Selection.FirstPoint);
194

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

    
200
                }
201
            }
202
            else if (s.equals(PluginServices.getText(this,"cancel")))
203
            {
204
                boolean loopbackFlag =
205
                    context.getState().getName().equals(
206
                        Selection.FirstPoint.getName());
207

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

    
213
                context.clearState();
214
                try
215
                {
216
                    ctxt.end();
217
                }
218
                finally
219
                {
220
                    context.setState(Selection.FirstPoint);
221

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

    
227
                }
228
            }
229
            else
230
            {
231
                boolean loopbackFlag =
232
                    context.getState().getName().equals(
233
                        Selection.FirstPoint.getName());
234

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

    
240
                context.clearState();
241
                try
242
                {
243
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
244
                }
245
                finally
246
                {
247
                    context.setState(Selection.FirstPoint);
248

    
249
                    if (loopbackFlag == false)
250
                    {
251
                        (context.getState()).Entry(context);
252
                    }
253

    
254
                }
255
            }
256

    
257
            return;
258
        }
259

    
260
        protected void addValue(SelectionCADToolContext context, double d)
261
        {
262
            SelectionCADTool ctxt = context.getOwner();
263

    
264
            boolean loopbackFlag =
265
                context.getState().getName().equals(
266
                    Selection.FirstPoint.getName());
267

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

    
273
            context.clearState();
274
            try
275
            {
276
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
277
            }
278
            finally
279
            {
280
                context.setState(Selection.FirstPoint);
281

    
282
                if (loopbackFlag == false)
283
                {
284
                    (context.getState()).Entry(context);
285
                }
286

    
287
            }
288
            return;
289
        }
290

    
291
        protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
292
        {
293
            SelectionCADTool ctxt = context.getOwner();
294

    
295
            boolean loopbackFlag =
296
                context.getState().getName().equals(
297
                    Selection.FirstPoint.getName());
298

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

    
304
            context.clearState();
305
            try
306
            {
307
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
308
            }
309
            finally
310
            {
311
                context.setState(Selection.FirstPoint);
312

    
313
                if (loopbackFlag == false)
314
                {
315
                    (context.getState()).Entry(context);
316
                }
317

    
318
            }
319
            return;
320
        }
321

    
322
    //-----------------------------------------------------------
323
    // Inner classse.
324
    //
325

    
326

    
327
        private static final class Selection_FirstPoint
328
            extends Selection_Default
329
        {
330
        //-------------------------------------------------------
331
        // Member methods.
332
        //
333

    
334
            private Selection_FirstPoint(String name, int id)
335
            {
336
                super (name, id);
337
            }
338

    
339
            protected void Entry(SelectionCADToolContext context)
340
            {
341
                SelectionCADTool ctxt = context.getOwner();
342

    
343
                ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
344
                ctxt.setDescription(new String[]{"cancel"});
345
                return;
346
            }
347

    
348
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
349
            {
350
                SelectionCADTool ctxt = context.getOwner();
351

    
352
                if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.SecondPoint"))
353
                {
354

    
355
                    (context.getState()).Exit(context);
356
                    context.clearState();
357
                    try
358
                    {
359
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
360
                        ctxt.setDescription(new String[]{"cancel"});
361
                        ctxt.addPoint(pointX, pointY, event);
362
                    }
363
                    finally
364
                    {
365
                        context.setState(Selection.SecondPoint);
366
                        (context.getState()).Entry(context);
367
                    }
368
                }
369
                else if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.getNextState().equals("Selection.WithSelectedFeatures"))
370
                {
371

    
372
                    (context.getState()).Exit(context);
373
                    context.clearState();
374
                    try
375
                    {
376
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
377
                        ctxt.setDescription(new String[]{"cancel"});
378
                        ctxt.addPoint(pointX, pointY, event);
379
                        ctxt.end();
380
                    }
381
                    finally
382
                    {
383
                        context.setState(Selection.WithSelectedFeatures);
384
                        (context.getState()).Entry(context);
385
                    }
386
                }                else
387
                {
388
                    super.addPoint(context, pointX, pointY, event);
389
                }
390

    
391
                return;
392
            }
393

    
394
        //-------------------------------------------------------
395
        // Member data.
396
        //
397
        }
398

    
399
        private static final class Selection_SecondPoint
400
            extends Selection_Default
401
        {
402
        //-------------------------------------------------------
403
        // Member methods.
404
        //
405

    
406
            private Selection_SecondPoint(String name, int id)
407
            {
408
                super (name, id);
409
            }
410

    
411
            protected void addOption(SelectionCADToolContext context, String s)
412
            {
413
                SelectionCADTool ctxt = context.getOwner();
414

    
415

    
416
                (context.getState()).Exit(context);
417
                context.clearState();
418
                try
419
                {
420
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
421
                    ctxt.setDescription(new String[]{"cancel"});
422
                    ctxt.setType(s);
423
                }
424
                finally
425
                {
426
                    context.setState(Selection.FirstPoint);
427
                    (context.getState()).Entry(context);
428
                }
429
                return;
430
            }
431

    
432
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
433
            {
434
                SelectionCADTool ctxt = context.getOwner();
435

    
436
                if (ctxt.selectWithSecondPoint(pointX,pointY, event) > 0)
437
                {
438

    
439
                    (context.getState()).Exit(context);
440
                    context.clearState();
441
                    try
442
                    {
443
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
444
                        ctxt.setDescription(new String[]{"cancel"});
445
                        ctxt.addPoint(pointX, pointY, event);
446
                        ctxt.end();
447
                    }
448
                    finally
449
                    {
450
                        context.setState(Selection.WithSelectedFeatures);
451
                        (context.getState()).Entry(context);
452
                    }
453
                }
454
                else
455
                {
456

    
457
                    (context.getState()).Exit(context);
458
                    context.clearState();
459
                    try
460
                    {
461
                        ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
462
                        ctxt.setDescription(new String[]{"cancel"});
463
                        ctxt.addPoint(pointX, pointY, event);
464
                    }
465
                    finally
466
                    {
467
                        context.setState(Selection.FirstPoint);
468
                        (context.getState()).Entry(context);
469
                    }
470
                }
471

    
472
                return;
473
            }
474

    
475
        //-------------------------------------------------------
476
        // Member data.
477
        //
478
        }
479

    
480
        private static final class Selection_WithSelectedFeatures
481
            extends Selection_Default
482
        {
483
        //-------------------------------------------------------
484
        // Member methods.
485
        //
486

    
487
            private Selection_WithSelectedFeatures(String name, int id)
488
            {
489
                super (name, id);
490
            }
491

    
492
            protected void addOption(SelectionCADToolContext context, String s)
493
            {
494
                SelectionCADTool ctxt = context.getOwner();
495

    
496

    
497
                (context.getState()).Exit(context);
498
                context.clearState();
499
                try
500
                {
501
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
502
                    ctxt.setDescription(new String[]{"cancel"});
503
                    ctxt.setType(s);
504
                }
505
                finally
506
                {
507
                    context.setState(Selection.FirstPoint);
508
                    (context.getState()).Entry(context);
509
                }
510
                return;
511
            }
512

    
513
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
514
            {
515
                SelectionCADTool ctxt = context.getOwner();
516

    
517
                if (ctxt.selectHandlers(pointX, pointY, event)>0)
518
                {
519

    
520
                    (context.getState()).Exit(context);
521
                    context.clearState();
522
                    try
523
                    {
524
                        ctxt.setQuestion(PluginServices.getText(this,"insert_destination_point"));
525
                        ctxt.setDescription(new String[]{"cancel"});
526
                        ctxt.addPoint(pointX, pointY, event);
527
                    }
528
                    finally
529
                    {
530
                        context.setState(Selection.WithHandlers);
531
                        (context.getState()).Entry(context);
532
                    }
533
                }
534
                else if (ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.WithSelectedFeatures"))
535
                {
536
                    SelectionCADToolState endState = context.getState();
537

    
538
                    context.clearState();
539
                    try
540
                    {
541
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
542
                        ctxt.setDescription(new String[]{"cancel"});
543
                        ctxt.addPoint(pointX, pointY, event);
544
                    }
545
                    finally
546
                    {
547
                        context.setState(endState);
548
                    }
549
                }
550
                else
551
                {
552

    
553
                    (context.getState()).Exit(context);
554
                    context.clearState();
555
                    try
556
                    {
557
                        ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
558
                        ctxt.setDescription(new String[]{"cancel"});
559
                        ctxt.addPoint(pointX, pointY, event);
560
                    }
561
                    finally
562
                    {
563
                        context.setState(Selection.FirstPoint);
564
                        (context.getState()).Entry(context);
565
                    }
566
                }
567

    
568
                return;
569
            }
570

    
571
        //-------------------------------------------------------
572
        // Member data.
573
        //
574
        }
575

    
576
        private static final class Selection_WithHandlers
577
            extends Selection_Default
578
        {
579
        //-------------------------------------------------------
580
        // Member methods.
581
        //
582

    
583
            private Selection_WithHandlers(String name, int id)
584
            {
585
                super (name, id);
586
            }
587

    
588
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
589
            {
590
                SelectionCADTool ctxt = context.getOwner();
591

    
592

    
593
                (context.getState()).Exit(context);
594
                context.clearState();
595
                try
596
                {
597
                    ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
598
                    ctxt.setDescription(new String[]{"cancel"});
599
                    ctxt.addPoint(pointX, pointY, event);
600
                    ctxt.refresh();
601
                }
602
                finally
603
                {
604
                    context.setState(Selection.WithSelectedFeatures);
605
                    (context.getState()).Entry(context);
606
                }
607
                return;
608
            }
609

    
610
        //-------------------------------------------------------
611
        // Member data.
612
        //
613
        }
614

    
615
    //-----------------------------------------------------------
616
    // Member data.
617
    //
618
    }
619
}