Statistics
| Revision:

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

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

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

    
19
    public RotateCADToolContext(RotateCADTool owner)
20
    {
21
        super();
22

    
23
        _owner = owner;
24
        setState(Rotate.PointMain);
25
        Rotate.PointMain.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 void addValue(double d)
45
    {
46
        _transition = "addValue";
47
        getState().addValue(this, d);
48
        _transition = "";
49
        return;
50
    }
51

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

    
61
        return ((RotateCADToolState) _state);
62
    }
63

    
64
    protected RotateCADTool getOwner()
65
    {
66
        return (_owner);
67
    }
68

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

    
73
    transient private RotateCADTool _owner;
74

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

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

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

    
91
        protected void Entry(RotateCADToolContext context) {}
92
        protected void Exit(RotateCADToolContext context) {}
93

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

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

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

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

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

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

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

    
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137
        /* package */ static Rotate_Default.Rotate_PointMain PointMain;
138
        /* package */ static Rotate_Default.Rotate_AngleOrPoint AngleOrPoint;
139
        private static Rotate_Default Default;
140

    
141
        static
142
        {
143
            PointMain = new Rotate_Default.Rotate_PointMain("Rotate.PointMain", 0);
144
            AngleOrPoint = new Rotate_Default.Rotate_AngleOrPoint("Rotate.AngleOrPoint", 1);
145
            Default = new Rotate_Default("Rotate.Default", -1);
146
        }
147

    
148
    }
149

    
150
    protected static class Rotate_Default
151
        extends RotateCADToolState
152
    {
153
    //-----------------------------------------------------------
154
    // Member methods.
155
    //
156

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

    
162
        protected void addOption(RotateCADToolContext context, String s)
163
        {
164
            RotateCADTool ctxt = context.getOwner();
165

    
166
            if (s.equals(PluginServices.getText(this,"cancel")))
167
            {
168
                boolean loopbackFlag =
169
                    context.getState().getName().equals(
170
                        Rotate.PointMain.getName());
171

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

    
177
                context.clearState();
178
                try
179
                {
180
                    ctxt.end();
181
                }
182
                finally
183
                {
184
                    context.setState(Rotate.PointMain);
185

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

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

    
198
            return;
199
        }
200

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

    
205

    
206
        private static final class Rotate_PointMain
207
            extends Rotate_Default
208
        {
209
        //-------------------------------------------------------
210
        // Member methods.
211
        //
212

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

    
218
            protected void Entry(RotateCADToolContext context)
219
            {
220
                RotateCADTool ctxt = context.getOwner();
221

    
222
                ctxt.selection();
223
                ctxt.setQuestion(PluginServices.getText(this,"insert_basis_point"));
224
                ctxt.setDescription(new String[]{"cancel"});
225
                return;
226
            }
227

    
228
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
229
            {
230
                RotateCADTool ctxt = context.getOwner();
231

    
232

    
233
                (context.getState()).Exit(context);
234
                context.clearState();
235
                try
236
                {
237
                    ctxt.setQuestion(PluginServices.getText(this,"insert_rotation_angle"));
238
                    ctxt.setDescription(new String[]{"cancel"});
239
                    ctxt.addPoint(pointX, pointY, event);
240
                }
241
                finally
242
                {
243
                    context.setState(Rotate.AngleOrPoint);
244
                    (context.getState()).Entry(context);
245
                }
246
                return;
247
            }
248

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

    
254
        private static final class Rotate_AngleOrPoint
255
            extends Rotate_Default
256
        {
257
        //-------------------------------------------------------
258
        // Member methods.
259
        //
260

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

    
266
            protected void addPoint(RotateCADToolContext context, double pointX, double pointY, InputEvent event)
267
            {
268
                RotateCADTool ctxt = context.getOwner();
269

    
270

    
271
                (context.getState()).Exit(context);
272
                context.clearState();
273
                try
274
                {
275
                    ctxt.setDescription(new String[]{"cancel"});
276
                    ctxt.addPoint(pointX, pointY, event);
277
                    ctxt.end();
278
                    ctxt.refresh();
279
                }
280
                finally
281
                {
282
                    context.setState(Rotate.PointMain);
283
                    (context.getState()).Entry(context);
284
                }
285
                return;
286
            }
287

    
288
            protected void addValue(RotateCADToolContext context, double d)
289
            {
290
                RotateCADTool ctxt = context.getOwner();
291

    
292

    
293
                (context.getState()).Exit(context);
294
                context.clearState();
295
                try
296
                {
297
                    ctxt.setDescription(new String[]{"cancel"});
298
                    ctxt.addValue(d);
299
                    ctxt.end();
300
                    ctxt.refresh();
301
                }
302
                finally
303
                {
304
                    context.setState(Rotate.PointMain);
305
                    (context.getState()).Entry(context);
306
                }
307
                return;
308
            }
309

    
310
        //-------------------------------------------------------
311
        // Member data.
312
        //
313
        }
314

    
315
    //-----------------------------------------------------------
316
    // Member data.
317
    //
318
    }
319
}