Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / tools / SelectionCADTool.java @ 5205

History | View | Annotate | Download (20.2 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 com.iver.cit.gvsig.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.io.IOException;
51
import java.util.ArrayList;
52

    
53
import com.hardcode.driverManager.DriverLoadException;
54
import com.iver.andami.PluginServices;
55
import com.iver.cit.gvsig.CADExtension;
56
import com.iver.cit.gvsig.fmap.MapControl;
57
import com.iver.cit.gvsig.fmap.ViewPort;
58
import com.iver.cit.gvsig.fmap.core.FShape;
59
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
60
import com.iver.cit.gvsig.fmap.core.Handler;
61
import com.iver.cit.gvsig.fmap.core.IFeature;
62
import com.iver.cit.gvsig.fmap.core.IGeometry;
63
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
64
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
65
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
66
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
67
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
68
import com.iver.cit.gvsig.fmap.layers.FLayer;
69
import com.iver.cit.gvsig.fmap.layers.FLayers;
70
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
71
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
72
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
73
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
74
import com.iver.cit.gvsig.gui.Table;
75
import com.iver.cit.gvsig.gui.View;
76
import com.iver.cit.gvsig.gui.Panels.TextFieldEdit;
77
import com.iver.cit.gvsig.gui.cad.CADTool;
78
import com.iver.cit.gvsig.gui.cad.DefaultCADTool;
79
import com.iver.cit.gvsig.gui.cad.exception.CommadException;
80
import com.iver.cit.gvsig.gui.cad.tools.smc.SelectionCADToolContext;
81
import com.iver.cit.gvsig.gui.cad.tools.smc.SelectionCADToolContext.SelectionCADToolState;
82
import com.iver.cit.gvsig.layers.VectorialLayerEdited;
83

    
84
/**
85
 * DOCUMENT ME!
86
 *
87
 * @author Vicente Caballero Navarro
88
 */
89
public class SelectionCADTool extends DefaultCADTool {
90
        public final static int tolerance = 4;
91

    
92
        private SelectionCADToolContext _fsm;
93

    
94
        private Point2D firstPoint;
95

    
96
        //private Point2D lastPoint;
97

    
98

    
99

    
100
        private String nextState;
101
// Registros de los que se ha sleccionado alg?n handler.
102
        private ArrayList rowselectedHandlers=new ArrayList();
103
        private String type=PluginServices.getText(this,"simple");
104
        private ArrayList pointsPolygon=new ArrayList();
105
        /**
106
         * Crea un nuevo SelectionCADTool.
107
         */
108
        public SelectionCADTool() {
109
        }
110
        /**
111
         * M?todo de incio, para poner el c?digo de todo lo que se requiera de una
112
         * carga previa a la utilizaci?n de la herramienta.
113
         */
114
        public void init() {
115
                _fsm = new SelectionCADToolContext(this);
116
                setNextTool("selection");
117

    
118
                setType(PluginServices.getText(this,"simple"));
119
        }
120

    
121
        /*
122
         * (non-Javadoc)
123
         *
124
         * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
125
         *      double, double)
126
         */
127
        public void transition(double x, double y, InputEvent event) {
128
                System.out.println("TRANSICION DESDE ESTADO " + _fsm.getState()
129
                                + " x= " + x + " y=" + y);
130
                try{
131
                _fsm.addPoint(x, y, event);
132
                }catch (Exception e) {
133
                        init();
134
                }
135
                System.out.println("ESTADO ACTUAL: " + getStatus());
136

    
137
                // ESTO LO QUITO POR AHORA, PERO PUEDE QUE LO NECESITEMOS VOLVER A PONER.
138
                // Lo he quitado porque cuando seleccionas algo con CAD, molesta que
139
                // te hagan un redibujado.
140
                FLyrVect lv=(FLyrVect)((VectorialLayerEdited)CADExtension.getEditionManager().getActiveLayerEdited()).getLayer();
141
                //lv.getSource().getRecordset().getSelectionSupport().fireSelectionEvents();
142
                com.iver.andami.ui.mdiManager.View[] views = (com.iver.andami.ui.mdiManager.View[]) PluginServices.getMDIManager().getAllViews();
143

    
144
                for (int i=0 ; i<views.length ; i++){
145
                        if (views[i] instanceof Table){
146
                                Table table=(Table)views[i];
147
                                if (table.getModel().getAssociatedTable()!=null && table.getModel().getAssociatedTable().equals(lv))
148
                                        table.updateSelection();
149
                        }
150
                }
151
        }
152

    
153
        /*
154
         * (non-Javadoc)
155
         *
156
         * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
157
         *      double)
158
         */
159
        public void transition(double d) {
160
                // _fsm.addValue(sel,d);
161
        }
162

    
163
        /*
164
         * (non-Javadoc)
165
         *
166
         * @see com.iver.cit.gvsig.gui.cad.CADTool#transition(com.iver.cit.gvsig.fmap.layers.FBitSet,
167
         *      java.lang.String)
168
         */
169
        public void transition(String s) throws CommadException {
170
                if (!super.changeCommand(s)){
171

    
172
                        _fsm.addOption(s);
173

    
174
            }
175
        }
176

    
177
        public String getNextState() {
178
                return nextState;
179
        }
180

    
181
        protected void pointDoubleClick(MapControl map) {
182
                try {
183
                        FLayer[] actives = map.getMapContext()
184
            .getLayers().getActives();
185
            for (int i=0; i < actives.length; i++){
186
                if (actives[i] instanceof FLyrAnnotation && actives[i].isEditing()) {
187
                    FLyrAnnotation lyrAnnotation = (FLyrAnnotation) actives[i];
188

    
189
                            lyrAnnotation.setSelectedEditing();
190
                            lyrAnnotation.setInEdition(lyrAnnotation.getRecordset().getSelection().nextSetBit(0));
191
                            FLabel fl=lyrAnnotation.getLabel(lyrAnnotation.getInEdition());
192
                                        if (fl!=null){
193

    
194
                                                View vista=(View)PluginServices.getMDIManager().getActiveView();
195
                                                TextFieldEdit tfe=new TextFieldEdit(lyrAnnotation);
196

    
197
                                                tfe.show(vista.getMapControl().getViewPort().fromMapPoint(fl.getOrig()),vista.getMapControl());
198
                                        }
199
                }
200
            }
201

    
202
                } catch (DriverLoadException e) {
203
                        e.printStackTrace();
204
                } catch (com.iver.cit.gvsig.fmap.DriverException e) {
205
                        e.printStackTrace();
206
                }
207

    
208
}
209
        /**
210
         * Equivale al transition del prototipo pero sin pasarle como par? metro el
211
         * editableFeatureSource que ya estar? creado.
212
         *
213
         * @param selection
214
         *            Bitset con las geometr?as que est?n seleccionadas.
215
         * @param x
216
         *            par?metro x del punto que se pase en esta transici?n.
217
         * @param y
218
         *            par?metro y del punto que se pase en esta transici?n.
219
         */
220
        public void addPoint(double x, double y, InputEvent event) {
221
                if (((MouseEvent)event).getClickCount()==2){
222
                        pointDoubleClick((MapControl)event.getComponent());
223
                        return;
224
                }
225
                SelectionCADToolState actualState = (SelectionCADToolState) _fsm
226
                                .getPreviousState();
227
                String status = actualState.getName();
228
                System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " +
229
                                                                                                                // _fsm.getState());
230
                VectorialLayerEdited vle = getVLE();
231
                VectorialEditableAdapter vea=vle.getVEA();
232
                ArrayList selectedHandler = vle.getSelectedHandler();
233
                ArrayList selectedRow = vle.getSelectedRow();
234
                System.out.println("STATUS ACTUAL = " + _fsm.getTransition());
235
                if (status.equals("Selection.FirstPoint")) {
236
                        firstPoint=new Point2D.Double(x,y);
237
                        pointsPolygon.add(firstPoint);
238
                } else if (status.equals("Selection.SecondPoint")) {
239
                } else if (status.equals("Selection.WithFeatures")) {
240
                } else if (status.equals("Selection.WithHandlers")) {
241
                        vea.startComplexRow();
242
                        for (int i = 0; i < selectedRow.size(); i++) {
243
                                IRowEdited row = (IRowEdited) selectedRow.get(i);
244
                                // Movemos los handlers que hemos seleccionado
245
                                // previamente dentro del m?todo select()
246
                                for (int k = 0; k < selectedHandler.size(); k++) {
247
                                        Handler h = (Handler) selectedHandler.get(k);
248
                                        h.set(x, y);
249
                                }
250

    
251
                                modifyFeature(row.getIndex(), (IFeature) row.getLinkedRow().cloneRow());
252
                        }
253
                        try {
254
                                vea.endComplexRow();
255
                        } catch (IOException e) {
256
                                e.printStackTrace();
257
                        } catch (DriverIOException e) {
258
                                e.printStackTrace();
259
                        }
260
                }else if (status.equals("Selection.NextPointPolygon")) {
261
                        pointsPolygon.add(new Point2D.Double(x,y));
262
                }
263
        }
264

    
265
        /**
266
         * Receives second point
267
         * @param x
268
         * @param y
269
         * @return numFeatures selected
270
         */
271
        public int selectWithSecondPoint(double x, double y, InputEvent event) {
272
                VectorialLayerEdited vle = getVLE();
273
                PluginServices.getMDIManager().setWaitCursor();
274
                vle.selectWithSecondPoint(x,y);
275
                ArrayList selectedRow = vle.getSelectedRow();
276
                PluginServices.getMDIManager().restoreCursor();
277
                if (selectedRow.size() > 0) {
278
                        nextState = "Selection.WithSelectedFeatures";
279
                } else
280
                        nextState = "Selection.FirstPoint";
281
                return selectedRow.size();
282
        }
283
        /**
284
         * Receives second point
285
         * @param x
286
         * @param y
287
         * @return numFeatures selected
288
         */
289
        public int selectWithSecondPointOutRectangle(double x, double y, InputEvent event) {
290
                Point2D lastPoint=new Point2D.Double(x,y);
291
                GeneralPathX gpx=new GeneralPathX();
292
                gpx.moveTo(firstPoint.getX(),firstPoint.getY());
293
                gpx.lineTo(lastPoint.getX(),firstPoint.getY());
294
                gpx.lineTo(lastPoint.getX(),lastPoint.getY());
295
                gpx.lineTo(firstPoint.getX(),lastPoint.getY());
296
                gpx.closePath();
297
                IGeometry rectangle=ShapeFactory.createPolygon2D(gpx);
298
                return selectWithPolygon(rectangle);
299
//                VectorialLayerEdited vle = getVLE();
300
//                PluginServices.getMDIManager().setWaitCursor();
301
//                vle.selectWithSecondPointOutRectangle(firstPoint,x,y);
302
//                ArrayList selectedRow = vle.getSelectedRow();
303
//                PluginServices.getMDIManager().restoreCursor();
304
//                if (selectedRow.size() > 0) {
305
//                        nextState = "Selection.WithSelectedFeatures";
306
//                } else
307
//                        nextState = "Selection.FirstPoint";
308
//                return selectedRow.size();
309
        }
310
        /**
311
         * Receives second point
312
         * @param x
313
         * @param y
314
         * @return numFeatures selected
315
         */
316
        public int selectWithCircle(double x, double y, InputEvent event) {
317
                IGeometry circle=ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y));
318
                return selectWithPolygon(circle);
319
        }
