Statistics
| Revision:

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

History | View | Annotate | Download (10.2 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.CopyCADTool;
12

    
13

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

    
21
    public CopyCADToolContext(CopyCADTool owner)
22
    {
23
        super();
24

    
25
        _owner = owner;
26
        setState(Copy.FirstPointToMove);
27
        Copy.FirstPointToMove.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 CopyCADToolState getState()
55
        throws statemap.StateUndefinedException
56
    {
57
        if (_state == null)
58
        {
59
            throw(
60
                new statemap.StateUndefinedException());
61
        }
62

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

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

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

    
75
    transient private CopyCADTool _owner;
76

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

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

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

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

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

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

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

    
111
        protected void Default(CopyCADToolContext 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 Copy
127
    {
128
    //-----------------------------------------------------------
129
    // Member methods.
130
    //
131

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

    
136
        //-------------------------------------------------------
137
        // Statics.
138
        //
139
        /* package */ static Copy_Default.Copy_FirstPointToMove FirstPointToMove;
140
        /* package */ static Copy_Default.Copy_SecondPointToMove SecondPointToMove;
141
        private static Copy_Default Default;
142

    
143
        static
144
        {
145
            FirstPointToMove = new Copy_Default.Copy_FirstPointToMove("Copy.FirstPointToMove", 0);
146
            SecondPointToMove = new Copy_Default.Copy_SecondPointToMove("Copy.SecondPointToMove", 1);
147
            Default = new Copy_Default("Copy.Default", -1);
148
        }
149

    
150
    }
151

    
152
    protected static class Copy_Default
153
        extends CopyCADToolState
154
    {
155
    //-----------------------------------------------------------
156
    // Member methods.
157
    //
158

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

    
164
        protected void addOption(CopyCADToolContext context, String s)
165
        {
166
            CopyCADTool ctxt = context.getOwner();
167

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

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

    
179
                context.clearState();
180
                try
181
                {
182
                    ctxt.end();
183
                }
184
                finally
185
                {
186
                    context.setState(Copy.FirstPointToMove);
187

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

    
193
                }
194
            }
195
            else
196
            {
197
                boolean loopbackFlag =
198
                    context.getState().getName().equals(
199
                        Copy.FirstPointToMove.getName());
200

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

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

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

    
220
                }
221
            }
222

    
223
            return;
224
        }
225

    
226
        protected void addValue(CopyCADToolContext context, double d)
227
        {
228
            CopyCADTool ctxt = context.getOwner();
229

    
230
            boolean loopbackFlag =
231
                context.getState().getName().equals(
232
                    Copy.FirstPointToMove.getName());
233

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

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

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

    
253
            }
254
            return;
255
        }
256

    
257
        protected void addPoint(CopyCADToolContext context, double pointX, double pointY, InputEvent event)
258
        {
259
            CopyCADTool ctxt = context.getOwner();
260

    
261
            boolean loopbackFlag =
262
                context.getState().getName().equals(
263
                    Copy.FirstPointToMove.getName());
264

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

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

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

    
284
            }
285
            return;
286
        }
287

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

    
292

    
293
        private static final class Copy_FirstPointToMove
294
            extends Copy_Default
295
        {
296
        //-------------------------------------------------------
297
        // Member methods.
298
        //
299

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

    
305
            protected void Entry(CopyCADToolContext context)
306
            {
307
                CopyCADTool ctxt = context.getOwner();
308

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

    
315
            protected void addPoint(CopyCADToolContext context, double pointX, double pointY, InputEvent event)
316
            {
317
                CopyCADTool ctxt = context.getOwner();
318

    
319

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

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

    
341
        private static final class Copy_SecondPointToMove
342
            extends Copy_Default
343
        {
344
        //-------------------------------------------------------
345
        // Member methods.
346
        //
347

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

    
353
            protected void addPoint(CopyCADToolContext context, double pointX, double pointY, InputEvent event)
354
            {
355
                CopyCADTool ctxt = context.getOwner();
356

    
357

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

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

    
380
    //-----------------------------------------------------------
381
    // Member data.
382
    //
383
    }
384
}