Statistics
| Revision:

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

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.LineCADTool;
9
import java.awt.event.InputEvent;
10

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

    
18
    public LineCADToolContext(LineCADTool owner)
19
    {
20
        super();
21

    
22
        _owner = owner;
23
        setState(Line.FirstPoint);
24
        Line.FirstPoint.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, InputEvent event)
36
    {
37
        _transition = "addPoint";
38
        getState().addPoint(this, pointX, pointY, event);
39
        _transition = "";
40
        return;
41
    }
42

    
43
    public void addValue(double d)
44
    {
45
        _transition = "addValue";
46
        getState().addValue(this, d);
47
        _transition = "";
48
        return;
49
    }
50

    
51
    public LineCADToolState getState()
52
        throws statemap.StateUndefinedException
53
    {
54
        if (_state == null)
55
        {
56
            throw(
57
                new statemap.StateUndefinedException());
58
        }
59

    
60
        return ((LineCADToolState) _state);
61
    }
62

    
63
    protected LineCADTool getOwner()
64
    {
65
        return (_owner);
66
    }
67

    
68
//---------------------------------------------------------------
69
// Member data.
70
//
71

    
72
    transient private LineCADTool _owner;
73

    
74
//---------------------------------------------------------------
75
// Inner classes.
76
//
77

    
78
    public static abstract class LineCADToolState
79
        extends statemap.State
80
    {
81
    //-----------------------------------------------------------
82
    // Member methods.
83
    //
84

    
85
        protected LineCADToolState(String name, int id)
86
        {
87
            super (name, id);
88
        }
89

    
90
        protected void Entry(LineCADToolContext context) {}
91
        protected void Exit(LineCADToolContext context) {}
92

    
93
        protected void addOption(LineCADToolContext context, String s)
94
        {
95
            Default(context);
96
        }
97

    
98
        protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
99
        {
100
            Default(context);
101
        }
102

    
103
        protected void addValue(LineCADToolContext context, double d)
104
        {
105
            Default(context);
106
        }
107

    
108
        protected void Default(LineCADToolContext context)
109
        {
110
            throw (
111
                new statemap.TransitionUndefinedException(
112
                    "State: " +
113
                    context.getState().getName() +
114
                    ", Transition: " +
115
                    context.getTransition()));
116
        }
117

    
118
    //-----------------------------------------------------------
119
    // Member data.
120
    //
121
    }
122

    
123
    /* package */ static abstract class Line
124
    {
125
    //-----------------------------------------------------------
126
    // Member methods.
127
    //
128

    
129
    //-----------------------------------------------------------
130
    // Member data.
131
    //
132

    
133
        //-------------------------------------------------------
134
        // Statics.
135
        //
136
        /* package */ static Line_Default.Line_FirstPoint FirstPoint;
137
        /* package */ static Line_Default.Line_SecondPointOrAngle SecondPointOrAngle;
138
        /* package */ static Line_Default.Line_LenghtOrPoint LenghtOrPoint;
139
        private static Line_Default Default;
140

    
141
        static
142
        {
143
            FirstPoint = new Line_Default.Line_FirstPoint("Line.FirstPoint", 0);
144
            SecondPointOrAngle = new Line_Default.Line_SecondPointOrAngle("Line.SecondPointOrAngle", 1);
145
            LenghtOrPoint = new Line_Default.Line_LenghtOrPoint("Line.LenghtOrPoint", 2);
146
            Default = new Line_Default("Line.Default", -1);
147
        }
148

    
149
    }
150

    
151
    protected static class Line_Default
152
        extends LineCADToolState