320
        public int selectWithPolygon(IGeometry polygon) {
321
                VectorialLayerEdited vle = getVLE();
322
                PluginServices.getMDIManager().setWaitCursor();
323

    
324
                if (getType().equals(PluginServices.getText(this,"inside_circle")) || getType().equals(PluginServices.getText(this,"inside_polygon"))) {
325
                        vle.selectInsidePolygon(polygon);
326
                } else if (getType().equals(PluginServices.getText(this,"cross_circle")) || getType().equals(PluginServices.getText(this,"cross_polygon"))) {
327
                        vle.selectCrossPolygon(polygon);
328
                } else if (getType().equals(PluginServices.getText(this,"out_circle")) || getType().equals(PluginServices.getText(this,"out_polygon")) || getType().equals(PluginServices.getText(this,"out_rectangle"))) {
329
                        vle.selectOutPolygon(polygon);
330
                }
331
                ArrayList selectedRow = vle.getSelectedRow();
332
                PluginServices.getMDIManager().restoreCursor();
333
                if (selectedRow.size() > 0) {
334
                        nextState = "Selection.WithSelectedFeatures";
335
                        end();
336
                } else
337
                        nextState = "Selection.FirstPoint";
338
                return selectedRow.size();
339
        }
340

    
341
        /**
342
         * M?todo para dibujar la lo necesario para el estado en el que nos
343
         * encontremos.
344
         *
345
         * @param g
346
         *            Graphics sobre el que dibujar.
347
         * @param selectedGeometries
348
         *            BitSet con las geometr?as seleccionadas.
349
         * @param x
350
         *            par?metro x del punto que se pase para dibujar.
351
         * @param y
352
         *            par?metro x del punto que se pase para dibujar.
353
         */
