Statistics
| Revision:

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

History | View | Annotate | Download (8.72 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
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 addPoint(double pointX, double pointY)
28
    {
29
        _transition = "addPoint";
30
        getState().addPoint(this, pointX, pointY);
31
        _transition = "";
32
        return;
33
    }
34
35
    public SelectionCADToolState getState()
36
        throws statemap.StateUndefinedException
37
    {
38
        if (_state == null)
39
        {
40
            throw(
41
                new statemap.StateUndefinedException());
42
        }
43
44
        return ((SelectionCADToolState) _state);
45
    }
46
47
    protected SelectionCADTool getOwner()
48
    {
49
        return (_owner);
50
    }
51
52
//---------------------------------------------------------------
53
// Member data.
54
//
55
56
    transient private SelectionCADTool _owner;
57
58
//---------------------------------------------------------------
59
// Inner classes.
60
//
61
62
    public static abstract class SelectionCADToolState
63
        extends statemap.State
64
    {
65
    //-----------------------------------------------------------
66
    // Member methods.
67
    //
68
69
        protected SelectionCADToolState(String name, int id)
70
        {
71
            super (name, id);
72
        }
73
74
        protected void Entry(SelectionCADToolContext context) {}
75
        protected void Exit(SelectionCADToolContext context) {}
76
77
        protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
78
        {
79
            Default(context);
80
        }
81
82
        protected void Default(SelectionCADToolContext context)
83
        {
84
            throw (
85
                new statemap.TransitionUndefinedException(
86
                    "State: " +
87
                    context.getState().getName() +
88
                    ", Transition: " +
89
                    context.getTransition()));
90
        }
91
92
    //-----------------------------------------------------------
93
    // Member data.
94
    //
95
    }
96
97
    /* package */ static abstract class ExecuteMap
98
    {
99
    //-----------------------------------------------------------
100
    // Member methods.
101
    //
102
103
    //-----------------------------------------------------------
104
    // Member data.
105
    //
106
107
        //-------------------------------------------------------
108
        // Statics.
109
        //
110
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
111
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
112
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
113
        /* package */ static ExecuteMap_Default.ExecuteMap_Third Third;
114
        private static ExecuteMap_Default Default;
115
116
        static
117
        {
118
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
119
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
120
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
121
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
122
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
123
        }
124
125
    }
126
127
    protected static class ExecuteMap_Default
128
        extends SelectionCADToolState
129
    {
130
    //-----------------------------------------------------------
131
    // Member methods.
132
    //
133
134
        protected ExecuteMap_Default(String name, int id)
135
        {
136
            super (name, id);
137
        }
138
139
    //-----------------------------------------------------------
140
    // Inner classse.
141
    //
142
143
144
        private static final class ExecuteMap_Initial
145
            extends ExecuteMap_Default
146
        {
147
        //-------------------------------------------------------
148
        // Member methods.
149
        //
150
151
            private ExecuteMap_Initial(String name, int id)
152
            {
153
                super (name, id);
154
            }
155
156
            protected void Entry(SelectionCADToolContext context)
157
            {
158
                SelectionCADTool ctxt = context.getOwner();
159
160
                ctxt.init();
161 3847 caballero
                ctxt.setQuestion("SELECCION" + "\n" +
162
                "Precise punto del rect?ngulo de selecci?n");
163 3832 caballero
                return;
164
            }
165
166
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
167
            {
168
                SelectionCADTool ctxt = context.getOwner();
169
170 3847 caballero
                if (!ctxt.isSelected(pointX,pointY))
171 3832 caballero
                {
172 3847 caballero
173
                    (context.getState()).Exit(context);
174
                    context.clearState();
175
                    try
176
                    {
177
                        ctxt.setQuestion("Precise segundo punto del rect?ngulo de seleccion");
178
                        ctxt.addPoint(pointX, pointY);
179
                    }
180
                    finally
181
                    {
182
                        context.setState(ExecuteMap.First);
183
                        (context.getState()).Entry(context);
184
                    }
185 3832 caballero
                }
186 3847 caballero
                else if (ctxt.isSelected(pointX,pointY))
187 3832 caballero
                {
188 3847 caballero
189
                    (context.getState()).Exit(context);
190
                    context.clearState();
191
                    try
192
                    {
193
                        ctxt.setQuestion("Precise punto destino");
194
                        ctxt.addPoint(pointX, pointY);
195
                    }
196
                    finally
197
                    {
198
                        context.setState(ExecuteMap.Second);
199
                        (context.getState()).Entry(context);
200
                    }
201
                }                else
202
                {
203
                    super.addPoint(context, pointX, pointY);
204 3832 caballero
                }
205 3847 caballero
206 3832 caballero
                return;
207
            }
208
209
        //-------------------------------------------------------
210
        // Member data.
211
        //
212
        }
213
214
        private static final class ExecuteMap_First
215
            extends ExecuteMap_Default
216
        {
217
        //-------------------------------------------------------
218
        // Member methods.
219
        //
220
221
            private ExecuteMap_First(String name, int id)
222
            {
223
                super (name, id);
224
            }
225
226
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
227
            {
228
                SelectionCADTool ctxt = context.getOwner();
229
230
231
                (context.getState()).Exit(context);
232
                context.clearState();
233
                try
234
                {
235
                    ctxt.setQuestion("Precise punto de estiramiento");
236
                    ctxt.addPoint(pointX, pointY);
237
                }
238
                finally
239
                {
240 3847 caballero
                    context.setState(ExecuteMap.Initial);
241 3832 caballero
                    (context.getState()).Entry(context);
242
                }
243
                return;
244
            }
245
246
        //-------------------------------------------------------
247
        // Member data.
248
        //
249
        }
250
251
        private static final class ExecuteMap_Second
252
            extends ExecuteMap_Default
253
        {
254
        //-------------------------------------------------------
255
        // Member methods.
256
        //
257
258
            private ExecuteMap_Second(String name, int id)
259
            {
260
                super (name, id);
261
            }
262
263
            protected void addPoint(SelectionCADToolContext context, double pointX, double pointY)
264
            {
265
                SelectionCADTool ctxt = context.getOwner();
266
267
268
                (context.getState()).Exit(context);
269
                context.clearState();
270
                try
271
                {
272 3847 caballero
                    ctxt.setQuestion("Precise punto destino");
273 3832 caballero
                    ctxt.addPoint(pointX, pointY);
274 3847 caballero
                    ctxt.end();
275
                    ctxt.refresh();
276 3832 caballero
                }
277
                finally
278
                {
279
                    context.setState(ExecuteMap.Third);
280
                    (context.getState()).Entry(context);
281
                }
282
                return;
283
            }
284
285
        //-------------------------------------------------------
286
        // Member data.
287
        //
288
        }
289
290
        private static final class ExecuteMap_Third
291
            extends ExecuteMap_Default
292
        {
293
        //-------------------------------------------------------
294
        // Member methods.
295
        //
296
297
            private ExecuteMap_Third(String name, int id)
298
            {
299
                super (name, id);
300
            }
301
302
        //-------------------------------------------------------
303
        // Member data.
304
        //
305
        }
306
307
    //-----------------------------------------------------------
308
    // Member data.
309
    //
310
    }
311
}