153
    {
154
    //-----------------------------------------------------------
155
    // Member methods.
156
    //
157

    
158
        protected Line_Default(String name, int id)
159
        {
160
            super (name, id);
161
        }
162

    
163
        protected void addOption(LineCADToolContext context, String s)
164
        {
165
            LineCADTool ctxt = context.getOwner();
166

    
167
            if (s.equals("Cancelar"))
168
            {
169
                boolean loopbackFlag =
170
                    context.getState().getName().equals(
171
                        Line.FirstPoint.getName());
172

    
173
                if (loopbackFlag == false)
174
                {
175
                    (context.getState()).Exit(context);
176
                }
177

    
178
                context.clearState();
179
                try
180
                {
181
                    ctxt.end();
182
                }
183
                finally
184
                {
185
                    context.setState(Line.FirstPoint);
186

    
187
                    if (loopbackFlag == false)
188
                    {
189
                        (context.getState()).Entry(context);
190
                    }
191

    
192
                }
193
            }
194
            else
195
            {
196
                super.addOption(context, s);
197
            }
198

    
199
            return;
200
        }
201

    
202
    //-----------------------------------------------------------
203
    // Inner classse.
204
    //
205

    
206

    
207
        private static final class Line_FirstPoint
208
            extends Line_Default
209
        {
210
        //-------------------------------------------------------
211
        // Member methods.
212
        //
213

    
214
            private Line_FirstPoint(String name, int id)
215
            {
216
                super (name, id);
217
            }
218

    
219
            protected void Entry(LineCADToolContext context)
220
            {
221
                LineCADTool ctxt = context.getOwner();
222

    
223
                ctxt.setQuestion("LINEA" + "\n" +
224
                "Insertar primer punto");
225
                ctxt.setDescription(new String[]{"Cancelar"});
226
                return;
227
            }
228

    
229
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
230
            {
231
                LineCADTool ctxt = context.getOwner();
232

    
233

    
234
                (context.getState()).Exit(context);
235
                context.clearState();
236
                try
237
                {
238
                    ctxt.setQuestion("Insertar segundo punto o angulo");
239
                    ctxt.setDescription(new String[]{"Cancelar"});
240
                    ctxt.addPoint(pointX, pointY, event);
241
                }
242
                finally
243
                {
244
                    context.setState(Line.SecondPointOrAngle);
245
                    (context.getState()).Entry(context);
246
                }
247
                return;
248
            }
249

    
250
        //-------------------------------------------------------
251
        // Member data.
252
        //
253
        }
254

    
255
        private static final class Line_SecondPointOrAngle
256
            extends Line_Default
257
        {
258
        //-------------------------------------------------------
259
        // Member methods.
260
        //
261

    
262
            private Line_SecondPointOrAngle(String name, int id)
263
            {
264
                super (name, id);
265
            }
266

    
267
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
268
            {
269
                LineCADTool ctxt = context.getOwner();
270

    
271
                LineCADToolState endState = context.getState();
272

    
273
                context.clearState();
274
                try
275
                {
276
                    ctxt.setQuestion("Insertar segundo punto o angulo");
277
                    ctxt.setDescription(new String[]{"Cancelar"});
278
                    ctxt.addPoint(pointX, pointY, event);
279
                }
280
                finally
281
                {
282
                    context.setState(endState);
283
                }
284
                return;
285
            }
286

    
287
            protected void addValue(LineCADToolContext context, double d)
288
            {
289
                LineCADTool ctxt = context.getOwner();
290

    
291

    
292
                (context.getState()).Exit(context);
293
                context.clearState();
294
                try
295
                {
296
                    ctxt.setQuestion("Insertar longitud o punto");
297
                    ctxt.setDescription(new String[]{"Cancelar"});
298
                    ctxt.addValue(d);
299
                }
300
                finally
301
                {
302
                    context.setState(Line.LenghtOrPoint);
303
                    (context.getState()).Entry(context);
304
                }
305
                return;
306
            }
307

    
308
        //-------------------------------------------------------
309
        // Member data.
310
        //
311
        }
312

    
313
        private static final class Line_LenghtOrPoint
314
            extends Line_Default
315
        {
316
        //-------------------------------------------------------
317
        // Member methods.
318
        //
319

    
320
            private Line_LenghtOrPoint(String name, int id)
321
            {
322
                super (name, id);
323
            }
324

    
325
            protected void addPoint(LineCADToolContext context, double pointX, double pointY, InputEvent event)
326
            {
327
                LineCADTool ctxt = context.getOwner();
328

    
329

    
330
                (context.getState()).Exit(context);
331
                context.clearState();
332
                try
333
                {
334
                    ctxt.setQuestion("Insertar segundo punto o angulo");
335
                    ctxt.setDescription(new String[]{"Cancelar"});
336
                    ctxt.addPoint(pointX, pointY, event);
337
                }
338
                finally
339
                {
340
                    context.setState(Line.SecondPointOrAngle);
341
                    (context.getState()).Entry(context);
342
                }
343
                return;
344
            }
345

    
346
            protected void addValue(LineCADToolContext context, double d)
347
            {
348
                LineCADTool ctxt = context.getOwner();
349

    
350

    
351
                (context.getState()).Exit(context);
352
                context.clearState();
353
                try
354
                {
355
                    ctxt.setQuestion("Insertar segundo punto o angulo");
356
                    ctxt.setDescription(new String[]{"Cancelar"});
357
                    ctxt.addValue(d);
358
                }
359
                finally
360
                {
361
                    context.setState(Line.SecondPointOrAngle);
362
                    (context.getState()).Entry(context);
363
                }
364
                return;
365
            }
366

    
367
        //-------------------------------------------------------
368
        // Member data.
369
        //
370
        }
371

    
372
    //-----------------------------------------------------------
373
    // Member data.
374
    //
375
    }
376
}