354
        public void drawOperation(Graphics g, double x, double y) {
355
                SelectionCADToolState actualState = _fsm.getState();
356
                String status = actualState.getName();
357
                VectorialLayerEdited vle = getVLE();
358
                ArrayList selectedHandler = vle.getSelectedHandler();
359
                ViewPort vp=vle.getLayer().getFMap().getViewPort();
360
                if (status.equals("Selection.SecondPoint") || status.equals("Selection.SecondPointOutRectangle")) {
361
                        // Dibuja el rect?ngulo de selecci?n
362
                        GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
363
                                        4);
364
                        elShape.moveTo(firstPoint.getX(), firstPoint.getY());
365
                        elShape.lineTo(x, firstPoint.getY());
366
                        elShape.lineTo(x, y);
367
                        elShape.lineTo(firstPoint.getX(), y);
368
                        elShape.lineTo(firstPoint.getX(), firstPoint.getY());
369
                        ShapeFactory.createPolyline2D(elShape).draw((Graphics2D) g,
370
                                        vp,
371
                                        CADTool.selectSymbol);
372
                        Image img = vle.getSelectionImage();
373
                g.drawImage(img, 0, 0, null);
374
                return;
375
                }if (status.equals("Selection.SecondPointCircle")) {
376
                        // Dibuja el c?rculo de selecci?n
377
                        ShapeFactory.createCircle(firstPoint,new Point2D.Double(x,y)).draw((Graphics2D) g,
378
                                        vp,
379
                                        CADTool.selectSymbol);
380
                        Image img = vle.getSelectionImage();
381
                g.drawImage(img, 0, 0, null);
382
                return;
383
                }else if (status.equals("Selection.NextPointPolygon")) {
384
                        // Dibuja el pol?gono de selecci?n
385
                        IGeometry polygon=getGeometryPolygon(new Point2D.Double(x,y));
386
                        polygon.draw((Graphics2D) g,
387
                                        vp,
388
                                        CADTool.selectSymbol);
389
                        Image img = vle.getSelectionImage();
390
                g.drawImage(img, 0, 0, null);
391
                return;
392
                }else if (status.equals("Selection.WithHandlers")) {
393
                        // Movemos los handlers que hemos seleccionado
394
                        // previamente dentro del m?todo select()
395
                        for (int k = 0; k < selectedHandler.size(); k++) {
396
                                Handler h = (Handler) selectedHandler.get(k);
397
                                h.set(x, y);
398
                        }
399
                        // Y una vez movidos los v?rtices (handles)
400
                        // redibujamos la nueva geometr?a.
401
                        for (int i = 0; i < rowselectedHandlers.size(); i++) {
402
                                IRowEdited rowEd = (IRowEdited) rowselectedHandlers.get(i);
403
                                IGeometry geom = ((IFeature) rowEd.getLinkedRow())
404
                                                .getGeometry().cloneGeometry();
405
                                g.setColor(Color.gray);
406
                                geom.draw((Graphics2D) g, vp, CADTool.modifySymbol);
407
                        }
408
                        return;
409
                }else{
410
                        try{
411
                        Image imgSel = vle.getSelectionImage();
412
                if (imgSel!=null)
413
                        g.drawImage(imgSel, 0, 0, null);
414
                Image imgHand = vle.getHandlersImage();
415
                if (imgHand!=null)
416
                        g.drawImage(imgHand, 0, 0, null);
417
                        }catch (Exception e) {
418
                        }
419
                }
