Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / tools / smc / JoinCADToolContext.java @ 40557

History | View | Annotate | Download (8.83 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
//
26
// Vicente Caballero Navarro
27

    
28

    
29
package org.gvsig.editing.gui.cad.tools.smc;
30

    
31
import java.awt.event.InputEvent;
32

    
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.editing.gui.cad.tools.JoinCADTool;
35

    
36

    
37
public final class JoinCADToolContext
38
    extends statemap.FSMContext
39
{
40
//---------------------------------------------------------------
41
// Member methods.
42
//
43

    
44
    public JoinCADToolContext(JoinCADTool owner)
45
    {
46
        super();
47

    
48
        _owner = owner;
49
        setState(Join.Execute);
50
        Join.Execute.Entry(this);
51
    }
52

    
53
    public void addOption(String s)
54
    {
55
        _transition = "addOption";
56
        getState().addOption(this, s);
57
        _transition = "";
58
        return;
59
    }
60

    
61
    public void addPoint(double pointX, double pointY, InputEvent event)
62
    {
63
        _transition = "addPoint";
64
        getState().addPoint(this, pointX, pointY, event);
65
        _transition = "";
66
        return;
67
    }
68

    
69
    public void addValue(double d)
70
    {
71
        _transition = "addValue";
72
        getState().addValue(this, d);
73
        _transition = "";
74
        return;
75
    }
76

    
77
    public JoinCADToolState getState()
78
        throws statemap.StateUndefinedException
79
    {
80
        if (_state == null)
81
        {
82
            throw(
83
                new statemap.StateUndefinedException());
84
        }
85

    
86
        return ((JoinCADToolState) _state);
87
    }
88

    
89
    protected JoinCADTool getOwner()
90
    {
91
        return (_owner);
92
    }
93

    
94
//---------------------------------------------------------------
95
// Member data.
96
//
97

    
98
    transient private JoinCADTool _owner;
99

    
100
//---------------------------------------------------------------
101
// Inner classes.
102
//
103

    
104
    public static abstract class JoinCADToolState
105
        extends statemap.State
106
    {
107
    //-----------------------------------------------------------
108
    // Member methods.
109
    //
110

    
111
        protected JoinCADToolState(String name, int id)
112
        {
113
            super (name, id);
114
        }
115

    
116
        protected void Entry(JoinCADToolContext context) {}
117
        protected void Exit(JoinCADToolContext context) {}
118

    
119
        protected void addOption(JoinCADToolContext context, String s)
120
        {
121
            Default(context);
122
        }
123

    
124
        protected void addPoint(JoinCADToolContext context, double pointX, double pointY, InputEvent event)
125
        {
126
            Default(context);
127
        }
128

    
129
        protected void addValue(JoinCADToolContext context, double d)
130
        {
131
            Default(context);
132
        }
133

    
134
        protected void Default(JoinCADToolContext context)
135
        {
136
            throw (
137
                new statemap.TransitionUndefinedException(
138
                    "State: " +
139
                    context.getState().getName() +
140
                    ", Transition: " +
141
                    context.getTransition()));
142
        }
143

    
144
    //-----------------------------------------------------------
145
    // Member data.
146
    //
147
    }
148

    
149
    /* package */ static abstract class Join
150
    {
151
    //-----------------------------------------------------------
152
    // Member methods.
153
    //
154

    
155
    //-----------------------------------------------------------
156
    // Member data.
157
    //
158

    
159
        //-------------------------------------------------------
160
        // Statics.
161
        //
162
        /* package */ static Join_Default.Join_Execute Execute;
163
        private static Join_Default Default;
164

    
165
        static
166
        {
167
            Execute = new Join_Default.Join_Execute("Join.Execute", 0);
168
            Default = new Join_Default("Join.Default", -1);
169
        }
170

    
171
    }
172

    
173
    protected static class Join_Default
174
        extends JoinCADToolState
175
    {
176
    //-----------------------------------------------------------
177
    // Member methods.
178
    //
179

    
180
        protected Join_Default(String name, int id)
181
        {
182
            super (name, id);
183
        }
184

    
185
        protected void addOption(JoinCADToolContext context, String s)
186
        {
187
            JoinCADTool ctxt = context.getOwner();
188

    
189
            if (s.equals(PluginServices.getText(this,"cancel")))
190
            {
191
                boolean loopbackFlag =
192
                    context.getState().getName().equals(
193
                        Join.Execute.getName());
194

    
195
                if (loopbackFlag == false)
196
                {
197
                    (context.getState()).Exit(context);
198
                }
199

    
200
                context.clearState();
201
                try
202
                {
203
                    ctxt.end();
204
                }
205
                finally
206
                {
207
                    context.setState(Join.Execute);
208

    
209
                    if (loopbackFlag == false)
210
                    {
211
                        (context.getState()).Entry(context);
212
                    }
213

    
214
                }
215
            }
216
            else
217
            {
218
                boolean loopbackFlag =
219
                    context.getState().getName().equals(
220
                        Join.Execute.getName());
221

    
222
                if (loopbackFlag == false)
223
                {
224
                    (context.getState()).Exit(context);
225
                }
226

    
227
                context.clearState();
228
                try
229
                {
230
                    ctxt.throwOptionException(PluginServices.getText(this,"incorrect_option"), s);
231
                }
232
                finally
233
                {
234
                    context.setState(Join.Execute);
235

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

    
241
                }
242
            }
243

    
244
            return;
245
        }
246

    
247
        protected void addValue(JoinCADToolContext context, double d)
248
        {
249
            JoinCADTool ctxt = context.getOwner();
250

    
251
            boolean loopbackFlag =
252
                context.getState().getName().equals(
253
                    Join.Execute.getName());
254

    
255
            if (loopbackFlag == false)
256
            {
257
                (context.getState()).Exit(context);
258
            }
259

    
260
            context.clearState();
261
            try
262
            {
263
                ctxt.throwValueException(PluginServices.getText(this,"incorrect_value"), d);
264
            }
265
            finally
266
            {
267
                context.setState(Join.Execute);
268

    
269
                if (loopbackFlag == false)
270
                {
271
                    (context.getState()).Entry(context);
272
                }
273

    
274
            }
275
            return;
276
        }
277

    
278
        protected void addPoint(JoinCADToolContext context, double pointX, double pointY, InputEvent event)
279
        {
280
            JoinCADTool ctxt = context.getOwner();
281

    
282
            boolean loopbackFlag =
283
                context.getState().getName().equals(
284
                    Join.Execute.getName());
285

    
286
            if (loopbackFlag == false)
287
            {
288
                (context.getState()).Exit(context);
289
            }
290

    
291
            context.clearState();
292
            try
293
            {
294
                ctxt.throwPointException(PluginServices.getText(this,"incorrect_point"), pointX, pointY);
295
            }
296
            finally
297
            {
298
                context.setState(Join.Execute);
299

    
300
                if (loopbackFlag == false)
301
                {
302
                    (context.getState()).Entry(context);
303
                }
304

    
305
            }
306
            return;
307
        }
308

    
309
    //-----------------------------------------------------------
310
    // Inner classse.
311
    //
312

    
313

    
314
        private static final class Join_Execute
315
            extends Join_Default
316
        {
317
        //-------------------------------------------------------
318
        // Member methods.
319
        //
320

    
321
            private Join_Execute(String name, int id)
322
            {
323
                super (name, id);
324
            }
325

    
326
            protected void Entry(JoinCADToolContext context)
327
            {
328
                JoinCADTool ctxt = context.getOwner();
329

    
330
                ctxt.join();
331
                ctxt.end();
332
                return;
333
            }
334

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

    
340
    //-----------------------------------------------------------
341
    // Member data.
342
    //
343
    }
344
}