Statistics
| Revision:

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

History | View | Annotate | Download (11.3 KB)

1

    
2
//
3
// Vicente Caballero Navarro
4

    
5

    
6
package com.iver.cit.gvsig.gui.cad.tools.smc;
7

    
8
import java.awt.event.InputEvent;
9

    
10
import com.iver.andami.PluginServices;
11
import com.iver.cit.gvsig.gui.cad.tools.MatrixCADTool;
12

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

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

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

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

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

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

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

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

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

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

    
74
    transient private MatrixCADTool _owner;
75

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

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

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

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

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

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

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

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

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

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

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

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

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

    
151
    }
152

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

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

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

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

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

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

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

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

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

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

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

    
221
                }
222
            }
223

    
224
            return;
225
        }
226

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

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

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

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

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

    
254
            }
255
            return;
256
        }
257

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

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

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

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

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

    
285
            }
286
            return;
287
        }
288

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

    
293

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

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

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

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

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

    
320

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

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

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

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

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

    
358

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

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

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

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

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

    
395

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

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

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