Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / smc / SelectionCADToolContext.java @ 3883

History | View | Annotate | Download (10.3 KB)

1

    
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

    
11
public final class SelectionCADToolContext
12
    extends statemap.FSMContext
13
{
14
//---------------------------------------------------------------
15
// Member methods.
16
//
17

    
18
    public SelectionCADToolContext(SelectionCADTool owner)
19
    {
20
        super();
21

    
22
        _owner = owner;
23
        setState(ExecuteMap.Initial);
24
        ExecuteMap.Initial.Entry(this);
25
    }
26

    
27
    public void addOption(String s)
28
    {
29
        _transition = "addOption";
30
        getState().addOption(this, s);
31
        _transition = "";
32
        return;
33
    }
34

    
35
    public void addPoint(double pointX, double pointY)
36
    {
37
        _transition = "addPoint";
38
        getState().addPoint(this, pointX, pointY);
39
        _transition = "";
40
        return;
41
    }
42

    
43
    public SelectionCADToolState getState()
44
        throws statemap.StateUndefinedException
45
    {
46
        if (_state == null)
47
        {
48
            throw(
49
                new statemap.StateUndefinedException());
50
        }
51

    
52
        return ((SelectionCADToolState) _state);
53
    }
54

    
55
    protected SelectionCADTool getOwner()
56
    {
57
        return (_owner);
58
    }
59

    
60
//---------------------------------------------------------------
61
// Member data.
62
//
63

    
64
    transient private SelectionCADTool _owner;
65

    
66
//---------------------------------------------------------------
67
// Inner classes.
68
//
69

    
70
    public static abstract class SelectionCADToolState
71
        extends statemap.State
72
    {
73
    //-----------------------------------------------------------
74
    // Member methods.
75
    //
76

    
77
        protected SelectionCADToolState(String name, int id)
78
        {
79
            super (name, id);
80
        }
81

    
82
        protected void Entry(SelectionCADToolContext context) {}
83
        protected void Exit(SelectionCADToolContext context) {}
84

    
85
        protected void addOption(SelectionCADToolContext context, String s)
86
        {
87
            Default(context);
88
        }
89

    
90
        protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
91
        {
92
            Default(context);
93
        }
94

    
95
        protected void Default(SelectionCADToolContext context)
96
        {
97
            throw (
98
                new statemap.TransitionUndefinedException(
99
                    "State: " +
100
                    context.getState().getName() +
101
                    ", Transition: " +
102
                    context.getTransition()));
103
        }
104

    
105
    //-----------------------------------------------------------
106
    // Member data.
107
    //
108
    }
109

    
110
    /* package */ static abstract class ExecuteMap
111
    {
112
    //-----------------------------------------------------------
113
    // Member methods.
114
    //
115

    
116
    //-----------------------------------------------------------
117
    // Member data.
118
    //
119

    
120
        //-------------------------------------------------------
121
        // Statics.
122
        //
123
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
124
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
125
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
126
        /* package */ static ExecuteMap_Default.ExecuteMap_Third Third;
127
        private static ExecuteMap_Default Default;
128

    
129
        static
130
        {
131
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
132
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
133
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
134
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
135
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
136
        }
137

    
138
    }
139

    
140
    protected static class ExecuteMap_Default
141
        extends SelectionCADToolState
142
    {
143
    //-----------------------------------------------------------
144
    // Member methods.
145
    //
146

    
147
        protected ExecuteMap_Default(String name, int id)
148
        {
149
            super (name, id);
150
        }
151

    
152
        protected void addOption(SelectionCADToolContext context, String s)
153
        {
154
            SelectionCADTool ctxt = context.getOwner();
155

    
156
            if (s.equals("Cancelar"))
157
            {
158
                boolean loopbackFlag =
159
                    context.getState().getName().equals(
160
                        ExecuteMap.Initial.getName());
161

    
162
                if (loopbackFlag == false)
163
                {
164
                    (context.getState()).Exit(context);
165
                }
166

    
167
                context.clearState();
168
                try
169
                {
170
                    ctxt.end();
171
                }
172
                finally
173
                {
174
                    context.setState(ExecuteMap.Initial);
175

    
176
                    if (loopbackFlag == false)
177
                    {
178
                        (context.getState()).Entry(context);
179
                    }
180

    
181
                }
182
            }
183
            else
184
            {
185
                super.addOption(context, s);
186
            }
187

    
188
            return;
189
        }
190

    
191
    //-----------------------------------------------------------
192
    // Inner classse.
193
    //
194

    
195

    
196
        private static final class ExecuteMap_Initial
197
            extends ExecuteMap_Default
198
        {
199
        //-------------------------------------------------------
200
        // Member methods.
201
        //
202

    
203
            private ExecuteMap_Initial(String name, int id)
204
            {
205
                super (name, id);
206
            }
207

    
208
            protected void Entry(SelectionCADToolContext context)
209
            {
210
                SelectionCADTool ctxt = context.getOwner();
211

    
212
                ctxt.setQuestion("SELECCION" + "\n" +
213
                "Precise punto del rect?ngulo de selecci?n");
214
                ctxt.setDescription(new String[]{"Cancelar"});
215
                return;
216
            }
217

    
218
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
219
            {
220
                SelectionCADTool ctxt = context.getOwner();
221

    
222
                if (!ctxt.isSelected(pointX,pointY))
223
                {
224

    
225
                    (context.getState()).Exit(context);
226
                    context.clearState();
227
                    try
228
                    {
229
                        ctxt.setQuestion("Precise segundo punto del rect?ngulo de seleccion");
230
                        ctxt.setDescription(new String[]{"Cancelar"});
231
                        ctxt.addPoint(pointX, pointY);
232
                    }
233
                    finally
234
                    {
235
                        context.setState(ExecuteMap.First);
236
                        (context.getState()).Entry(context);
237
                    }
238
                }
239
                else if (ctxt.isSelected(pointX,pointY))
240
                {
241

    
242
                    (context.getState()).Exit(context);
243
                    context.clearState();
244
                    try
245
                    {
246
                        ctxt.setQuestion("Precise punto destino");
247
                        ctxt.setDescription(new String[]{"Cancelar"});
248
                        ctxt.addPoint(pointX, pointY);
249
                    }
250
                    finally
251
                    {
252
                        context.setState(ExecuteMap.Second);
253
                        (context.getState()).Entry(context);
254
                    }
255
                }                else
256
                {
257
                    super.addPoint(context, pointX, pointY);
258
                }
259

    
260
                return;
261
            }
262

    
263
        //-------------------------------------------------------
264
        // Member data.
265
        //
266
        }
267

    
268
        private static final class ExecuteMap_First
269
            extends ExecuteMap_Default
270
        {
271
        //-------------------------------------------------------
272
        // Member methods.
273
        //
274

    
275
            private ExecuteMap_First(String name, int id)
276
            {
277
                super (name, id);
278
            }
279

    
280
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
281
            {
282
                SelectionCADTool ctxt = context.getOwner();
283

    
284

    
285
                (context.getState()).Exit(context);
286
                context.clearState();
287
                try
288
                {
289
                    ctxt.setQuestion("Precise punto de estiramiento");
290
                    ctxt.setDescription(new String[]{"Cancelar"});
291
                    ctxt.addPoint(pointX, pointY);
292
                    ctxt.end();
293
                }
294
                finally
295
                {
296
                    context.setState(ExecuteMap.Initial);
297
                    (context.getState()).Entry(context);
298
                }
299
                return;
300
            }
301

    
302
        //-------------------------------------------------------
303
        // Member data.
304
        //
305
        }
306

    
307
        private static final class ExecuteMap_Second
308
            extends ExecuteMap_Default
309
        {
310
        //-------------------------------------------------------
311
        // Member methods.
312
        //
313

    
314
            private ExecuteMap_Second(String name, int id)
315
            {
316
                super (name, id);
317
            }
318

    
319
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
320
            {
321
                SelectionCADTool ctxt = context.getOwner();
322

    
323

    
324
                (context.getState()).Exit(context);
325
                context.clearState();
326
                try
327
                {
328
                    ctxt.setQuestion("Precise punto destino");
329
                    ctxt.setDescription(new String[]{"Cancelar"});
330
                    ctxt.addPoint(pointX, pointY);
331
                    ctxt.end();
332
                    ctxt.refresh();
333
                }
334
                finally
335
                {
336
                    context.setState(ExecuteMap.Third);
337
                    (context.getState()).Entry(context);
338
                }
339
                return;
340
            }
341

    
342
        //-------------------------------------------------------
343
        // Member data.
344
        //
345
        }
346

    
347
        private static final class ExecuteMap_Third
348
            extends ExecuteMap_Default
349
        {
350
        //-------------------------------------------------------
351
        // Member methods.
352
        //
353

    
354
            private ExecuteMap_Third(String name, int id)
355
            {
356
                super (name, id);
357
            }
358

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

    
364
    //-----------------------------------------------------------
365
    // Member data.
366
    //
367
    }
368
}