420
        }
421

    
422
        /**
423
         * Add a diferent option.
424
         *
425
         * @param sel
426
         *            DOCUMENT ME!
427
         * @param s
428
         *            Diferent option.
429
         */
430
        public void addOption(String s) {
431
                SelectionCADToolState actualState = (SelectionCADToolState) _fsm
432
                                .getPreviousState();
433
                String status = actualState.getName();
434
                System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " +
435
                // _fsm.getState());
436
                System.out.println("STATUS ACTUAL = " + _fsm.getTransition());
437
                if (s.equals(PluginServices.getText(this,"cancel"))){
438
                        init();
439
                        return;
440
                }else if (s.equals(PluginServices.getText(this,"select_all"))){
441
                        selectAll();
442
                        init();
443
                        return;
444
                }
445
                if (status.equals("Selection.FirstPoint")) {
446
                        setType(s);
447
                        return;
448
                }else if (status.equals("Selection.NextPointPolygon")){
449
                        if (s.equals(PluginServices.getText(this,"end_polygon")) || s.equals("E") || s.equals("e")) {
450
                        IGeometry polygon=getGeometryPolygon(null);
451
                        selectWithPolygon(polygon);
452
                        pointsPolygon.clear();
453
                        setType(PluginServices.getText(this,"simple"));
454
                        return;
455
                        }
456
                }
457
                init();
458
        }
