Statistics
| Revision:

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

History | View | Annotate | Download (8.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
import java.awt.event.InputEvent;
10
import com.iver.andami.PluginServices;
11

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

    
19
    public ArcCADToolContext(ArcCADTool owner)
20
    {
21
        super();
22

    
23
        _owner = owner;
24
        setState(Arc.FirstPoint);
25
        Arc.FirstPoint.Entry(this);
26
    }
27

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

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

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

    
53
        return ((ArcCADToolState) _state);
54
    }
55

    
56
    protected ArcCADTool getOwner()
57
    {
58
        return (_owner);
59
    }
60

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

    
65
    transient private ArcCADTool _owner;
66

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

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

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

    
83
        protected void Entry(ArcCADToolContext context) {}
84
        protected void Exit(ArcCADToolContext context) {}
85

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

    
91
        protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
92
        {
93
            Default(context);
94
        }
95

    
96
        protected void Default(ArcCADToolContext 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
    /* package */ static abstract class Arc
112
    {
113
    //-----------------------------------------------------------
114
    // Member methods.
115
    //
116

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

    
121
        //-------------------------------------------------------
122
        // Statics.
123
        //
124
        /* package */ static Arc_Default.Arc_FirstPoint FirstPoint;
125
        /* package */ static Arc_Default.Arc_SecondPoint SecondPoint;
126
        /* package */ static Arc_Default.Arc_ThirdPoint ThirdPoint;
127
        private static Arc_Default Default;
128

    
129
        static
130
        {
131
            FirstPoint = new Arc_Default.Arc_FirstPoint("Arc.FirstPoint", 0);
132
            SecondPoint = new Arc_Default.Arc_SecondPoint("Arc.SecondPoint", 1);
133
            ThirdPoint = new Arc_Default.Arc_ThirdPoint("Arc.ThirdPoint", 2);
134
            Default = new Arc_Default("Arc.Default", -1);
135
        }
136

    
137
    }
138

    
139
    protected static class Arc_Default
140
        extends ArcCADToolState
141
    {
142
    //-----------------------------------------------------------
143
    // Member methods.
144
    //
145

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

    
151
        protected void addOption(ArcCADToolContext context, String s)
152
        {
153
            ArcCADTool ctxt = context.getOwner();
154

    
155
            if (s.equals(PluginServices.getText(this,"cancel")))
156
            {
157
                boolean loopbackFlag =
158
                    context.getState().getName().equals(
159
                        Arc.FirstPoint.getName());
160

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

    
166
                context.clearState();
167
                try
168
                {
169
                    ctxt.end();
170
                }
171
                finally
172
                {
173
                    context.setState(Arc.FirstPoint);
174

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

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

    
187
            return;
188
        }
189

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

    
194

    
195
        private static final class Arc_FirstPoint
196
            extends Arc_Default
197
        {
198
        //-------------------------------------------------------
199
        // Member methods.
200
        //
201

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

    
207
            protected void Entry(ArcCADToolContext context)
208
            {
209
                ArcCADTool ctxt = context.getOwner();
210

    
211
                ctxt.setQuestion(ctxt.getName() + "\n"+
212
                PluginServices.getText(this,"insert_first_point"));
213
                ctxt.setDescription(new String[]{"cancel"});
214
                return;
215
            }
216

    
217
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
218
            {
219
                ArcCADTool ctxt = context.getOwner();
220

    
221

    
222
                (context.getState()).Exit(context);
223
                context.clearState();
224
                try
225
                {
226
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
227
                    ctxt.setDescription(new String[]{"cancel"});
228
                    ctxt.addPoint(pointX, pointY, event);
229
                }
230
                finally
231
                {
232
                    context.setState(Arc.SecondPoint);
233
                    (context.getState()).Entry(context);
234
                }
235
                return;
236
            }
237

    
238
        //-------------------------------------------------------
239
        // Member data.
240
        //
241
        }
242

    
243
        private static final class Arc_SecondPoint
244
            extends Arc_Default
245
        {
246
        //-------------------------------------------------------
247
        // Member methods.
248
        //
249

    
250
            private Arc_SecondPoint(String name, int id)
251
            {
252
                super (name, id);
253
            }
254

    
255
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
256
            {
257
                ArcCADTool ctxt = context.getOwner();
258

    
259

    
260
                (context.getState()).Exit(context);
261
                context.clearState();
262
                try
263
                {
264
                    ctxt.setQuestion(PluginServices.getText(this,"insert_last_point"));
265
                    ctxt.setDescription(new String[]{"cancel"});
266
                    ctxt.addPoint(pointX, pointY, event);
267
                }
268
                finally
269
                {
270
                    context.setState(Arc.ThirdPoint);
271
                    (context.getState()).Entry(context);
272
                }
273
                return;
274
            }
275

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

    
281
        private static final class Arc_ThirdPoint
282
            extends Arc_Default
283
        {
284
        //-------------------------------------------------------
285
        // Member methods.
286
        //
287

    
288
            private Arc_ThirdPoint(String name, int id)
289
            {
290
                super (name, id);
291
            }
292

    
293
            protected void addPoint(ArcCADToolContext context, double pointX, double pointY, InputEvent event)
294
            {
295
                ArcCADTool ctxt = context.getOwner();
296

    
297

    
298
                (context.getState()).Exit(context);
299
                context.clearState();
300
                try
301
                {
302
                    ctxt.addPoint(pointX, pointY, event);
303
                    ctxt.end();
304
                }
305
                finally
306
                {
307
                    context.setState(Arc.FirstPoint);
308
                    (context.getState()).Entry(context);
309
                }
310
                return;
311
            }
312

    
313
        //-------------------------------------------------------
314
        // Member data.
315
        //
316
        }
317

    
318
    //-----------------------------------------------------------
319
    // Member data.
320
    //
321
    }
322
}