Statistics
| Revision:

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

History | View | Annotate | Download (7.57 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.ArcCADTool;
9

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

    
17
    public ArcCADToolContext(ArcCADTool owner)
18
    {
19
        super();
20

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

    
26
    public void addPoint(double pointX, double pointY)
27
    {
28
        _transition = "addPoint";
29
        getState().addPoint(this, pointX, pointY);
30
        _transition = "";
31
        return;
32
    }
33

    
34
    public ArcCADToolState getState()
35
        throws statemap.StateUndefinedException
36
    {
37
        if (_state == null)
38
        {
39
            throw(
40
                new statemap.StateUndefinedException());
41
        }
42

    
43
        return ((ArcCADToolState) _state);
44
    }
45

    
46
    protected ArcCADTool getOwner()
47
    {
48
        return (_owner);
49
    }
50

    
51
//---------------------------------------------------------------
52
// Member data.
53
//
54

    
55
    transient private ArcCADTool _owner;
56

    
57
//---------------------------------------------------------------
58
// Inner classes.
59
//
60

    
61
    public static abstract class ArcCADToolState
62
        extends statemap.State
63
    {
64
    //-----------------------------------------------------------
65
    // Member methods.
66
    //
67

    
68
        protected ArcCADToolState(String name, int id)
69
        {
70
            super (name, id);
71
        }
72

    
73
        protected void Entry(ArcCADToolContext context) {}
74
        protected void Exit(ArcCADToolContext context) {}
75

    
76
        protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
77
        {
78
            Default(context);
79
        }
80

    
81
        protected void Default(ArcCADToolContext context)
82
        {
83
            throw (
84
                new statemap.TransitionUndefinedException(
85
                    "State: " +
86
                    context.getState().getName() +
87
                    ", Transition: " +
88
                    context.getTransition()));
89
        }
90

    
91
    //-----------------------------------------------------------
92
    // Member data.
93
    //
94
    }
95

    
96
    /* package */ static abstract class ExecuteMap
97
    {
98
    //-----------------------------------------------------------
99
    // Member methods.
100
    //
101

    
102
    //-----------------------------------------------------------
103
    // Member data.
104
    //
105

    
106
        //-------------------------------------------------------
107
        // Statics.
108
        //
109
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
110
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
111
        /* package */ static ExecuteMap_Default.ExecuteMap_Second Second;
112
        /* package */ static ExecuteMap_Default.ExecuteMap_Third Third;
113
        private static ExecuteMap_Default Default;
114

    
115
        static
116
        {
117
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
118
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
119
            Second = new ExecuteMap_Default.ExecuteMap_Second("ExecuteMap.Second", 2);
120
            Third = new ExecuteMap_Default.ExecuteMap_Third("ExecuteMap.Third", 3);
121
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
122
        }
123

    
124
    }
125

    
126
    protected static class ExecuteMap_Default
127
        extends ArcCADToolState
128
    {
129
    //-----------------------------------------------------------
130
    // Member methods.
131
    //
132

    
133
        protected ExecuteMap_Default(String name, int id)
134
        {
135
            super (name, id);
136
        }
137

    
138
    //-----------------------------------------------------------
139
    // Inner classse.
140
    //
141

    
142

    
143
        private static final class ExecuteMap_Initial
144
            extends ExecuteMap_Default
145
        {
146
        //-------------------------------------------------------
147
        // Member methods.
148
        //
149

    
150
            private ExecuteMap_Initial(String name, int id)
151
            {
152
                super (name, id);
153
            }
154

    
155
            protected void Entry(ArcCADToolContext context)
156
            {
157
                ArcCADTool ctxt = context.getOwner();
158

    
159
                ctxt.init();
160
                ctxt.setQuestion("ARCO" + "\n"+
161
                "Insertar primer punto");
162
                return;
163
            }
164

    
165
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
166
            {
167
                ArcCADTool ctxt = context.getOwner();
168

    
169

    
170
                (context.getState()).Exit(context);
171
                context.clearState();
172
                try
173
                {
174
                    ctxt.setQuestion("Insertar segundo punto");
175
                    ctxt.addPoint(pointX, pointY);
176
                }
177
                finally
178
                {
179
                    context.setState(ExecuteMap.First);
180
                    (context.getState()).Entry(context);
181
                }
182
                return;
183
            }
184

    
185
        //-------------------------------------------------------
186
        // Member data.
187
        //
188
        }
189

    
190
        private static final class ExecuteMap_First
191
            extends ExecuteMap_Default
192
        {
193
        //-------------------------------------------------------
194
        // Member methods.
195
        //
196

    
197
            private ExecuteMap_First(String name, int id)
198
            {
199
                super (name, id);
200
            }
201

    
202
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
203
            {
204
                ArcCADTool ctxt = context.getOwner();
205

    
206

    
207
                (context.getState()).Exit(context);
208
                context.clearState();
209
                try
210
                {
211
                    ctxt.setQuestion("Insertar ultimo punto");
212
                    ctxt.addPoint(pointX, pointY);
213
                }
214
                finally
215
                {
216
                    context.setState(ExecuteMap.Second);
217
                    (context.getState()).Entry(context);
218
                }
219
                return;
220
            }
221

    
222
        //-------------------------------------------------------
223
        // Member data.
224
        //
225
        }
226

    
227
        private static final class ExecuteMap_Second
228
            extends ExecuteMap_Default
229
        {
230
        //-------------------------------------------------------
231
        // Member methods.
232
        //
233

    
234
            private ExecuteMap_Second(String name, int id)
235
            {
236
                super (name, id);
237
            }
238

    
239
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY)
240
            {
241
                ArcCADTool ctxt = context.getOwner();
242

    
243

    
244
                (context.getState()).Exit(context);
245
                context.clearState();
246
                try
247
                {
248
                    ctxt.addPoint(pointX, pointY);
249
                    ctxt.end();
250
                }
251
                finally
252
                {
253
                    context.setState(ExecuteMap.Third);
254
                    (context.getState()).Entry(context);
255
                }
256
                return;
257
            }
258

    
259
        //-------------------------------------------------------
260
        // Member data.
261
        //
262
        }
263

    
264
        private static final class ExecuteMap_Third
265
            extends ExecuteMap_Default
266
        {
267
        //-------------------------------------------------------
268
        // Member methods.
269
        //
270

    
271
            private ExecuteMap_Third(String name, int id)
272
            {
273
                super (name, id);
274
            }
275

    
276
        //-------------------------------------------------------
277
        // Member data.
278
        //
279
        }
280

    
281
    //-----------------------------------------------------------
282
    // Member data.
283
    //
284
    }
285
}