Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_915 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / SelectionCADToolContext.java @ 12217

History | View | Annotate | Download (19.1 KB)

1 3832 caballero
2
//
3
// Vicente Caballero Navarro
4
5
6
package com.iver.cit.gvsig.gui.cad.tools.smc;
7
8
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool;
9
import com.iver.cit.gvsig.fmap.layers.FBitSet;
10 4324 caballero
import java.awt.event.InputEvent;
11 4584 caballero
import com.iver.andami.PluginServices;
12 3832 caballero
13
public final class SelectionCADToolContext
14
    extends statemap.FSMContext
15
{
16
//---------------------------------------------------------------
17
// Member methods.
18
//
19
20
    public SelectionCADToolContext(SelectionCADTool owner)
21
    {
22
        super();
23
24
        _owner = owner;
25 3978 caballero
        setState(Selection.FirstPoint);
26
        Selection.FirstPoint.Entry(this);
27 3832 caballero
    }
28
29 3883 caballero
    public void addOption(String s)
30
    {
31
        _transition = "addOption";
32
        getState().addOption(this, s);
33
        _transition = "";
34
        return;
35
    }
36
37 4324 caballero
    public void addPoint(double pointX, double pointY, InputEvent event)
38 3832 caballero
    {
39
        _transition = "addPoint";
40 4324 caballero
        getState().addPoint(this, pointX, pointY, event);
41 3832 caballero
        _transition = "";
42
        return;
43
    }
44
45 5735 caballero
    public void addValue(double d)
46
    {
47
        _transition = "addValue";
48
        getState().addValue(this, d);
49
        _transition = "";
50
        return;
51
    }
52
53 3832 caballero
    public SelectionCADToolState getState()
54
        throws statemap.StateUndefinedException
55
    {
56
        if (_state == null)
57
        {
58
            throw(
59
                new statemap.StateUndefinedException());
60
        }
61
62
        return ((SelectionCADToolState) _state);
63
    }
64
65
    protected SelectionCADTool getOwner()
66
    {
67
        return (_owner);
68
    }
69
70
//---------------------------------------------------------------
71
// Member data.
72
//
73
74
    transient private SelectionCADTool _owner;
75
76
//---------------------------------------------------------------
77
// Inner classes.
78
//
79
80
    public static abstract class SelectionCADToolState
81
        extends statemap.State
82
    {
83
    //-----------------------------------------------------------
84
    // Member methods.
85
    //
86
87
        protected SelectionCADToolState(String name, int id)
88
        {
89
            super (name, id);
90
        }
91
92
        protected void Entry(SelectionCADToolContext context) {}
93
        protected void Exit(SelectionCADToolContext context) {}
94
95 3883 caballero
        protected void addOption(SelectionCADToolContext context, String s)
96
        {
97
            Default(context);
98
        }
99
100 4324 caballero
        protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
101 3832 caballero
        {
102
            Default(context);
103
        }
104
105 5735 caballero
        protected void addValue(SelectionCADToolContext context, double d)
106
        {
107
            Default(context);
108
        }
109
110 3832 caballero
        protected void Default(SelectionCADToolContext context)
111
        {
112
            throw (
113
                new statemap.TransitionUndefinedException(
114
                    "State: " +
115
                    context.getState().getName() +
116
                    ", Transition: " +
117
                    context.getTransition()));
118
        }
119
120
    //-----------------------------------------------------------
121
    // Member data.
122
    //
123
    }
124
125 3978 caballero
    /* package */ static abstract class Selection
126 3832 caballero
    {
127
    //-----------------------------------------------------------
128
    // Member methods.
129
    //
130
131
    //-----------------------------------------------------------
132
    // Member data.
133
    //
134
135
        //-------------------------------------------------------
136
        // Statics.
137
        //
138 3978 caballero
        /* package */ static Selection_Default.Selection_FirstPoint FirstPoint;
139
        /* package */ static Selection_Default.Selection_SecondPoint SecondPoint;
140 4445 fjp
        /* package */ static Selection_Default.Selection_WithSelectedFeatures WithSelectedFeatures;
141
        /* package */ static Selection_Default.Selection_WithHandlers WithHandlers;
142 3978 caballero
        private static Selection_Default Default;
143 3832 caballero
144
        static
145
        {
146 3978 caballero
            FirstPoint = new Selection_Default.Selection_FirstPoint("Selection.FirstPoint", 0);
147
            SecondPoint = new Selection_Default.Selection_SecondPoint("Selection.SecondPoint", 1);
148 4445 fjp
            WithSelectedFeatures = new Selection_Default.Selection_WithSelectedFeatures("Selection.WithSelectedFeatures", 2);
149
            WithHandlers = new Selection_Default.Selection_WithHandlers("Selection.WithHandlers", 3);
150 3978 caballero
            Default = new Selection_Default("Selection.Default", -1);
151 3832 caballero
        }
152
153
    }
154
155 3978 caballero
    protected static class Selection_Default
156 3832 caballero
        extends SelectionCADToolState
157
    {
158
    //-----------------------------------------------------------
159
    // Member methods.
160
    //
161
162 3978 caballero
        protected Selection_Default(String name, int id)
163 3832 caballero
        {
164
            super (name, id);
165
        }
166
167 3883 caballero
        protected void addOption(SelectionCADToolContext context, String s)
168
        {
169
            SelectionCADTool ctxt = context.getOwner();
170
171 9068 caballero
            if (s.equals(""))
172 3883 caballero
            {
173
                boolean loopbackFlag =
174
                    context.getState().getName().equals(
175 3978 caballero
                        Selection.FirstPoint.getName());
176 3883 caballero
177
                if (loopbackFlag == false)
178
                {
179
                    (context.getState()).Exit(context);
180
                }
181
182
                context.clearState();
183
                try
184
                {
185 9068 caballero
                    ctxt.restorePreviousTool();
186
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
187
                    ctxt.setDescription(new String[]{"cancel"});
188 3883 caballero
                    ctxt.end();
189
                }
190
                finally
191
                {
192 3978 caballero
                    context.setState(Selection.FirstPoint);
193 3883 caballero
194
                    if (loopbackFlag == false)
195
                    {
196
                        (context.getState()).Entry(context);
197
                    }
198
199
                }
200
            }
201 9068 caballero
            else if (s.equals(PluginServices.getText(this,"cancel")))
202
            {
203
                boolean loopbackFlag =
204
                    context.getState().getName().equals(
205
                        Selection.FirstPoint.getName());
206
207
                if (loopbackFlag == false)
208
                {
209
                    (context.getState()).Exit(context);
210
                }
211
212
                context.clearState();
213
                try
214
                {
215
                    ctxt.end();
216
                }
217
                finally
218
                {
219
                    context.setState(Selection.FirstPoint);
220
221
                    if (loopbackFlag == false)
222
                    {
223
                        (context.getState()).Entry(context);
224
                    }
225
226
                }
227
            }
228 3883 caballero
            else
229
            {
230 5735 caballero
                boolean loopbackFlag =
231
                    context.getState().getName().equals(
232
                        Selection.FirstPoint.getName());
233
234
                if (loopbackFlag == false)
235
                {
236
                    (context.getState()).Exit(context);
237
                }
238
239
                context.clearState();
240
                try
241
                {
242
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
243
                }
244
                finally
245
                {
246
                    context.setState(Selection.FirstPoint);
247
248
                    if (loopbackFlag == false)
249
                    {
250
                        (context.getState()).Entry(context);
251
                    }
252
253
                }
254 3883 caballero
            }
255
256
            return;
257
        }
258
259 5735 caballero
        protected void addValue(SelectionCADToolContext context, double d)
260
        {
261
            SelectionCADTool ctxt = context.getOwner();
262
263
            boolean loopbackFlag =
264
                context.getState().getName().equals(
265
                    Selection.FirstPoint.getName());
266
267
            if (loopbackFlag == false)
268
            {
269
                (context.getState()).Exit(context);
270
            }
271
272
            context.clearState();
273
            try
274
            {
275
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
276
            }
277
            finally
278
            {
279
                context.setState(Selection.FirstPoint);
280
281
                if (loopbackFlag == false)
282
                {
283
                    (context.getState()).Entry(context);
284
                }
285
286
            }
287
            return;
288
        }
289
290
        protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
291
        {
292
            SelectionCADTool ctxt = context.getOwner();
293
294
            boolean loopbackFlag =
295
                context.getState().getName().equals(
296
                    Selection.FirstPoint.getName());
297
298
            if (loopbackFlag == false)
299
            {
300
                (context.getState()).Exit(context);
301
            }
302
303
            context.clearState();
304
            try
305
            {
306
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
307
            }
308
            finally
309
            {
310
                context.setState(Selection.FirstPoint);
311
312
                if (loopbackFlag == false)
313
                {
314
                    (context.getState()).Entry(context);
315
                }
316
317
            }
318
            return;
319
        }
320
321 3832 caballero
    //-----------------------------------------------------------
322
    // Inner classse.
323
    //
324
325
326 3978 caballero
        private static final class Selection_FirstPoint
327
            extends Selection_Default
328 3832 caballero
        {
329
        //-------------------------------------------------------
330
        // Member methods.
331
        //
332
333 3978 caballero
            private Selection_FirstPoint(String name, int id)
334 3832 caballero
            {
335
                super (name, id);
336
            }
337
338
            protected void Entry(SelectionCADToolContext context)
339
            {
340
                SelectionCADTool ctxt = context.getOwner();
341
342 5207 caballero
                ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
343
                ctxt.setDescription(new String[]{"cancel"});
344 3832 caballero
                return;
345
            }
346
347 4324 caballero
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
348 3832 caballero
            {
349
                SelectionCADTool ctxt = context.getOwner();
350
351 5207 caballero
                if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.SecondPoint"))
352 3832 caballero
                {
353 3847 caballero
354
                    (context.getState()).Exit(context);
355
                    context.clearState();
356
                    try
357
                    {
358 5207 caballero
                        ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
359
                        ctxt.setDescription(new String[]{"cancel"});
360 4365 caballero
                        ctxt.addPoint(pointX, pointY, event);
361 3847 caballero
                    }
362
                    finally
363
                    {
364 3978 caballero
                        context.setState(Selection.SecondPoint);
365 3847 caballero
                        (context.getState()).Entry(context);
366
                    }
367 3832 caballero
                }
368 4708 caballero
                else if (ctxt.getType().equals(PluginServices.getText(this,"simple")) && ctxt.getNextState().equals("Selection.WithSelectedFeatures"))
369 3832 caballero
                {
370 3847 caballero
371 4445 fjp
                    (context.getState()).Exit(context);
372 4020 caballero
                    context.clearState();
373
                    try
374
                    {
375 4584 caballero
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
376 5207 caballero
                        ctxt.setDescription(new String[]{"cancel"});
377 4365 caballero
                        ctxt.addPoint(pointX, pointY, event);
378 4465 caballero
                        ctxt.end();
379 4020 caballero
                    }
380
                    finally
381
                    {
382 4445 fjp
                        context.setState(Selection.WithSelectedFeatures);
383
                        (context.getState()).Entry(context);
384 4020 caballero
                    }
385 4445 fjp
                }                else
386
                {
387
                    super.addPoint(context, pointX, pointY, event);
388 4020 caballero
                }
389 4445 fjp
390
                return;
391
            }
392
393
        //-------------------------------------------------------
394
        // Member data.
395
        //
396
        }
397
398
        private static final class Selection_SecondPoint
399
            extends Selection_Default
400
        {
401
        //-------------------------------------------------------
402
        // Member methods.
403
        //
404
405
            private Selection_SecondPoint(String name, int id)
406
            {
407
                super (name, id);
408
            }
409
410 4708 caballero
            protected void addOption(SelectionCADToolContext context, String s)
411
            {
412
                SelectionCADTool ctxt = context.getOwner();
413
414
415
                (context.getState()).Exit(context);
416
                context.clearState();
417
                try
418
                {
419 5207 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
420
                    ctxt.setDescription(new String[]{"cancel"});
421 4708 caballero
                    ctxt.setType(s);
422
                }
423
                finally
424
                {
425
                    context.setState(Selection.FirstPoint);
426
                    (context.getState()).Entry(context);
427
                }
428
                return;
429
            }
430
431 4445 fjp
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
432
            {
433
                SelectionCADTool ctxt = context.getOwner();
434
435 4491 fjp
                if (ctxt.selectWithSecondPoint(pointX,pointY, event) > 0)
436 4020 caballero
                {
437
438 3847 caballero
                    (context.getState()).Exit(context);
439
                    context.clearState();
440
                    try
441
                    {
442 4584 caballero
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
443 5207 caballero
                        ctxt.setDescription(new String[]{"cancel"});
444 4448 fjp
                        ctxt.addPoint(pointX, pointY, event);
445 4465 caballero
                        ctxt.end();
446 4445 fjp
                    }
447
                    finally
448
                    {
449 4448 fjp
                        context.setState(Selection.WithSelectedFeatures);
450 4445 fjp
                        (context.getState()).Entry(context);
451
                    }
452
                }
453 4448 fjp
                else
454 4445 fjp
                {
455
456
                    (context.getState()).Exit(context);
457
                    context.clearState();
458
                    try
459
                    {
460 5207 caballero
                        ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
461
                        ctxt.setDescription(new String[]{"cancel"});
462 4708 caballero
                        ctxt.addPoint(pointX, pointY, event);
463 3847 caballero
                    }
464
                    finally
465
                    {
466 4448 fjp
                        context.setState(Selection.FirstPoint);
467 3847 caballero
                        (context.getState()).Entry(context);
468
                    }
469 3832 caballero
                }
470 3847 caballero
471 3832 caballero
                return;
472
            }
473
474
        //-------------------------------------------------------
475
        // Member data.
476
        //
477
        }
478
479 4445 fjp
        private static final class Selection_WithSelectedFeatures
480 3978 caballero
            extends Selection_Default
481 3832 caballero
        {
482
        //-------------------------------------------------------
483
        // Member methods.
484
        //
485
486 4445 fjp
            private Selection_WithSelectedFeatures(String name, int id)
487 3832 caballero
            {
488
                super (name, id);
489
            }
490
491 4708 caballero
            protected void addOption(SelectionCADToolContext context, String s)
492
            {
493
                SelectionCADTool ctxt = context.getOwner();
494
495
496
                (context.getState()).Exit(context);
497
                context.clearState();
498
                try
499
                {
500 5207 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
501
                    ctxt.setDescription(new String[]{"cancel"});
502 4708 caballero
                    ctxt.setType(s);
503
                }
504
                finally
505
                {
506
                    context.setState(Selection.FirstPoint);
507
                    (context.getState()).Entry(context);
508
                }
509
                return;
510
            }
511
512 4324 caballero
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
513 3832 caballero
            {
514
                SelectionCADTool ctxt = context.getOwner();
515
516 4491 fjp
                if (ctxt.selectHandlers(pointX, pointY, event)>0)
517 4445 fjp
                {
518 3832 caballero
519 4445 fjp
                    (context.getState()).Exit(context);
520
                    context.clearState();
521
                    try
522
                    {
523 4584 caballero
                        ctxt.setQuestion(PluginServices.getText(this,"insert_destination_point"));
524 5207 caballero
                        ctxt.setDescription(new String[]{"cancel"});
525 4445 fjp
                        ctxt.addPoint(pointX, pointY, event);
526
                    }
527
                    finally
528
                    {
529 4448 fjp
                        context.setState(Selection.WithHandlers);
530 4445 fjp
                        (context.getState()).Entry(context);
531
                    }
532 3832 caballero
                }
533 4491 fjp
                else if (ctxt.selectFeatures(pointX,pointY, event) && ctxt.getNextState().equals("Selection.WithSelectedFeatures"))
534 3832 caballero
                {
535 4448 fjp
                    SelectionCADToolState endState = context.getState();
536 4445 fjp
537 4448 fjp
                    context.clearState();
538
                    try
539
                    {
540 4584 caballero
                        ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
541 5207 caballero
                        ctxt.setDescription(new String[]{"cancel"});
542 4448 fjp
                        ctxt.addPoint(pointX, pointY, event);
543
                    }
544
                    finally
545
                    {
546
                        context.setState(endState);
547
                    }
548
                }
549
                else
550
                {
551
552 4445 fjp
                    (context.getState()).Exit(context);
553
                    context.clearState();
554
                    try
555
                    {
556 5207 caballero
                        ctxt.setQuestion(PluginServices.getText(this,"insert_point_selection"));
557
                        ctxt.setDescription(new String[]{"cancel"});
558 4445 fjp
                        ctxt.addPoint(pointX, pointY, event);
559
                    }
560
                    finally
561
                    {
562 4448 fjp
                        context.setState(Selection.FirstPoint);
563 4445 fjp
                        (context.getState()).Entry(context);
564
                    }
565 3832 caballero
                }
566 4445 fjp
567 3832 caballero
                return;
568
            }
569
570
        //-------------------------------------------------------
571
        // Member data.
572
        //
573
        }
574
575 4445 fjp
        private static final class Selection_WithHandlers
576 3978 caballero
            extends Selection_Default
577 3832 caballero
        {
578
        //-------------------------------------------------------
579
        // Member methods.
580
        //
581
582 4445 fjp
            private Selection_WithHandlers(String name, int id)
583 3832 caballero
            {
584
                super (name, id);
585
            }
586
587 4324 caballero
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
588 3832 caballero
            {
589
                SelectionCADTool ctxt = context.getOwner();
590
591
592
                (context.getState()).Exit(context);
593
                context.clearState();
594
                try
595
                {
596 4584 caballero
                    ctxt.setQuestion(PluginServices.getText(this,"select_handlers"));
597 5207 caballero
                    ctxt.setDescription(new String[]{"cancel"});
598 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
599 3847 caballero
                    ctxt.refresh();
600 3832 caballero
                }
601
                finally
602
                {
603 4445 fjp
                    context.setState(Selection.WithSelectedFeatures);
604 3832 caballero
                    (context.getState()).Entry(context);
605
                }
606
                return;
607
            }
608
609
        //-------------------------------------------------------
610
        // Member data.
611
        //
612
        }
613
614
    //-----------------------------------------------------------
615
    // Member data.
616
    //
617
    }
618
}