459
        private int selectAll() {
460
                VectorialLayerEdited vle = getVLE();
461
                PluginServices.getMDIManager().setWaitCursor();
462
                vle.selectAll();
463
                ArrayList selectedRow = vle.getSelectedRow();
464
                PluginServices.getMDIManager().restoreCursor();
465
                if (selectedRow.size() > 0) {
466
                        nextState = "Selection.WithSelectedFeatures";
467
                } else
468
                        nextState = "Selection.FirstPoint";
469
                end();
470
                return selectedRow.size();
471
        }
472

    
473
        private IGeometry getGeometryPolygon(Point2D p) {
474
                Point2D[] points = (Point2D[]) pointsPolygon.toArray(new Point2D[0]);
475
                GeneralPathX gpx = new GeneralPathX();
476
                for (int i = 0; i < points.length; i++) {
477
                        if (i == 0) {
478
                                gpx.moveTo(points[i].getX(), points[i].getY());
479
                        } else {
480
                                gpx.lineTo(points[i].getX(), points[i].getY());
481
                        }
482
                }
483
                if (p!=null){
484
                        gpx.lineTo(p.getX(),p.getY());
485
                        gpx.closePath();
486
                        IGeometry polyline = ShapeFactory.createPolyline2D(gpx);
487
                        return polyline;
488
                }
489
                gpx.closePath();
490
                IGeometry polygon = ShapeFactory.createPolygon2D(gpx);
491
                return polygon;
492
        }
493

    
494
        /*
495
         * (non-Javadoc)
496
         *
497
         * @see com.iver.cit.gvsig.gui.cad.CADTool#addvalue(double)
498
         */
499
        public void addValue(double d) {
500
        }
501

    
502
        public String getStatus() {
503
                try {
504
                        SelectionCADToolState actualState = (SelectionCADToolState) _fsm
505
                                        .getPreviousState();
506
                        String status = actualState.getName();
507

    
508
                        return status;
509
                } catch (NullPointerException e) {
510
                        return "Selection.FirstPoint";
511
                }
512
        }
513

    
514

    
515

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

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

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

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

    
532

    
533
                if ((status.equals("Selection.FirstPoint"))
534
                                || (status.equals("Selection.WithSelectedFeatures"))) {
535
                        PluginServices.getMDIManager().setWaitCursor();
536
                        firstPoint = new Point2D.Double(x, y);
537
                        vle.selectWithPoint(x,y);
538
                        PluginServices.getMDIManager().restoreCursor();
539
                }
