Statistics
| Revision:

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

History | View | Annotate | Download (5.78 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.PointCADTool;
9

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

    
17
    public PointCADToolContext(PointCADTool owner)
18
    {
19
        super();
20

    
21
        _owner = owner;
22
        setState(ExecuteMap.Initial);
23
        ExecuteMap.Initial.Entry(this);
24
    }
25

    
26
    public void addPoint(double pointX, double pointY)
27
    {
28
        _transition = "addPoint";
29
        getState().addPoint(this, pointX, pointY);
30
        _transition = "";
31
        return;
32
    }
33

    
34
    public PointCADToolState getState()
35
        throws statemap.StateUndefinedException
36
    {
37
        if (_state == null)
38
        {
39
            throw(
40
                new statemap.StateUndefinedException());
41
        }
42

    
43
        return ((PointCADToolState) _state);
44
    }
45

    
46
    protected PointCADTool getOwner()
47
    {
48
        return (_owner);
49
    }
50

    
51
//---------------------------------------------------------------
52
// Member data.
53
//
54

    
55
    transient private PointCADTool _owner;
56

    
57
//---------------------------------------------------------------
58
// Inner classes.
59
//
60

    
61
    public static abstract class PointCADToolState
62
        extends statemap.State
63
    {
64
    //-----------------------------------------------------------
65
    // Member methods.
66
    //
67

    
68
        protected PointCADToolState(String name, int id)
69
        {
70
            super (name, id);
71
        }
72

    
73
        protected void Entry(PointCADToolContext context) {}
74
        protected void Exit(PointCADToolContext context) {}
75

    
76
        protected void addPoint(PointCADToolContext context, double pointX, double pointY)
77
        {
78
            Default(context);
79
        }
80

    
81
        protected void Default(PointCADToolContext context)
82
        {
83
            throw (
84
                new statemap.TransitionUndefinedException(
85
                    "State: " +
86
                    context.getState().getName() +
87
                    ", Transition: " +
88
                    context.getTransition()));
89
        }
90

    
91
    //-----------------------------------------------------------
92
    // Member data.
93
    //
94
    }
95

    
96
    /* package */ static abstract class ExecuteMap
97
    {
98
    //-----------------------------------------------------------
99
    // Member methods.
100
    //
101

    
102
    //-----------------------------------------------------------
103
    // Member data.
104
    //
105

    
106
        //-------------------------------------------------------
107
        // Statics.
108
        //
109
        /* package */ static ExecuteMap_Default.ExecuteMap_Initial Initial;
110
        /* package */ static ExecuteMap_Default.ExecuteMap_First First;
111
        private static ExecuteMap_Default Default;
112

    
113
        static
114
        {
115
            Initial = new ExecuteMap_Default.ExecuteMap_Initial("ExecuteMap.Initial", 0);
116
            First = new ExecuteMap_Default.ExecuteMap_First("ExecuteMap.First", 1);
117
            Default = new ExecuteMap_Default("ExecuteMap.Default", -1);
118
        }
119

    
120
    }
121

    
122
    protected static class ExecuteMap_Default
123
        extends PointCADToolState
124
    {
125
    //-----------------------------------------------------------
126
    // Member methods.
127
    //
128

    
129
        protected ExecuteMap_Default(String name, int id)
130
        {
131
            super (name, id);
132
        }
133

    
134
    //-----------------------------------------------------------
135
    // Inner classse.
136
    //
137

    
138

    
139
        private static final class ExecuteMap_Initial
140
            extends ExecuteMap_Default
141
        {
142
        //-------------------------------------------------------
143
        // Member methods.
144
        //
145

    
146
            private ExecuteMap_Initial(String name, int id)
147
            {
148
                super (name, id);
149
            }
150

    
151
            protected void Entry(PointCADToolContext context)
152
            {
153
                PointCADTool ctxt = context.getOwner();
154

    
155
                ctxt.init();
156
                ctxt.setQuestion("PUNTO" + "\n" +
157
                "Defina el punto");
158
                return;
159
            }
160

    
161
            protected void addPoint(PointCADToolContext context, double pointX, double pointY)
162
            {
163
                PointCADTool ctxt = context.getOwner();
164

    
165

    
166
                (context.getState()).Exit(context);
167
                context.clearState();
168
                try
169
                {
170
                    ctxt.setQuestion("Insertar punto");
171
                    ctxt.addPoint(pointX, pointY);
172
                }
173
                finally
174
                {
175
                    context.setState(ExecuteMap.First);
176
                    (context.getState()).Entry(context);
177
                }
178
                return;
179
            }
180

    
181
        //-------------------------------------------------------
182
        // Member data.
183
        //
184
        }
185

    
186
        private static final class ExecuteMap_First
187
            extends ExecuteMap_Default
188
        {
189
        //-------------------------------------------------------
190
        // Member methods.
191
        //
192

    
193
            private ExecuteMap_First(String name, int id)
194
            {
195
                super (name, id);
196
            }
197

    
198
            protected void addPoint(PointCADToolContext context, double pointX, double pointY)
199
            {
200
                PointCADTool ctxt = context.getOwner();
201

    
202
                PointCADToolState endState = context.getState();
203

    
204
                context.clearState();
205
                try
206
                {
207
                    ctxt.setQuestion("Insertar punto");
208
                    ctxt.addPoint(pointX, pointY);
209
                }
210
                finally
211
                {
212
                    context.setState(endState);
213
                }
214
                return;
215
            }
216

    
217
        //-------------------------------------------------------
218
        // Member data.
219
        //
220
        }
221

    
222
    //-----------------------------------------------------------
223
    // Member data.
224
    //
225
    }
226
}