Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / smc / MatrixCADToolContext.java @ 29616

History | View | Annotate | Download (11.3 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

    
6
package org.gvsig.editing.gui.cad.tools.smc;
7

    
8
import java.awt.event.InputEvent;
9

    
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.editing.gui.cad.tools.MatrixCADTool;
12

    
13

    
14
public final class MatrixCADToolContext
15
    extends statemap.FSMContext
16
{
17
//---------------------------------------------------------------
18
// Member methods.
19
//
20

    
21
    public MatrixCADToolContext(MatrixCADTool owner)
22
    {
23
        super();
24

    
25
        _owner = owner;
26
        setState(Matrix.Start);
27
        Matrix.Start.Entry(this);
28
    }
29

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

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

    
46
    public void addValue(double d)
47
    {
48
        _transition = "addValue";
49
        getState().addValue(this, d);
50
        _transition = "";
51
        return;
52
    }
53

    
54
    public MatrixCADToolState getState()
55
        throws statemap.StateUndefinedException
56
    {
57
        if (_state == null)
58
        {
59
            throw(
60
                new statemap.StateUndefinedException());
61
        }
62

    
63
        return ((MatrixCADToolState) _state);
64
    }
65

    
66
    protected MatrixCADTool getOwner()
67
    {
68
        return (_owner);
69
    }
70

    
71
//---------------------------------------------------------------
72
// Member data.
73
//
74

    
75
    transient private MatrixCADTool _owner;
76

    
77
//---------------------------------------------------------------
78
// Inner classes.
79
//
80

    
81
    public static abstract class MatrixCADToolState
82
        extends statemap.State
83
    {
84
    //-----------------------------------------------------------
85
    // Member methods.
86
    //
87

    
88
        protected MatrixCADToolState(String name, int id)
89
        {
90
            super (name, id);
91
        }
92

    
93
        protected void Entry(MatrixCADToolContext context) {}
94
        protected void Exit(MatrixCADToolContext context) {}
95

    
96
        protected void addOption(MatrixCADToolContext context, String s)
97
        {
98
            Default(context);
99
        }
100

    
101
        protected void addPoint(MatrixCADToolContext context, double pointX, double pointY, InputEvent event)
102
        {
103
            Default(context);
104
        }
105

    
106
        protected void addValue(MatrixCADToolContext context, double d)
107
        {
108
            Default(context);
109
        }
110

    
111
        protected void Default(MatrixCADToolContext context)
112
        {
113
            throw (
114
                new statemap.TransitionUndefinedException(
115
                    "State: " +
116
                    context.getState().getName() +
117
                    ", Transition: " +
118
                    context.getTransition()));
119
        }
120

    
121
    //-----------------------------------------------------------
122
    // Member data.
123
    //
124
    }
125

    
126
    /* package */ static abstract class Matrix
127
    {
128
    //-----------------------------------------------------------
129
    // Member methods.
130
    //
131

    
132
    //-----------------------------------------------------------
133
    // Member data.
134
    //
135

    
136
        //-------------------------------------------------------
137
        // Statics.
138
        //
139
        /* package */ static Matrix_Default.Matrix_Start Start;
140
        /* package */ static Matrix_Default.Matrix_FirstPoint FirstPoint;
141
        /* package */ static Matrix_Default.Matrix_SecondPoint SecondPoint;
142
        private static Matrix_Default Default;
143

    
144
        static
145
        {
146
            Start = new Matrix_Default.Matrix_Start("Matrix.Start", 0);
147
            FirstPoint = new Matrix_Default.Matrix_FirstPoint("Matrix.FirstPoint", 1);
148
            SecondPoint = new Matrix_Default.Matrix_SecondPoint("Matrix.SecondPoint", 2);
149
            Default = new Matrix_Default("Matrix.Default", -1);
150
        }
151

    
152
    }
153

    
154
    protected static class Matrix_Default
155
        extends MatrixCADToolState
156
    {
157
    //-----------------------------------------------------------
158
    // Member methods.
159
    //
160

    
161
        protected Matrix_Default(String name, int id)
162
        {
163
            super (name, id);
164
        }
165

    
166
        protected void addOption(MatrixCADToolContext context, String s)
167
        {
168
            MatrixCADTool ctxt = context.getOwner();
169

    
170
            if (s.equals(PluginServices.getText(this,"cancel")))
171
            {
172
                boolean loopbackFlag =
173
                    context.getState().getName().equals(
174
                        Matrix.Start.getName());
175

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

    
181
                context.clearState();
182
                try
183
                {
184
                    ctxt.end();
185
                }
186
                finally
187
                {
188
                    context.setState(Matrix.Start);
189

    
190
                    if (loopbackFlag == false)
191
                    {
192
                        (context.getState()).Entry(context);
193
                    }
194

    
195
                }
196
            }
197
            else
198
            {
199
                boolean loopbackFlag =
200
                    context.getState().getName().equals(
201
                        Matrix.Start.getName());
202

    
203
                if (loopbackFlag == false)
204
                {
205
                    (context.getState()).Exit(context);
206
                }
207

    
208
                context.clearState();
209
                try
210
                {
211
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
212
                }
213
                finally
214
                {
215
                    context.setState(Matrix.Start);
216

    
217
                    if (loopbackFlag == false)
218
                    {
219
                        (context.getState()).Entry(context);
220
                    }
221

    
222
                }
223
            }
224

    
225
            return;
226
        }
227

    
228
        protected void addValue(MatrixCADToolContext context, double d)
229
        {
230
            MatrixCADTool ctxt = context.getOwner();
231

    
232
            boolean loopbackFlag =
233
                context.getState().getName().equals(
234
                    Matrix.Start.getName());
235

    
236
            if (loopbackFlag == false)
237
            {
238
                (context.getState()).Exit(context);
239
            }
240

    
241
            context.clearState();
242
            try
243
            {
244
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
245
            }
246
            finally
247
            {
248
                context.setState(Matrix.Start);
249

    
250
                if (loopbackFlag == false)
251
                {
252
                    (context.getState()).Entry(context);
253
                }
254

    
255
            }
256
            return;
257
        }
258

    
259
        protected void addPoint(MatrixCADToolContext context, double pointX, double pointY, InputEvent event)
260
        {
261
            MatrixCADTool ctxt = context.getOwner();
262

    
263
            boolean loopbackFlag =
264
                context.getState().getName().equals(
265
                    Matrix.Start.getName());
266

    
267
            if (loopbackFlag == false)
268
            {
269
                (context.getState()).Exit(context);
270
            }
271

    
272
            context.clearState();
273
            try
274
            {
275
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
276
            }
277
            finally
278
            {
279
                context.setState(Matrix.Start);
280

    
281
                if (loopbackFlag == false)
282
                {
283
                    (context.getState()).Entry(context);
284
                }
285

    
286
            }
287
            return;
288
        }
289

    
290
    //-----------------------------------------------------------
291
    // Inner classse.
292
    //
293

    
294

    
295
        private static final class Matrix_Start
296
            extends Matrix_Default
297
        {
298
        //-------------------------------------------------------
299
        // Member methods.
300
        //
301

    
302
            private Matrix_Start(String name, int id)
303
            {
304
                super (name, id);
305
            }
306

    
307
            protected void Entry(MatrixCADToolContext context)
308
            {
309
                MatrixCADTool ctxt = context.getOwner();
310

    
311
                ctxt.selection();
312
                ctxt.setQuestion(PluginServices.getText(this,"insert_first_point"));
313
                ctxt.setDescription(new String[]{"cancel"});
314
                return;
315
            }
316

    
317
            protected void addPoint(MatrixCADToolContext context, double pointX, double pointY, InputEvent event)
318
            {
319
                MatrixCADTool ctxt = context.getOwner();
320

    
321

    
322
                (context.getState()).Exit(context);
323
                context.clearState();
324
                try
325
                {
326
                    ctxt.setQuestion(PluginServices.getText(this,"insert_second_point"));
327
                    ctxt.setDescription(new String[]{"cancel"});
328
                    ctxt.addPoint(pointX, pointY, event);
329
                }
330
                finally
331
                {
332
                    context.setState(Matrix.SecondPoint);
333
                    (context.getState()).Entry(context);
334
                }
335
                return;
336
            }
337

    
338
        //-------------------------------------------------------
339
        // Member data.
340
        //
341
        }
342

    
343
        private static final class Matrix_FirstPoint
344
            extends Matrix_Default
345
        {
346
        //-------------------------------------------------------
347
        // Member methods.
348
        //
349

    
350
            private Matrix_FirstPoint(String name, int id)
351
            {
352
                super (name, id);
353
            }
354

    
355
            protected void addPoint(MatrixCADToolContext context, double pointX, double pointY, InputEvent event)
356
            {
357
                MatrixCADTool ctxt = context.getOwner();
358

    
359

    
360
                (context.getState()).Exit(context);
361
                context.clearState();
362
                try
363
                {
364
                    ctxt.setDescription(new String[]{"cancel"});
365
                    ctxt.addPoint(pointX, pointY, event);
366
                }
367
                finally
368
                {
369
                    context.setState(Matrix.SecondPoint);
370
                    (context.getState()).Entry(context);
371
                }
372
                return;
373
            }
374

    
375
        //-------------------------------------------------------
376
        // Member data.
377
        //
378
        }
379

    
380
        private static final class Matrix_SecondPoint
381
            extends Matrix_Default
382
        {
383
        //-------------------------------------------------------
384
        // Member methods.
385
        //
386

    
387
            private Matrix_SecondPoint(String name, int id)
388
            {
389
                super (name, id);
390
            }
391

    
392
            protected void addPoint(MatrixCADToolContext context, double pointX, double pointY, InputEvent event)
393
            {
394
                MatrixCADTool ctxt = context.getOwner();
395

    
396

    
397
                (context.getState()).Exit(context);
398
                context.clearState();
399
                try
400
                {
401
                    ctxt.setDescription(new String[]{"cancel"});
402
                    ctxt.addPoint(pointX, pointY, event);
403
                    ctxt.endMatrix();
404
                }
405
                finally
406
                {
407
                    context.setState(Matrix.FirstPoint);
408
                    (context.getState()).Entry(context);
409
                }
410
                return;
411
            }
412

    
413
        //-------------------------------------------------------
414
        // Member data.
415
        //
416
        }
417

    
418
    //-----------------------------------------------------------
419
    // Member data.
420
    //
421
    }
422
}