540
                ArrayList selectedRow = vle.getSelectedRow();
541
                if (selectedRow.size() > 0) {
542
                        nextState = "Selection.WithSelectedFeatures";
543
                        return true;
544
                } else {
545
                        {
546
                                nextState = "Selection.SecondPoint";
547
                                return true;
548
                        }
549
                }
550
        }
551

    
552
        public int selectHandlers(double x, double y, InputEvent event) {
553
                Point2D auxPoint = new Point2D.Double(x, y);
554

    
555
                VectorialLayerEdited vle = getVLE();
556
                ArrayList selectedHandler = vle.getSelectedHandler();
557
                ArrayList selectedRow = vle.getSelectedRow();
558
                System.out.println("DENTRO DE selectHandlers. selectedRow.size= "
559
                                + selectedRow.size());
560
                selectedHandler.clear();
561

    
562
                // Se comprueba si se pincha en una gemometr?a
563
                PluginServices.getMDIManager().setWaitCursor();
564

    
565
                double tam = getCadToolAdapter().getMapControl().getViewPort()
566
                                .toMapDistance(tolerance);
567

    
568
                Handler[] handlers = null;
569
                rowselectedHandlers.clear();
570
                for (int i = 0; i < selectedRow.size(); i++) {
571
                        IRowEdited rowEd = (IRowEdited) selectedRow.get(i);
572

    
573
                        IFeature fea = (IFeature) rowEd.getLinkedRow();
574
                        handlers = fea.getGeometry().getHandlers(IGeometry.SELECTHANDLER);
575
                        // y miramos los handlers de cada entidad seleccionada
576
                        double min = tam;
577
                        // int hSel = -1;
578

    
579
                        for (int j = 0; j < handlers.length; j++) {
580
                                Point2D handlerPoint = handlers[j].getPoint();
581
                                double distance = auxPoint.distance(handlerPoint);
582
                                if (distance <= min) {
583
                                        min = distance;
584
                                        // hSel = j;
585
                                        selectedHandler.add(handlers[j]);
586
                                        rowselectedHandlers.add(rowEd);
587
                                }
588
                        }
589
                }
590
                PluginServices.getMDIManager().restoreCursor();
591

    
592
                int numHandlesSelected = selectedHandler.size();
593

    
594
                /*
595
                 * if (numHandlesSelected == 0) selectFeatures(x,y);
596
                 */
597

    
598
                return numHandlesSelected;
599
        }
600

    
601
        public String getType() {
602
                return type;
603
        }
604

    
605
        public void setType(String type) {
606
                if (type.equals("S") || type.equals("s")){
607
                        this.type=PluginServices.getText(this,"simple");
608
                }else if (type.equals("OR") || type.equals("or")){
609
                        this.type=PluginServices.getText(this,"out_rectangle");
610
                }else if (type.equals("IP") || type.equals("ip")){
611
                        this.type=PluginServices.getText(this,"inside_polygon");
612
                }else if (type.equals("CP") || type.equals("cp")){
613
                        this.type=PluginServices.getText(this,"cross_polygon");
614
                }else if (type.equals("OP") || type.equals("op")){
615
                        this.type=PluginServices.getText(this,"out_polygon");
616
                }else if (type.equals("IC") || type.equals("ic")){
617
                        this.type=PluginServices.getText(this,"inside_circle");
618
                }else if (type.equals("CC") || type.equals("cc")){
619
                        this.type=PluginServices.getText(this,"cross_circle");
620
                }else if (type.equals("OC") || type.equals("oc")){
621
                        this.type=PluginServices.getText(this,"cross_circle");
622
                }else if (type.equals(PluginServices.getText(this,"select_all"))){
623
                        selectAll();
624
                        init();
625
                }else{
626
                        this.type = type;
627
                }
628
                pointsPolygon.clear();
629
        }
630

    
631
        public String toString() {
632
                return "_selection";
633
        }
634

    
635
}