Statistics
| Revision:

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

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

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

    
19
    public ScaleCADToolContext(ScaleCADTool owner)
20
    {
21
        super();
22

    
23
        _owner = owner;
24
        setState(Scale.PointMain);
25
        Scale.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 ScaleCADToolState getState()
53
        throws statemap.StateUndefinedException
54
    {
55
        if (_state == null)
56
        {
57
            throw(
58
                new statemap.StateUndefinedException());
59
        }
60

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

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

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

    
73
    transient private ScaleCADTool _owner;
74

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

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

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

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

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

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

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

    
109
        protected void Default(ScaleCADToolContext 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 Scale
125
    {
126
    //-----------------------------------------------------------
127
    // Member methods.
128
    //
129

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

    
134
        //-------------------------------------------------------
135
        // Statics.
136
        //
137
        /* package */ static Scale_Default.Scale_PointMain PointMain;
138
        /* package */ static Scale_Default.Scale_ScaleFactorOrReference ScaleFactorOrReference;
139
        /* package */ static Scale_Default.Scale_PointOriginOrScaleFactor PointOriginOrScaleFactor;
140
        /* package */ static Scale_Default.Scale_EndPointReference EndPointReference;
141
        /* package */ static Scale_Default.Scale_OriginPointScale OriginPointScale;
142
        /* package */ static Scale_Default.Scale_EndPointScale EndPointScale;
143
        private static Scale_Default Default;
144

    
145
        static
146
        {
147
            PointMain = new Scale_Default.Scale_PointMain("Scale.PointMain", 0);
148
            ScaleFactorOrReference = new Scale_Default.Scale_ScaleFactorOrReference("Scale.ScaleFactorOrReference", 1);
149
            PointOriginOrScaleFactor = new Scale_Default.Scale_PointOriginOrScaleFactor("Scale.PointOriginOrScaleFactor", 2);
150
            EndPointReference = new Scale_Default.Scale_EndPointReference("Scale.EndPointReference", 3);
151
            OriginPointScale = new Scale_Default.Scale_OriginPointScale("Scale.OriginPointScale", 4);
152
            EndPointScale = new Scale_Default.Scale_EndPointScale("Scale.EndPointScale", 5);
153
            Default = new Scale_Default("Scale.Default", -1);
154
        }
155

    
156
    }
157

    
158
    protected static class Scale_Default
159
        extends ScaleCADToolState
160
    {
161
    //-----------------------------------------------------------
162
    // Member methods.
163
    //
164

    
165
        protected Scale_Default(String name, int id)
166
        {
167
            super (name, id);
168
        }
169

    
170
        protected void addOption(ScaleCADToolContext context, String s)
171
        {
172
            ScaleCADTool ctxt = context.getOwner();
173

    
174
            if (s.equals(PluginServices.getText(this,"cancel")))
175
            {
176
                boolean loopbackFlag =
177
                    context.getState().getName().equals(
178
                        Scale.PointMain.getName());
179

    
180
                if (loopbackFlag == false)
181
                {
182
                    (context.getState()).Exit(context);
183
                }
184

    
185
                context.clearState();
186
                try
187
                {
188
                    ctxt.end();
189
                }
190
                finally
191
                {
192
                    context.setState(Scale.PointMain);
193

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

    
199
                }
200
            }
201
            else
202
            {
203
                super.addOption(context, s);
204
            }
205

    
206
            return;
207
        }
208

    
209
    //-----------------------------------------------------------
210
    // Inner classse.
211
    //
212

    
213

    
214
        private static final class Scale_PointMain
215
            extends Scale_Default
216
        {
217
        //-------------------------------------------------------
218
        // Member methods.
219
        //
220

    
221
            private Scale_PointMain(String name, int id)
222
            {
223
                super (name, id);
224
            }
225

    
226
            protected void Entry(ScaleCADToolContext context)
227
            {
228
                ScaleCADTool ctxt = context.getOwner();
229

    
230
                ctxt.selection();
231
                ctxt.setQuestion(PluginServices.getText(this,"insert_basis_point"));
232
                ctxt.setDescription(new String[]{"cancel"});
233
                return;
234
            }
235

    
236
            protected void addPoint(ScaleCADToolContext context, double pointX, double pointY, InputEvent event)
237
            {
238
                ScaleCADTool ctxt = context.getOwner();
239

    
240

    
241
                (context.getState()).Exit(context);
242
                context.clearState();
243
                try
244
                {
245
                    ctxt.setQuestion(PluginServices.getText(this,"insert_factor_or_reference"));
246
                    ctxt.setDescription(new String[]{"reference", "cancel"});
247
                    ctxt.addPoint(pointX, pointY, event);
248
                }
249
                finally
250
                {
251
                    context.setState(Scale.ScaleFactorOrReference);
252
                    (context.getState()).Entry(context);
253
                }
254
                return;
255
            }
256

    
257
        //-------------------------------------------------------
258
        // Member data.
259
        //
260
        }
261

    
262
        private static final class Scale_ScaleFactorOrReference
263
            extends Scale_Default
264
        {
265
        //-------------------------------------------------------
266
        // Member methods.
267
        //
268

    
269
            private Scale_ScaleFactorOrReference(String name, int id)
270
            {
271
                super (name, id);
272
            }
273

    
274
            protected void addOption(ScaleCADToolContext context, String s)
275
            {
276
                ScaleCADTool ctxt = context.getOwner();
277

    
278
                if (s.equals(null) || s.equals(""))
279
                {
280

    
281
                    (context.getState()).Exit(context);
282
                    context.clearState();
283
                    try
284
                    {
285
                        ctxt.addOption(s);
286
                        ctxt.end();
287
                        ctxt.refresh();
288
                    }
289
                    finally
290
                    {
291
                        context.setState(Scale.PointMain);
292
                        (context.getState()).Entry(context);
293
                    }
294
                }
295
                else if (s.equals("R") || s.equals("r") || s.equals(PluginServices.getText(this,"reference")))
296
                {
297

    
298
                    (context.getState()).Exit(context);
299
                    context.clearState();
300
                    try
301
                    {
302
                        ctxt.setQuestion(PluginServices.getText(this,"insert_reference_point_or_factor"));
303
                        ctxt.setDescription(new String[]{"factor", "cancel"});
304
                    }
305
                    finally
306
                    {
307
                        context.setState(Scale.PointOriginOrScaleFactor);
308
                        (context.getState()).Entry(context);
309
                    }
310
                }                else
311
                {
312
                    super.addOption(context, s);
313
                }
314

    
315
                return;
316
            }
317

    
318
            protected void addPoint(ScaleCADToolContext context, double pointX, double pointY, InputEvent event)
319
            {
320
                ScaleCADTool ctxt = context.getOwner();
321

    
322

    
323
                (context.getState()).Exit(context);
324
                context.clearState();
325
                try
326
                {
327
                    ctxt.addPoint(pointX, pointY, event);
328
                    ctxt.end();
329
                    ctxt.refresh();
330
                }
331
                finally
332
                {
333
                    context.setState(Scale.PointMain);
334
                    (context.getState()).Entry(context);
335
                }
336
                return;
337
            }
338

    
339
            protected void addValue(ScaleCADToolContext context, double d)
340
            {
341
                ScaleCADTool ctxt = context.getOwner();
342

    
343

    
344
                (context.getState()).Exit(context);
345
                context.clearState();
346
                try
347
                {
348
                    ctxt.addValue(d);
349
                    ctxt.end();
350
                    ctxt.refresh();
351
                }
352
                finally
353
                {
354
                    context.setState(Scale.PointMain);
355
                    (context.getState()).Entry(context);
356
                }
357
                return;
358
            }
359

    
360
        //-------------------------------------------------------
361
        // Member data.
362
        //
363
        }
364

    
365
        private static final class Scale_PointOriginOrScaleFactor
366
            extends Scale_Default
367
        {
368
        //-------------------------------------------------------
369
        // Member methods.
370
        //
371

    
372
            private Scale_PointOriginOrScaleFactor(String name, int id)
373
            {
374
                super (name, id);
375
            }
376

    
377
            protected void addOption(ScaleCADToolContext context, String s)
378
            {
379
                ScaleCADTool ctxt = context.getOwner();
380

    
381
                if (s.equals("F") || s.equals("f") || s.equals(PluginServices.getText(this,"factor")))
382
                {
383

    
384
                    (context.getState()).Exit(context);
385
                    context.clearState();
386
                    try
387
                    {
388
                        ctxt.setQuestion(PluginServices.getText(this,"insert_factor_or_reference"));
389
                        ctxt.setDescription(new String[]{"reference", "cancel"});
390
                        ctxt.addOption(s);
391
                    }
392
                    finally
393
                    {
394
                        context.setState(Scale.PointMain);
395
                        (context.getState()).Entry(context);
396
                    }
397
                }
398
                else
399
                {
400
                    super.addOption(context, s);
401
                }
402

    
403
                return;
404
            }
405

    
406
            protected void addPoint(ScaleCADToolContext context, double pointX, double pointY, InputEvent event)
407
            {
408
                ScaleCADTool ctxt = context.getOwner();
409

    
410

    
411
                (context.getState()).Exit(context);
412
                context.clearState();
413
                try
414
                {
415
                    ctxt.setQuestion(PluginServices.getText(this,"insert_last_point_reference"));
416
                    ctxt.setDescription(new String[]{"cancel"});
417
                    ctxt.addPoint(pointX, pointY, event);
418
                }
419
                finally
420
                {
421
                    context.setState(Scale.EndPointReference);
422
                    (context.getState()).Entry(context);
423
                }
424
                return;
425
            }
426

    
427
        //-------------------------------------------------------
428
        // Member data.
429
        //
430
        }
431

    
432
        private static final class Scale_EndPointReference
433
            extends Scale_Default
434
        {
435
        //-------------------------------------------------------
436
        // Member methods.
437
        //
438

    
439
            private Scale_EndPointReference(String name, int id)
440
            {
441
                super (name, id);
442
            }
443

    
444
            protected void addPoint(ScaleCADToolContext context, double pointX, double pointY, InputEvent event)
445
            {
446
                ScaleCADTool ctxt = context.getOwner();
447

    
448

    
449
                (context.getState()).Exit(context);
450
                context.clearState();
451
                try
452
                {
453
                    ctxt.setQuestion(PluginServices.getText(this,"insert_first_point_scale"));
454
                    ctxt.setDescription(new String[]{"cancel"});
455
                    ctxt.addPoint(pointX, pointY, event);
456
                }
457
                finally
458
                {
459
                    context.setState(Scale.OriginPointScale);
460
                    (context.getState()).Entry(context);
461
                }
462
                return;
463
            }
464

    
465
        //-------------------------------------------------------
466
        // Member data.
467
        //
468
        }
469

    
470
        private static final class Scale_OriginPointScale
471
            extends Scale_Default
472
        {
473
        //-------------------------------------------------------
474
        // Member methods.
475
        //
476

    
477
            private Scale_OriginPointScale(String name, int id)
478
            {
479
                super (name, id);
480
            }
481

    
482
            protected void addPoint(ScaleCADToolContext context, double pointX, double pointY, InputEvent event)
483
            {
484
                ScaleCADTool ctxt = context.getOwner();
485

    
486

    
487
                (context.getState()).Exit(context);
488
                context.clearState();
489
                try
490
                {
491
                    ctxt.setQuestion(PluginServices.getText(this,"insert_last_point_scale"));
492
                    ctxt.setDescription(new String[]{"cancel"});
493
                    ctxt.addPoint(pointX, pointY, event);
494
                }
495
                finally
496
                {
497
                    context.setState(Scale.EndPointScale);
498
                    (context.getState()).Entry(context);
499
                }
500
                return;
501
            }
502

    
503
        //-------------------------------------------------------
504
        // Member data.
505
        //
506
        }
507

    
508
        private static final class Scale_EndPointScale
509
            extends Scale_Default
510
        {
511
        //-------------------------------------------------------
512
        // Member methods.
513
        //
514

    
515
            private Scale_EndPointScale(String name, int id)
516
            {
517
                super (name, id);
518
            }
519

    
520
            protected void addPoint(ScaleCADToolContext context, double pointX, double pointY, InputEvent event)
521
            {
522
                ScaleCADTool ctxt = context.getOwner();
523

    
524

    
525
                (context.getState()).Exit(context);
526
                context.clearState();
527
                try
528
                {
529
                    ctxt.addPoint(pointX, pointY, event);
530
                    ctxt.end();
531
                    ctxt.refresh();
532
                }
533
                finally
534
                {
535
                    context.setState(Scale.PointMain);
536
                    (context.getState()).Entry(context);
537
                }
538
                return;
539
            }
540

    
541
        //-------------------------------------------------------
542
        // Member data.
543
        //
544
        }
545

    
546
    //-----------------------------------------------------------
547
    // Member data.
548
    //
549
    }
550
}