Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / gui / cad / tools / ComplexSelectionCADTool.java @ 29616

History | View | Annotate | Download (22.9 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.editing.gui.cad.tools;
42

    
43
import java.awt.Color;
44
import java.awt.Graphics;
45
import java.awt.Graphics2D;
46
import java.awt.Image;
47
import java.awt.event.InputEvent;
48
import java.awt.event.MouseEvent;
49
import java.awt.geom.Point2D;
50
import java.util.ArrayList;
51
import java.util.List;
52

    
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.andami.messages.NotificationManager;
55
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
56
import org.gvsig.editing.CADExtension;
57
import org.gvsig.editing.gui.cad.DefaultCADTool;
58
import org.gvsig.editing.gui.cad.exception.CommandException;
59
import org.gvsig.editing.gui.cad.tools.smc.ComplexSelectionCADToolContext;
60
import org.gvsig.editing.gui.cad.tools.smc.ComplexSelectionCADToolContext.ComplexSelectionCADToolState;
61
import org.gvsig.editing.layers.VectorialLayerEdited;
62
import org.gvsig.fmap.dal.exception.DataException;
63
import org.gvsig.fmap.dal.exception.InitializeException;
64
import org.gvsig.fmap.dal.exception.ReadException;
65
import org.gvsig.fmap.dal.feature.DisposableIterator;
66
import org.gvsig.fmap.dal.feature.EditableFeature;
67
import org.gvsig.fmap.dal.feature.Feature;
68
import org.gvsig.fmap.dal.feature.FeatureSelection;
69
import org.gvsig.fmap.dal.feature.FeatureStore;
70
import org.gvsig.fmap.dal.feature.FeatureType;
71
import org.gvsig.fmap.geom.Geometry;
72
import org.gvsig.fmap.geom.handler.Handler;
73
import org.gvsig.fmap.geom.operation.Draw;
74
import org.gvsig.fmap.geom.operation.DrawOperationContext;
75
import org.gvsig.fmap.geom.operation.GeometryOperationException;
76
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
77
import org.gvsig.fmap.geom.primitive.GeneralPathX;
78
import org.gvsig.fmap.mapcontext.ViewPort;
79
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
80
import org.gvsig.fmap.mapcontrol.MapControl;
81

    
82

    
83
/**
84
 * DOCUMENT ME!
85
 *
86
 * @author Vicente Caballero Navarro
87
 */
88
public class ComplexSelectionCADTool extends SelectionCADTool {
89
        protected ComplexSelectionCADToolContext _fsm;
90
        protected List pointsPolygon = new ArrayList();
91

    
92
        /**
93
         * Crea un nuevo ComplexSelectionCADTool.
94
         */
95
        public ComplexSelectionCADTool() {
96
                type = PluginServices.getText(this, "inside_circle");
97
        }
98

    
99
        /**
100
         * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
101
         * carga previa a la utilizaci?n de la herramienta.
102
         */
103
        public void init() {
104
                _fsm = new ComplexSelectionCADToolContext(this);
105
                setNextTool("complex_selection");
106

    
107
                setType(PluginServices.getText(this, "inside_circle"));
108
        }
109

    
110
        /**
111
         * Equivale al transition del prototipo pero sin pasarle como par? metro el
112
         * editableFeatureSource que ya estar? creado.
113
         *
114
         * @param selection
115
         *            Bitset con las geometr?as que est?n seleccionadas.
116
         * @param x
117
         *            par?metro x del punto que se pase en esta transici?n.
118
         * @param y
119
         *            par?metro y del punto que se pase en esta transici?n.
120
         */
121
        public void addPoint(double x, double y, InputEvent event) {
122
                if (event != null && ((MouseEvent) event).getClickCount() == 2) {
123
                        try {
124
                                pointDoubleClick(((MapControl) event.getComponent())
125
                                                .getMapContext());
126
                        } catch (ReadException e) {
127
                                NotificationManager.addError(e.getMessage(), e);
128
                        }
129
                        return;
130
                }
131
                ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm
132
                                .getPreviousState();
133
                String status = actualState.getName();
134
                System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " +
135
                // _fsm.getState());
136
                VectorialLayerEdited vle = getVLE();
137
                FeatureStore featureStore = null;
138
                try {
139
                        featureStore = vle.getFeatureStore();
140
                } catch (ReadException e) {
141
                        // TODO Auto-generated catch block
142
                        e.printStackTrace();
143
                }
144
                ArrayList selectedHandler = vle.getSelectedHandler();
145
                System.out.println("STATUS ACTUAL = " + _fsm.getTransition());
146
                if (status.equals("Selection.FirstPoint")) {
147
                        firstPoint = new Point2D.Double(x, y);
148
                        pointsPolygon.add(firstPoint);
149
                } else if (status.equals("Selection.SecondPoint")) {
150
                } else if (status.equals("Selection.WithFeatures")) {
151
                } else if (status.equals("Selection.WithHandlers")) {
152
                        String description = PluginServices.getText(this, "move_handlers");
153
                        DisposableIterator iterator = null;
154
                        try {
155
                                featureStore.beginEditingGroup(description);
156
                                ArrayList selectedRowsAux = new ArrayList();
157

    
158
                                iterator = ((FeatureSelection) featureStore.getSelection())
159
                                                .iterator();
160

    
161
                                while (iterator.hasNext()) {
162
                                        Feature feature = (Feature) iterator.next();
163

    
164
                                        // }
165
                                        Geometry ig = (feature.getDefaultGeometry())
166
                                                        .cloneGeometry();
167
                                        // Movemos los handlers que hemos seleccionado
168
                                        // previamente dentro del m?todo select()
169
                                        Handler[] handlers = ig.getHandlers(Geometry.SELECTHANDLER);
170
                                        for (int k = 0; k < selectedHandler.size(); k++) {
171
                                                Handler h = (Handler) selectedHandler.get(k);
172
                                                for (int j = 0; j < handlers.length; j++) {
173
                                                        if (h.getPoint().equals(handlers[j].getPoint())) {
174
                                                                handlers[j].set(x, y);
175
                                                        }
176
                                                }
177
                                        }
178
                                        EditableFeature eFeature = feature.getEditable();
179
                                        eFeature.setGeometry(featureStore.getDefaultFeatureType()
180
                                                        .getDefaultGeometryAttributeName(), ig);
181
                                        featureStore.update(eFeature);
182
                                        selectedRowsAux.add(eFeature);
183
                                }
184

    
185
                                firstPoint = new Point2D.Double(x, y);
186
                                // vle.setSelectionCache(VectorialLayerEdited.SAVEPREVIOUS,
187
                                // selectedRowsAux);
188

    
189
                                featureStore.endEditingGroup();
190
                        } catch (DataException e1) {
191
                                // TODO Auto-generated catch block
192
                                e1.printStackTrace();
193
                        } finally {
194
                                if (iterator != null) {
195
                                        iterator.dispose();
196
                                }
197
                        }
198

    
199
                } else if (status.equals("Selection.NextPointPolygon")) {
200
                        pointsPolygon.add(new Point2D.Double(x, y));
201
                }
202
        }
203

    
204
        /**
205
         * Receives second point
206
         *
207
         * @param x
208
         * @param y
209
         * @return numFeatures selected
210
         */
211
        public long selectWithSecondPointOutRectangle(double x, double y,
212
                        InputEvent event) {
213
                Point2D lastPoint = new Point2D.Double(x, y);
214
                GeneralPathX gpx = new GeneralPathX();
215
                gpx.moveTo(firstPoint.getX(), firstPoint.getY());
216
                gpx.lineTo(lastPoint.getX(), firstPoint.getY());
217
                gpx.lineTo(lastPoint.getX(), lastPoint.getY());
218
                gpx.lineTo(firstPoint.getX(), lastPoint.getY());
219
                gpx.closePath();
220
                Geometry rectangle = createSurface(gpx);
221
                return selectWithPolygon(rectangle);
222
        }
223

    
224
        /**
225
         * Receives second point
226
         *
227
         * @param x
228
         * @param y
229
         * @return numFeatures selected
230
         */
231
        public long selectWithCircle(double x, double y, InputEvent event) {
232
                Geometry circle = createCircle(firstPoint,
233
                                new Point2D.Double(x, y));
234
                return selectWithPolygon(circle);
235
        }
236

    
237
        public long selectWithPolygon(Geometry polygon) {
238
                VectorialLayerEdited vle = getVLE();
239
                PluginServices.getMDIManager().setWaitCursor();
240

    
241
                if (getType().equals(PluginServices.getText(this, "inside_circle"))
242
                                || getType().equals(
243
                                                PluginServices.getText(this, "inside_polygon"))) {
244
                        vle.selectInsidePolygon(polygon);
245
                } else if (getType().equals(
246
                                PluginServices.getText(this, "cross_circle"))
247
                                || getType().equals(
248
                                                PluginServices.getText(this, "cross_polygon"))) {
249
                        vle.selectCrossPolygon(polygon);
250
                } else if (getType().equals(PluginServices.getText(this, "out_circle"))
251
                                || getType()
252
                                                .equals(PluginServices.getText(this, "out_polygon"))
253
                                || getType().equals(
254
                                                PluginServices.getText(this, "out_rectangle"))) {
255
                        vle.selectOutPolygon(polygon);
256
                }
257
                long countSelection = 0;
258
                try {
259
                        countSelection = ((FeatureSelection) vle.getFeatureStore()
260
                                        .getSelection()).getSize();
261
                } catch (ReadException e) {
262
                        // TODO Auto-generated catch block
263
                        e.printStackTrace();
264
                } catch (DataException e) {
265
                        // TODO Auto-generated catch block
266
                        e.printStackTrace();
267
                }
268
                PluginServices.getMDIManager().restoreCursor();
269
                if (countSelection > 0) {
270
                        nextState = "Selection.WithSelectedFeatures";
271
                        end();
272
                } else {
273
                        nextState = "Selection.FirstPoint";
274
                }
275
                return countSelection;
276
        }
277

    
278
        /**
279
         * M?todo para dibujar la lo necesario para el estado en el que nos
280
         * encontremos.
281
         *
282
         * @param g
283
         *            Graphics sobre el que dibujar.
284
         * @param selectedGeometries
285
         *            BitSet con las geometr?as seleccionadas.
286
         * @param x
287
         *            par?metro x del punto que se pase para dibujar.
288
         * @param y
289
         *            par?metro x del punto que se pase para dibujar.
290
         */
291
        public void drawOperation(Graphics g, double x, double y) {
292
                ComplexSelectionCADToolState actualState = _fsm.getState();
293
                String status = actualState.getName();
294
                VectorialLayerEdited vle = getVLE();
295
                ArrayList selectedHandler = vle.getSelectedHandler();
296
                ViewPort vp = vle.getLayer().getMapContext().getViewPort();
297
                if (status.equals("Selection.SecondPoint")
298
                                || status.equals("Selection.SecondPointOutRectangle")) {
299
                        // Dibuja el rect?ngulo de selecci?n
300
                        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
301
                                        4);
302
                        elShape.moveTo(firstPoint.getX(), firstPoint.getY());
303
                        elShape.lineTo(x, firstPoint.getY());
304
                        elShape.lineTo(x, y);
305
                        elShape.lineTo(firstPoint.getX(), y);
306
                        elShape.lineTo(firstPoint.getX(), firstPoint.getY());
307

    
308
                        DrawOperationContext doc = new DrawOperationContext();
309
                        doc.setGraphics((Graphics2D) g);
310
                        doc.setViewPort(vp);
311
                        doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
312
                        try {
313
                                createCurve(elShape).invokeOperation(
314
                                                Draw.CODE, doc);
315
                        } catch (GeometryOperationNotSupportedException e) {
316
                                e.printStackTrace();
317
                        } catch (GeometryOperationException e) {
318
                                e.printStackTrace();
319
                        }
320
                        Image img = vle.getSelectionImage();
321
                        g.drawImage(img, 0, 0, null);
322
                        return;
323
                }
324
                if (status.equals("Selection.SecondPointCircle")) {
325
                        Geometry circle = createCircle(firstPoint,
326
                                        new Point2D.Double(x, y));
327
                        GeneralPathX gpx = new GeneralPathX();
328
                        gpx.append(circle.getInternalShape(), true);
329
                        Geometry circleSel = createCurve(gpx);
330
                        // Dibuja el c?rculo de selecci?n
331
                        DrawOperationContext doc = new DrawOperationContext();
332
                        doc.setGraphics((Graphics2D) g);
333
                        doc.setViewPort(vp);
334
                        doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
335
                        try {
336
                                circleSel.invokeOperation(Draw.CODE, doc);
337
                        } catch (GeometryOperationNotSupportedException e) {
338
                                e.printStackTrace();
339
                        } catch (GeometryOperationException e) {
340
                                e.printStackTrace();
341
                        }
342
                        Image img = vle.getSelectionImage();
343
                        g.drawImage(img, 0, 0, null);
344
                        return;
345
                } else if (status.equals("Selection.NextPointPolygon")) {
346
                        // Dibuja el pol?gono de selecci?n
347
                        Geometry polygon = getGeometryPolygon(new Point2D.Double(x, y));
348
                        DrawOperationContext doc = new DrawOperationContext();
349
                        doc.setGraphics((Graphics2D) g);
350
                        doc.setViewPort(vp);
351
                        doc.setSymbol(DefaultCADTool.geometrySelectSymbol);
352
                        try {
353
                                polygon.invokeOperation(Draw.CODE, doc);
354
                        } catch (GeometryOperationNotSupportedException e) {
355
                                e.printStackTrace();
356
                        } catch (GeometryOperationException e) {
357
                                e.printStackTrace();
358
                        }
359
                        Image img = vle.getSelectionImage();
360
                        g.drawImage(img, 0, 0, null);
361
                        return;
362
                } else if (status.equals("Selection.WithHandlers")) {
363
                        // Movemos los handlers que hemos seleccionado
364
                        // previamente dentro del m?todo select()
365
                        double xPrev = 0;
366
                        double yPrev = 0;
367
                        for (int k = 0; k < selectedHandler.size(); k++) {
368
                                Handler h = (Handler) selectedHandler.get(k);
369
                                xPrev = h.getPoint().getX();
370
                                yPrev = h.getPoint().getY();
371
                                h.set(x, y);
372
                        }
373
                        // Y una vez movidos los v?rtices (handles)
374
                        // redibujamos la nueva geometr?a.
375
                        for (int i = 0; i < rowselectedHandlers.size(); i++) {
376
                                Feature rowEd = (Feature) rowselectedHandlers.get(i);
377
                                Geometry geom = (rowEd.getDefaultGeometry())
378
                                                .cloneGeometry();
379
                                g.setColor(Color.gray);
380
                                DrawOperationContext doc = new DrawOperationContext();
381
                                doc.setGraphics((Graphics2D) g);
382
                                doc.setViewPort(vp);
383
                                doc.setSymbol(DefaultCADTool.axisReferencesSymbol);
384
                                try {
385
                                        geom.invokeOperation(Draw.CODE, doc);
386
                                } catch (GeometryOperationNotSupportedException e) {
387
                                        e.printStackTrace();
388
                                } catch (GeometryOperationException e) {
389
                                        e.printStackTrace();
390
                                }
391
                        }
392
                        for (int k = 0; k < selectedHandler.size(); k++) {
393
                                Handler h = (Handler) selectedHandler.get(k);
394
                                h.set(xPrev, yPrev);
395
                        }
396
                        return;
397
                } else {
398
                        if (!vle.getLayer().isVisible()) {
399
                                return;
400
                        }
401
                        try {
402
                                Image imgSel = vle.getSelectionImage();
403
                                if (imgSel != null) {
404
                                        g.drawImage(imgSel, 0, 0, null);
405
                                }
406
                                Image imgHand = vle.getHandlersImage();
407
                                if (imgHand != null) {
408
                                        g.drawImage(imgHand, 0, 0, null);
409
                                }
410
                        } catch (Exception e) {
411
                        }
412
                }
413
        }
414

    
415
        /**
416
         * Add a diferent option.
417
         *
418
         * @param sel
419
         *            DOCUMENT ME!
420
         * @param s
421
         *            Diferent option.
422
         */
423
        public void addOption(String s) {
424
                ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm
425
                                .getPreviousState();
426
                String status = actualState.getName();
427
                System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " +
428
                // _fsm.getState());
429
                System.out.println("STATUS ACTUAL = " + _fsm.getTransition());
430
                if (s.equals(PluginServices.getText(this, "cancel"))) {
431
                        init();
432
                        return;
433
                } else if (s.equals(PluginServices.getText(this, "select_all"))) {
434
                        selectAll();
435
                        init();
436
                        return;
437
                }
438
                if (status.equals("Selection.FirstPoint")) {
439
                        setType(s);
440
                        return;
441
                } else if (status.equals("Selection.NextPointPolygon")) {
442
                        if (s.equals(PluginServices.getText(this, "end_polygon"))
443
                                        || s.equalsIgnoreCase(PluginServices.getText(this,
444
                                                        "ComplexSelectionCADTool.end"))) {
445
                                Geometry polygon = getGeometryPolygon(null);
446
                                GeneralPathX gpx = new GeneralPathX();
447
                                gpx.append(polygon, true);
448
                                if (gpx.isCCW()) {
449
                                        gpx.flip();
450
                                        polygon = createSurface(gpx);
451
                                }
452
                                selectWithPolygon(polygon);
453
                                pointsPolygon.clear();
454
                                setType(PluginServices.getText(this, "inside_circle"));
455
                                return;
456
                        }
457
                }
458
                init();
459
        }
460

    
461
        private long selectAll() {
462
                VectorialLayerEdited vle = getVLE();
463
                PluginServices.getMDIManager().setWaitCursor();
464
                vle.selectAll();
465
                long countSelection = 0;
466
                try {
467
                        countSelection = ((FeatureSelection) vle.getFeatureStore()
468
                                        .getSelection()).getSize();
469
                } catch (ReadException e) {
470
                        // TODO Auto-generated catch block
471
                        e.printStackTrace();
472
                } catch (DataException e) {
473
                        // TODO Auto-generated catch block
474
                        e.printStackTrace();
475
                }
476
                PluginServices.getMDIManager().restoreCursor();
477
                if (countSelection > 0) {
478
                        nextState = "Selection.WithSelectedFeatures";
479
                } else {
480
                        nextState = "Selection.FirstPoint";
481
                }
482
                end();
483
                return countSelection;
484
        }
485

    
486
        private Geometry getGeometryPolygon(Point2D p) {
487
                Point2D[] points = (Point2D[]) pointsPolygon.toArray(new Point2D[0]);
488
                GeneralPathX gpx = new GeneralPathX();
489
                for (int i = 0; i < points.length; i++) {
490
                        if (i == 0) {
491
                                gpx.moveTo(points[i].getX(), points[i].getY());
492
                        } else {
493
                                gpx.lineTo(points[i].getX(), points[i].getY());
494
                        }
495
                }
496
                if (p != null) {
497
                        gpx.lineTo(p.getX(), p.getY());
498
                        gpx.closePath();
499
                        Geometry polyline = createCurve(gpx);
500
                        return polyline;
501
                }
502
                gpx.closePath();
503
                Geometry polygon = createSurface(gpx);
504
                return polygon;
505
        }
506

    
507
        /*
508
         * (non-Javadoc)
509
         *
510
         * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
511
         */
512
        public void addValue(double d) {
513
        }
514

    
515
        public void end() {
516
                if (!getNextTool().equals("complex_selection")) {
517
                        CADExtension.setCADTool(getNextTool(), false);
518
                }
519
        }
520

    
521
        public String getName() {
522
                return PluginServices.getText(this, "complex_selection_");
523
        }
524

    
525
        public boolean selectFeatures(double x, double y, InputEvent event) {
526
                ComplexSelectionCADToolState actualState = _fsm.getState();
527

    
528
                String status = actualState.getName();
529
                VectorialLayerEdited vle = getVLE();
530

    
531
                if ((status.equals("Selection.FirstPoint"))
532
                                || (status.equals("Selection.WithSelectedFeatures"))) {
533
                        PluginServices.getMDIManager().setWaitCursor();
534
                        firstPoint = new Point2D.Double(x, y);
535
                        vle.selectWithPoint(x, y, multipleSelection);
536
                        PluginServices.getMDIManager().restoreCursor();
537
                }
538
                long countSelection = 0;
539
                try {
540
                        countSelection = ((FeatureSelection) vle.getFeatureStore()
541
                                        .getSelection()).getSize();
542
                } catch (ReadException e) {
543
                        // TODO Auto-generated catch block
544
                        e.printStackTrace();
545
                } catch (DataException e) {
546
                        // TODO Auto-generated catch block
547
                        e.printStackTrace();
548
                }
549
                if (countSelection > 0) {
550
                        nextState = "Selection.WithSelectedFeatures";
551
                        return true;
552
                } else {
553
                        {
554
                                nextState = "Selection.SecondPoint";
555
                                return true;
556
                        }
557
                }
558
        }
559

    
560
        public int selectHandlers(double x, double y, InputEvent event) {
561
                Point2D auxPoint = new Point2D.Double(x, y);
562

    
563
                VectorialLayerEdited vle = getVLE();
564
                ArrayList selectedHandler = vle.getSelectedHandler();
565
                selectedHandler.clear();
566

    
567
                // Se comprueba si se pincha en una gemometr?a
568
                PluginServices.getMDIManager().setWaitCursor();
569

    
570
                double tam = getCadToolAdapter().getMapControl().getViewPort()
571
                                .toMapDistance(MapControl.tolerance);
572

    
573
                Handler[] handlers = null;
574
                rowselectedHandlers.clear();
575
                FeatureStore featureStore = null;
576
                try {
577
                        featureStore = vle.getFeatureStore();
578
                } catch (ReadException e) {
579
                        // TODO Auto-generated catch block
580
                        e.printStackTrace();
581
                }
582
                DisposableIterator iterator = null;
583
                try {
584
                        iterator = ((FeatureSelection) featureStore.getSelection())
585
                        .iterator();
586
                        while (iterator.hasNext()) {
587
                                Feature feature = (Feature) iterator.next();
588

    
589
                                Geometry geom = (feature.getDefaultGeometry()).cloneGeometry();
590
                                handlers = geom.getHandlers(Geometry.SELECTHANDLER);
591
                                // y miramos los handlers de cada entidad seleccionada
592
                                double min = tam;
593

    
594
                                for (int j = 0; j < handlers.length; j++) {
595
                                        Point2D handlerPoint = handlers[j].getPoint();
596
                                        double distance = auxPoint.distance(handlerPoint);
597
                                        if (distance <= min) {
598
                                                min = distance;
599
                                                selectedHandler.add(handlers[j]);
600
                                                EditableFeature eFeature;
601
                                                try {
602
                                                        eFeature = featureStore.createNewFeature(false);
603
                                                        FeatureType featureType = featureStore
604
                                                                        .getDefaultFeatureType();
605
                                                        for (int i = 0; i < featureType.size(); i++) {
606
                                                                eFeature.set(i, feature.get(i));
607
                                                        }
608
                                                        eFeature.setGeometry(featureType
609
                                                                        .getDefaultGeometryAttributeName(), geom);
610
                                                } catch (InitializeException e) {
611
                                                        // TODO Auto-generated catch block
612
                                                        e.printStackTrace();
613
                                                } catch (DataException e) {
614
                                                        // TODO Auto-generated catch block
615
                                                        e.printStackTrace();
616
                                                }
617
                                                rowselectedHandlers.add(feature);
618
                                        }
619
                                }
620
                        }
621
                } catch (DataException e1) {
622
                        // TODO Auto-generated catch block
623
                        e1.printStackTrace();
624
                } finally {
625
                        if (iterator != null) {
626
                                iterator.dispose();
627
                        }
628
                }
629

    
630
                PluginServices.getMDIManager().restoreCursor();
631

    
632
                int numHandlesSelected = selectedHandler.size();
633

    
634
                /*
635
                 * if (numHandlesSelected == 0) selectFeatures(x,y);
636
                 */
637

    
638
                return numHandlesSelected;
639
        }
640

    
641
        public String getType() {
642
                return type;
643
        }
644

    
645
        public void setType(String type) {
646
                if (type.equalsIgnoreCase(PluginServices.getText(this,
647
                                "ComplexSelectionCADTool.outrectangle"))) {
648
                        this.type = PluginServices.getText(this, "out_rectangle");
649
                } else if (type.equalsIgnoreCase(PluginServices.getText(this,
650
                                "ComplexSelectionCADTool.intropolygon"))) {
651
                        this.type = PluginServices.getText(this, "inside_polygon");
652
                } else if (type.equalsIgnoreCase(PluginServices.getText(this,
653
                                "ComplexSelectionCADTool.crosspolygon"))) {
654
                        this.type = PluginServices.getText(this, "cross_polygon");
655
                } else if (type.equalsIgnoreCase(PluginServices.getText(this,
656
                                "ComplexSelectionCADTool.outpolygon"))) {
657
                        this.type = PluginServices.getText(this, "out_polygon");
658
                } else if (type.equalsIgnoreCase(PluginServices.getText(this,
659
                                "ComplexSelectionCADTool.introcircle"))) {
660
                        this.type = PluginServices.getText(this, "inside_circle");
661
                } else if (type.equalsIgnoreCase(PluginServices.getText(this,
662
                                "ComplexSelectionCADTool.crosscircle"))) {
663
                        this.type = PluginServices.getText(this, "cross_circle");
664
                } else if (type.equalsIgnoreCase(PluginServices.getText(this,
665
                                "ComplexSelectionCADTool.outcircle"))) {
666
                        this.type = PluginServices.getText(this, "out_circle");
667
                } else if (type.equals(PluginServices.getText(this, "select_all"))) {
668
                        selectAll();
669
                        init();
670
                } else {
671
                        this.type = type;
672
                }
673
                pointsPolygon.clear();
674
        }
675

    
676
        /*
677
         * (non-Javadoc)
678
         *
679
         * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
680
         *      double, double)
681
         */
682
        public void transition(double x, double y, InputEvent event) {
683
                System.out.println("TRANSICION DESDE ESTADO " + _fsm.getState()
684
                                + " x= " + x + " y=" + y);
685
                try {
686
                        _fsm.addPoint(x, y, event);
687
                } catch (Exception e) {
688
                        init();
689
                }
690
                System.out.println("ESTADO ACTUAL: " + getStatus());
691

    
692
                FLyrVect lv = (FLyrVect) ((VectorialLayerEdited) CADExtension
693
                                .getEditionManager().getActiveLayerEdited()).getLayer();
694
                org.gvsig.andami.ui.mdiManager.IWindow[] views = PluginServices
695
                                .getMDIManager().getAllWindows();
696

    
697
                for (int i = 0; i < views.length; i++) {
698
                        if (views[i] instanceof FeatureTableDocumentPanel) {
699
                                FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) views[i];
700
                                if (table.getModel().getAssociatedLayer() != null
701
                                                && table.getModel().getAssociatedLayer().equals(lv)) {
702
                                        table.updateSelection();
703
                                }
704
                        }
705
                }
706
        }
707

    
708
        public String getStatus() {
709
                try {
710
                        ComplexSelectionCADToolState actualState = (ComplexSelectionCADToolState) _fsm
711
                                        .getPreviousState();
712
                        String status = actualState.getName();
713

    
714
                        return status;
715
                } catch (NullPointerException e) {
716
                        return "Selection.FirstPoint";
717
                }
718
        }
719

    
720
        /*
721
         * (non-Javadoc)
722
         *
723
         * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
724
         *      java.lang.String)
725
         */
726
        public void transition(String s) throws CommandException {
727
                if (!super.changeCommand(s)) {
728

    
729
                        _fsm.addOption(s);
730

    
731
                }
732
        }
733

    
734
        /*
735
         * (non-Javadoc)
736
         *
737
         * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
738
         *      double)
739
         */
740
        public void transition(double d) {
741
                _fsm.addValue(d);
742
        }
743

    
744
        public String toString() {
745
                return "_complex_selection";
746
        }
747

    
748
        public String getNextState() {
749
                return nextState;
750
        }
751

    
752
}