Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / SelectionCADToolContext.java @ 4465

History | View | Annotate | Download (13.6 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 3832 caballero
12
public final class SelectionCADToolContext
13
    extends statemap.FSMContext
14
{
15
//---------------------------------------------------------------
16
// Member methods.
17
//
18
19
    public SelectionCADToolContext(SelectionCADTool owner)
20
    {
21
        super();
22
23
        _owner = owner;
24 3978 caballero
        setState(Selection.FirstPoint);
25
        Selection.FirstPoint.Entry(this);
26 3832 caballero
    }
27
28 3883 caballero
    public void addOption(String s)
29
    {
30
        _transition = "addOption";
31
        getState().addOption(this, s);
32
        _transition = "";
33
        return;
34
    }
35
36 4324 caballero
    public void addPoint(double pointX, double pointY, InputEvent event)
37 3832 caballero
    {
38
        _transition = "addPoint";
39 4324 caballero
        getState().addPoint(this, pointX, pointY, event);
40 3832 caballero
        _transition = "";
41
        return;
42
    }
43
44
    public SelectionCADToolState getState()
45
        throws statemap.StateUndefinedException
46
    {
47
        if (_state == null)
48
        {
49
            throw(
50
                new statemap.StateUndefinedException());
51
        }
52
53
        return ((SelectionCADToolState) _state);
54
    }
55
56
    protected SelectionCADTool getOwner()
57
    {
58
        return (_owner);
59
    }
60
61
//---------------------------------------------------------------
62
// Member data.
63
//
64
65
    transient private SelectionCADTool _owner;
66
67
//---------------------------------------------------------------
68
// Inner classes.
69
//
70
71
    public static abstract class SelectionCADToolState
72
        extends statemap.State
73
    {
74
    //-----------------------------------------------------------
75
    // Member methods.
76
    //
77
78
        protected SelectionCADToolState(String name, int id)
79
        {
80
            super (name, id);
81
        }
82
83
        protected void Entry(SelectionCADToolContext context) {}
84
        protected void Exit(SelectionCADToolContext context) {}
85
86 3883 caballero
        protected void addOption(SelectionCADToolContext context, String s)
87
        {
88
            Default(context);
89
        }
90
91 4324 caballero
        protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
92 3832 caballero
        {
93
            Default(context);
94
        }
95
96
        protected void Default(SelectionCADToolContext context)
97
        {
98
            throw (
99
                new statemap.TransitionUndefinedException(
100
                    "State: " +
101
                    context.getState().getName() +
102
                    ", Transition: " +
103
                    context.getTransition()));
104
        }
105
106
    //-----------------------------------------------------------
107
    // Member data.
108
    //
109
    }
110
111 3978 caballero
    /* package */ static abstract class Selection
112 3832 caballero
    {
113
    //-----------------------------------------------------------
114
    // Member methods.
115
    //
116
117
    //-----------------------------------------------------------
118
    // Member data.
119
    //
120
121
        //-------------------------------------------------------
122
        // Statics.
123
        //
124 3978 caballero
        /* package */ static Selection_Default.Selection_FirstPoint FirstPoint;
125
        /* package */ static Selection_Default.Selection_SecondPoint SecondPoint;
126 4445 fjp
        /* package */ static Selection_Default.Selection_WithSelectedFeatures WithSelectedFeatures;
127
        /* package */ static Selection_Default.Selection_WithHandlers WithHandlers;
128 3978 caballero
        private static Selection_Default Default;
129 3832 caballero
130
        static
131
        {
132 3978 caballero
            FirstPoint = new Selection_Default.Selection_FirstPoint("Selection.FirstPoint", 0);
133
            SecondPoint = new Selection_Default.Selection_SecondPoint("Selection.SecondPoint", 1);
134 4445 fjp
            WithSelectedFeatures = new Selection_Default.Selection_WithSelectedFeatures("Selection.WithSelectedFeatures", 2);
135
            WithHandlers = new Selection_Default.Selection_WithHandlers("Selection.WithHandlers", 3);
136 3978 caballero
            Default = new Selection_Default("Selection.Default", -1);
137 3832 caballero
        }
138
139
    }
140
141 3978 caballero
    protected static class Selection_Default
142 3832 caballero
        extends SelectionCADToolState
143
    {
144
    //-----------------------------------------------------------
145
    // Member methods.
146
    //
147
148 3978 caballero
        protected Selection_Default(String name, int id)
149 3832 caballero
        {
150
            super (name, id);
151
        }
152
153 3883 caballero
        protected void addOption(SelectionCADToolContext context, String s)
154
        {
155
            SelectionCADTool ctxt = context.getOwner();
156
157
            if (s.equals("Cancelar"))
158
            {
159
                boolean loopbackFlag =
160
                    context.getState().getName().equals(
161 3978 caballero
                        Selection.FirstPoint.getName());
162 3883 caballero
163
                if (loopbackFlag == false)
164
                {
165
                    (context.getState()).Exit(context);
166
                }
167
168
                context.clearState();
169
                try
170
                {
171
                    ctxt.end();
172
                }
173
                finally
174
                {
175 3978 caballero
                    context.setState(Selection.FirstPoint);
176 3883 caballero
177
                    if (loopbackFlag == false)
178
                    {
179
                        (context.getState()).Entry(context);
180
                    }
181
182
                }
183
            }
184
            else
185
            {
186
                super.addOption(context, s);
187
            }
188
189
            return;
190
        }
191
192 3832 caballero
    //-----------------------------------------------------------
193
    // Inner classse.
194
    //
195
196
197 3978 caballero
        private static final class Selection_FirstPoint
198
            extends Selection_Default
199 3832 caballero
        {
200
        //-------------------------------------------------------
201
        // Member methods.
202
        //
203
204 3978 caballero
            private Selection_FirstPoint(String name, int id)
205 3832 caballero
            {
206
                super (name, id);
207
            }
208
209
            protected void Entry(SelectionCADToolContext context)
210
            {
211
                SelectionCADTool ctxt = context.getOwner();
212
213 3847 caballero
                ctxt.setQuestion("SELECCION" + "\n" +
214
                "Precise punto del rect?ngulo de selecci?n");
215 3883 caballero
                ctxt.setDescription(new String[]{"Cancelar"});
216 3832 caballero
                return;
217
            }
218
219 4324 caballero
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
220 3832 caballero
            {
221
                SelectionCADTool ctxt = context.getOwner();
222
223 4445 fjp
                if (ctxt.selectFeatures(pointX,pointY) && ctxt.getNextState().equals("Selection.SecondPoint"))
224 3832 caballero
                {
225 3847 caballero
226
                    (context.getState()).Exit(context);
227
                    context.clearState();
228
                    try
229
                    {
230
                        ctxt.setQuestion("Precise segundo punto del rect?ngulo de seleccion");
231 3883 caballero
                        ctxt.setDescription(new String[]{"Cancelar"});
232 4365 caballero
                        ctxt.addPoint(pointX, pointY, event);
233 3847 caballero
                    }
234
                    finally
235
                    {
236 3978 caballero
                        context.setState(Selection.SecondPoint);
237 3847 caballero
                        (context.getState()).Entry(context);
238
                    }
239 3832 caballero
                }
240 4445 fjp
                else if (ctxt.getNextState().equals("Selection.WithSelectedFeatures"))
241 3832 caballero
                {
242 3847 caballero
243 4445 fjp
                    (context.getState()).Exit(context);
244 4020 caballero
                    context.clearState();
245
                    try
246
                    {
247 4445 fjp
                        ctxt.setQuestion("select_handlers");
248 4020 caballero
                        ctxt.setDescription(new String[]{"Cancelar"});
249 4365 caballero
                        ctxt.addPoint(pointX, pointY, event);
250 4465 caballero
                        ctxt.end();
251 4020 caballero
                    }
252
                    finally
253
                    {
254 4445 fjp
                        context.setState(Selection.WithSelectedFeatures);
255
                        (context.getState()).Entry(context);
256 4020 caballero
                    }
257 4445 fjp
                }                else
258
                {
259
                    super.addPoint(context, pointX, pointY, event);
260 4020 caballero
                }
261 4445 fjp
262
                return;
263
            }
264
265
        //-------------------------------------------------------
266
        // Member data.
267
        //
268
        }
269
270
        private static final class Selection_SecondPoint
271
            extends Selection_Default
272
        {
273
        //-------------------------------------------------------
274
        // Member methods.
275
        //
276
277
            private Selection_SecondPoint(String name, int id)
278
            {
279
                super (name, id);
280
            }
281
282
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
283
            {
284
                SelectionCADTool ctxt = context.getOwner();
285
286 4448 fjp
                if (ctxt.selectWithSecondPoint(pointX,pointY) > 0)
287 4020 caballero
                {
288
289 3847 caballero
                    (context.getState()).Exit(context);
290
                    context.clearState();
291
                    try
292
                    {
293 4448 fjp
                        ctxt.setQuestion("select_handlers");
294 3883 caballero
                        ctxt.setDescription(new String[]{"Cancelar"});
295 4448 fjp
                        ctxt.addPoint(pointX, pointY, event);
296 4465 caballero
                        ctxt.end();
297 4445 fjp
                    }
298
                    finally
299
                    {
300 4448 fjp
                        context.setState(Selection.WithSelectedFeatures);
301 4445 fjp
                        (context.getState()).Entry(context);
302
                    }
303
                }
304 4448 fjp
                else
305 4445 fjp
                {
306
307
                    (context.getState()).Exit(context);
308
                    context.clearState();
309
                    try
310
                    {
311 4448 fjp
                        ctxt.setQuestion("Precise punto del rect?ngulo de selecci?n");
312 4445 fjp
                        ctxt.setDescription(new String[]{"Cancelar"});
313 3847 caballero
                    }
314
                    finally
315
                    {
316 4448 fjp
                        context.setState(Selection.FirstPoint);
317 3847 caballero
                        (context.getState()).Entry(context);
318
                    }
319 3832 caballero
                }
320 3847 caballero
321 3832 caballero
                return;
322
            }
323
324
        //-------------------------------------------------------
325
        // Member data.
326
        //
327
        }
328
329 4445 fjp
        private static final class Selection_WithSelectedFeatures
330 3978 caballero
            extends Selection_Default
331 3832 caballero
        {
332
        //-------------------------------------------------------
333
        // Member methods.
334
        //
335
336 4445 fjp
            private Selection_WithSelectedFeatures(String name, int id)
337 3832 caballero
            {
338
                super (name, id);
339
            }
340
341 4324 caballero
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
342 3832 caballero
            {
343
                SelectionCADTool ctxt = context.getOwner();
344
345 4448 fjp
                if (ctxt.selectHandlers(pointX, pointY)>0)
346 4445 fjp
                {
347 3832 caballero
348 4445 fjp
                    (context.getState()).Exit(context);
349
                    context.clearState();
350
                    try
351
                    {
352 4448 fjp
                        ctxt.setQuestion("Precise punto destino");
353 4445 fjp
                        ctxt.setDescription(new String[]{"Cancelar"});
354
                        ctxt.addPoint(pointX, pointY, event);
355
                    }
356
                    finally
357
                    {
358 4448 fjp
                        context.setState(Selection.WithHandlers);
359 4445 fjp
                        (context.getState()).Entry(context);
360
                    }
361 3832 caballero
                }
362 4448 fjp
                else if (ctxt.selectFeatures(pointX,pointY) && ctxt.getNextState().equals("Selection.WithSelectedFeatures"))
363 3832 caballero
                {
364 4448 fjp
                    SelectionCADToolState endState = context.getState();
365 4445 fjp
366 4448 fjp
                    context.clearState();
367
                    try
368
                    {
369
                        ctxt.setQuestion("select_handlers");
370
                        ctxt.setDescription(new String[]{"Cancelar"});
371
                        ctxt.addPoint(pointX, pointY, event);
372
                    }
373
                    finally
374
                    {
375
                        context.setState(endState);
376
                    }
377
                }
378
                else
379
                {
380
381 4445 fjp
                    (context.getState()).Exit(context);
382
                    context.clearState();
383
                    try
384
                    {
385 4448 fjp
                        ctxt.setQuestion("Precise punto del rect?ngulo de selecci?n");
386 4445 fjp
                        ctxt.setDescription(new String[]{"Cancelar"});
387
                        ctxt.addPoint(pointX, pointY, event);
388
                    }
389
                    finally
390
                    {
391 4448 fjp
                        context.setState(Selection.FirstPoint);
392 4445 fjp
                        (context.getState()).Entry(context);
393
                    }
394 3832 caballero
                }
395 4445 fjp
396 3832 caballero
                return;
397
            }
398
399
        //-------------------------------------------------------
400
        // Member data.
401
        //
402
        }
403
404 4445 fjp
        private static final class Selection_WithHandlers
405 3978 caballero
            extends Selection_Default
406 3832 caballero
        {
407
        //-------------------------------------------------------
408
        // Member methods.
409
        //
410
411 4445 fjp
            private Selection_WithHandlers(String name, int id)
412 3832 caballero
            {
413
                super (name, id);
414
            }
415
416 4324 caballero
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY, InputEvent event)
417 3832 caballero
            {
418
                SelectionCADTool ctxt = context.getOwner();
419
420
421
                (context.getState()).Exit(context);
422
                context.clearState();
423
                try
424
                {
425 4445 fjp
                    ctxt.setQuestion("select_handlers");
426 3883 caballero
                    ctxt.setDescription(new String[]{"Cancelar"});
427 4365 caballero
                    ctxt.addPoint(pointX, pointY, event);
428 3847 caballero
                    ctxt.refresh();
429 3832 caballero
                }
430
                finally
431
                {
432 4445 fjp
                    context.setState(Selection.WithSelectedFeatures);
433 3832 caballero
                    (context.getState()).Entry(context);
434
                }
435
                return;
436
            }
437
438
        //-------------------------------------------------------
439
        // Member data.
440
        //
441
        }
442
443
    //-----------------------------------------------------------
444
    // Member data.
445
    //
446
    }
447
}