Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / CADToolAdapter.java @ 4115

History | View | Annotate | Download (18.9 KB)

1
package com.iver.cit.gvsig.gui.cad;
2

    
3
import java.awt.Color;
4
import java.awt.Cursor;
5
import java.awt.Graphics;
6
import java.awt.Image;
7
import java.awt.Point;
8
import java.awt.Toolkit;
9
import java.awt.event.MouseEvent;
10
import java.awt.event.MouseWheelEvent;
11
import java.awt.geom.Point2D;
12
import java.awt.geom.Rectangle2D;
13
import java.awt.image.MemoryImageSource;
14
import java.io.IOException;
15
import java.util.List;
16
import java.util.Stack;
17

    
18
import com.iver.andami.PluginServices;
19
import com.iver.cit.gvsig.CADExtension;
20
import com.iver.cit.gvsig.fmap.ViewPort;
21
import com.iver.cit.gvsig.fmap.core.Handler;
22
import com.iver.cit.gvsig.fmap.core.IGeometry;
23
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
24
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
25
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
26
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
27
import com.iver.cit.gvsig.fmap.layers.FBitSet;
28
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
29
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
30
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener;
31
import com.iver.cit.gvsig.gui.View;
32
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool;
33
import com.vividsolutions.jts.geom.Envelope;
34
import com.vividsolutions.jts.index.SpatialIndex;
35

    
36
public class CADToolAdapter extends Behavior {
37
        private Stack cadToolStack = new Stack();
38

    
39
        // Para pasarle las coordenadas cuando se produce un evento textEntered
40
        private int lastX;
41

    
42
        private int lastY;
43

    
44
        private FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED);
45

    
46
        private Point2D mapAdjustedPoint;
47

    
48
        private boolean questionAsked = false;
49

    
50
        private Point2D adjustedPoint;
51

    
52
        private boolean snapping = false;
53

    
54
        private boolean adjustSnapping = false;
55

    
56
        private VectorialEditableAdapter vea;
57

    
58
        private CADGrid cadgrid = new CADGrid();
59

    
60
        private SpatialIndex spatialCache;
61

    
62
        /**
63
         * Pinta de alguna manera especial las geometrias seleccionadas para la
64
         * edici?n. En caso de que el snapping est? activado, pintar? el efecto del
65
         * mismo.
66
         * 
67
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
68
         */
69
        public void paintComponent(Graphics g) {
70
                super.paintComponent(g);
71
                drawCursor(g);
72
                getGrid().drawGrid(g);
73
                if (adjustedPoint != null) {
74
                        Point2D p = null;
75
                        if (mapAdjustedPoint != null) {
76
                                p = mapAdjustedPoint;
77
                        } else {
78
                                p = getMapControl().getViewPort().toMapPoint(adjustedPoint);
79
                        }
80
                        ((CADTool) cadToolStack.peek())
81
                                        .drawOperation(g, p.getX(), p.getY());
82
                }
83
        }
84

    
85
        /**
86
         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
87
         */
88
        public void mouseClicked(MouseEvent e) throws BehaviorException {
89
                if (e.getButton() == MouseEvent.BUTTON3) {
90
                        CADExtension.showPopup(e);
91
                }
92
        }
93

    
94
        /**
95
         * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
96
         */
97
        public void mouseEntered(MouseEvent e) throws BehaviorException {
98
                clearMouseImage();
99
        }
100

    
101
        /**
102
         * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
103
         */
104
        public void mouseExited(MouseEvent e) throws BehaviorException {
105
        }
106

    
107
        /**
108
         * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
109
         */
110
        public void mousePressed(MouseEvent e) throws BehaviorException {
111
                if (e.getButton() == MouseEvent.BUTTON1) {
112
                        ViewPort vp = getMapControl().getMapContext().getViewPort();
113
                        Point2D p;
114

    
115
                        if (mapAdjustedPoint != null) {
116
                                p = mapAdjustedPoint;
117
                        } else {
118
                                p = vp.toMapPoint(adjustedPoint);
119
                        }
120
                        transition(vea, new double[] { p.getX(), p.getY() });
121
                }
122
        }
123

    
124
        /**
125
         * Ajusta un punto de la imagen que se pasa como par?metro al grid si ?ste
126
         * est? activo y devuelve la distancia de un punto al punto ajustado
127
         * 
128
         * @param point
129
         * @param mapHandlerAdjustedPoint
130
         *            DOCUMENT ME!
131
         * 
132
         * @return Distancia del punto que se pasa como par?metro al punto ajustado
133
         */
134
        private double adjustToHandler(Point2D point,
135
                        Point2D mapHandlerAdjustedPoint) {
136
                // if (selection.cardinality() > 0) {
137
                double rw = getMapControl().getViewPort().toMapDistance(5);
138
                Point2D mapPoint = point;
139
                Rectangle2D r = new Rectangle2D.Double(mapPoint.getX() - rw / 2,
140
                                mapPoint.getY() - rw / 2, rw, rw);
141

    
142
                // int[] indexes = vea.getRowsIndexes(r);
143
                Envelope e = new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
144
                                r.getY() + r.getHeight());
145
                List l = getSpatialCache().query(e);
146
                double min = Double.MAX_VALUE;
147
                Point2D argmin = null;
148
                Point2D mapArgmin = null;
149

    
150
                for (int i = 0; i < l.size(); i++) {
151
                        IGeometry geometry = null;
152
                        geometry = (IGeometry) l.get(i);// getFeature(indexes[i]);
153
                        Handler[] handlers = geometry.getHandlers(IGeometry.SELECTHANDLER);
154

    
155
                        for (int j = 0; j < handlers.length; j++) {
156
                                Point2D handlerPoint = handlers[j].getPoint();
157
                                // System.err.println("handlerPoint= "+ handlerPoint);
158
                                Point2D handlerImagePoint = handlerPoint;
159
                                double dist = handlerImagePoint.distance(point);
160
                                if ((dist < getMapControl().getViewPort().toMapDistance(
161
                                                SelectionCADTool.tolerance))
162
                                                && (dist < min)) {
163
                                        min = dist;
164
                                        argmin = handlerImagePoint;
165
                                        mapArgmin = handlerPoint;
166
                                }
167
                        }
168
                }
169

    
170
                if (argmin != null) {
171
                        point.setLocation(argmin);
172

    
173
                        // Se hace el casting porque no se quiere redondeo
174
                        point.setLocation(argmin.getX(), argmin.getY());
175

    
176
                        mapHandlerAdjustedPoint.setLocation(mapArgmin);
177

    
178
                        return min;
179
                }
180

    
181
                return Double.MAX_VALUE;
182

    
183
        }
184

    
185
        /**
186
         * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
187
         */
188
        public void mouseReleased(MouseEvent e) throws BehaviorException {
189
                getMapControl().repaint();
190
        }
191

    
192
        /**
193
         * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
194
         */
195
        public void mouseDragged(MouseEvent e) throws BehaviorException {
196
                lastX = e.getX();
197
                lastY = e.getY();
198

    
199
                calculateSnapPoint(e.getPoint());
200
        }
201

    
202
        /**
203
         * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
204
         */
205
        public void mouseMoved(MouseEvent e) throws BehaviorException {
206

    
207
                lastX = e.getX();
208
                lastY = e.getY();
209

    
210
                calculateSnapPoint(e.getPoint());
211

    
212
                getMapControl().repaint();
213
        }
214

    
215
        private void clearMouseImage() {
216
                int[] pixels = new int[16 * 16];
217
                Image image = Toolkit.getDefaultToolkit().createImage(
218
                                new MemoryImageSource(16, 16, pixels, 0, 16));
219
                Cursor transparentCursor = Toolkit.getDefaultToolkit()
220
                                .createCustomCursor(image, new Point(0, 0), "invisiblecursor");
221

    
222
                getMapControl().setCursor(transparentCursor);
223
        }
224

    
225
        /**
226
         * DOCUMENT ME!
227
         * 
228
         * @param g
229
         *            DOCUMENT ME!
230
         */
231
        private void drawCursor(Graphics g) {
232

    
233
                Point2D p = adjustedPoint;
234

    
235
                if (p == null) {
236
                        getGrid().setViewPort(getMapControl().getViewPort());
237

    
238
                        return;
239
                }
240

    
241
                int size1 = 15;
242
                int size2 = 3;
243
                g.drawLine((int) (p.getX() - size1), (int) (p.getY()),
244
                                (int) (p.getX() + size1), (int) (p.getY()));
245
                g.drawLine((int) (p.getX()), (int) (p.getY() - size1),
246
                                (int) (p.getX()), (int) (p.getY() + size1));
247

    
248
                if (adjustedPoint != null) {
249
                        if (adjustSnapping) {
250
                                g.setColor(Color.ORANGE);
251
                                g.drawRect((int) (adjustedPoint.getX() - 6),
252
                                                (int) (adjustedPoint.getY() - 6), 12, 12);
253
                                g.drawRect((int) (adjustedPoint.getX() - 3),
254
                                                (int) (adjustedPoint.getY() - 3), 6, 6);
255
                                g.setColor(Color.MAGENTA);
256
                                g.drawRect((int) (adjustedPoint.getX() - 4),
257
                                                (int) (adjustedPoint.getY() - 4), 8, 8);
258

    
259
                                adjustSnapping = false;
260
                        } else {
261
                                g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2),
262
                                                (int) (size2 * 2), (int) (size2 * 2));
263
                        }
264
                }
265
        }
266

    
267
        /**
268
         * DOCUMENT ME!
269
         * 
270
         * @param point
271
         */
272
        private void calculateSnapPoint(Point point) {
273
                // Se comprueba el ajuste a rejilla
274

    
275
                Point2D gridAdjustedPoint = getMapControl().getViewPort().toMapPoint(
276
                                point);
277
                double minDistance = Double.MAX_VALUE;
278
                CADTool ct = (CADTool) cadToolStack.peek();
279
                if (ct instanceof SelectionCADTool
280
                                && ((SelectionCADTool) ct).getStatus().equals(
281
                                                "ExecuteMap.Initial")) {
282
                        mapAdjustedPoint = gridAdjustedPoint;
283
                        adjustedPoint = (Point2D) point.clone();
284
                } else {
285

    
286
                        minDistance = getGrid().adjustToGrid(gridAdjustedPoint);
287
                        if (minDistance < Double.MAX_VALUE) {
288
                                adjustedPoint = getMapControl().getViewPort().fromMapPoint(
289
                                                gridAdjustedPoint);
290
                                mapAdjustedPoint = gridAdjustedPoint;
291
                        } else {
292
                                mapAdjustedPoint = null;
293
                        }
294
                }
295
                Point2D handlerAdjustedPoint = null;
296

    
297
                // Se comprueba el ajuste a los handlers
298
                if (mapAdjustedPoint != null) {
299
                        handlerAdjustedPoint = (Point2D) mapAdjustedPoint.clone(); // getMapControl().getViewPort().toMapPoint(point);
300
                } else {
301
                        handlerAdjustedPoint = getMapControl().getViewPort().toMapPoint(
302
                                        point);
303
                }
304

    
305
                Point2D mapPoint = new Point2D.Double();
306
                double distance = adjustToHandler(handlerAdjustedPoint, mapPoint);
307

    
308
                if (distance < minDistance) {
309
                        adjustSnapping = true;
310
                        adjustedPoint = getMapControl().getViewPort().fromMapPoint(
311
                                        handlerAdjustedPoint);
312
                        mapAdjustedPoint = mapPoint;
313
                        minDistance = distance;
314
                }
315

    
316
                // Si no hay ajuste
317
                if (minDistance == Double.MAX_VALUE) {
318
                        adjustedPoint = point;
319
                        mapAdjustedPoint = null;
320
                }
321

    
322
        }
323

    
324
        /**
325
         * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)
326
         */
327
        public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException {
328
                getMapControl().cancelDrawing();
329
                ViewPort vp = getMapControl().getViewPort();
330
                // Point2D pReal = vp.toMapPoint(e.getPoint());
331

    
332
                Point2D pReal = new Point2D.Double(vp.getAdjustedExtent().getCenterX(),
333
                                vp.getAdjustedExtent().getCenterY());
334
                int amount = e.getWheelRotation();
335
                double nuevoX;
336
                double nuevoY;
337
                double factor;
338

    
339
                if (amount > 0) // nos acercamos
340
                {
341
                        factor = 0.9;
342
                } else // nos alejamos
343
                {
344
                        factor = 1.2;
345
                }
346
                Rectangle2D.Double r = new Rectangle2D.Double();
347
                if (vp.getExtent() != null) {
348
                        nuevoX = pReal.getX()
349
                                        - ((vp.getExtent().getWidth() * factor) / 2.0);
350
                        nuevoY = pReal.getY()
351
                                        - ((vp.getExtent().getHeight() * factor) / 2.0);
352
                        r.x = nuevoX;
353
                        r.y = nuevoY;
354
                        r.width = vp.getExtent().getWidth() * factor;
355
                        r.height = vp.getExtent().getHeight() * factor;
356

    
357
                        vp.setExtent(r);
358
                }
359
        }
360

    
361
        /**
362
         * M?todo que realiza las transiciones en las herramientas en funci?n de un
363
         * texto introducido en la consola
364
         * 
365
         * @param text
366
         *            DOCUMENT ME!
367
         */
368
        public void textEntered(String text) {
369
                if (text == null) {
370
                        transition("cancel");
371
                } else {
372
                        /*
373
                         * if ("".equals(text)) { transition("aceptar"); } else {
374
                         */
375
                        text = text.trim();
376

    
377
                        String[] numbers = text.split(",");
378
                        double[] values = null;
379

    
380
                        try {
381
                                if (numbers.length == 2) {
382
                                        // punto
383
                                        values = new double[] { Double.parseDouble(numbers[0]),
384
                                                        Double.parseDouble(numbers[1]) };
385
                                        transition(vea, values);
386
                                } else if (numbers.length == 1) {
387
                                        // valor
388
                                        values = new double[] { Double.parseDouble(numbers[0]) };
389
                                        transition(vea, values[0]);
390
                                }
391
                        } catch (NumberFormatException e) {
392
                                transition(vea, text);
393
                        }
394
                        // }
395
                }
396
                getMapControl().repaint();
397
        }
398

    
399
        /**
400
         * Transici?n por comando ("cancel", actionCommand de una herramienta, etc).
401
         * 
402
         * @param text
403
         *            DOCUMENT ME!
404
         */
405
        public void transition(String text) {
406
                transition(vea, text);
407
                // getMapControl().repaint();
408
        }
409

    
410
        /**
411
         * DOCUMENT ME!
412
         */
413
        public void configureMenu() {
414
                String[] desc = ((CADTool) cadToolStack.peek()).getDescriptions();
415
                // String[] labels = ((CADTool)
416
                // cadToolStack.peek()).getCurrentTransitions();
417
                CADExtension.clearMenu();
418

    
419
                for (int i = 0; i < desc.length; i++) {
420
                        if (desc[i] != null) {
421
                                CADExtension.addMenuEntry(desc[i]);// , labels[i]);
422
                        }
423
                }
424

    
425
        }
426

    
427
        /**
428
         * DOCUMENT ME!
429
         * 
430
         * @param text
431
         *            DOCUMENT ME!
432
         * @param source
433
         *            DOCUMENT ME!
434
         * @param sel
435
         *            DOCUMENT ME!
436
         * @param values
437
         *            DOCUMENT ME!
438
         */
439
        private void transition(VectorialEditableAdapter source, double[] values) {
440
                questionAsked = true;
441
                if (!cadToolStack.isEmpty()) {
442
                        CADTool ct = (CADTool) cadToolStack.peek();
443
                        // /String[] trs = ct.getAutomaton().getCurrentTransitions();
444
                        boolean esta = true;
445
                        /*
446
                         * for (int i = 0; i < trs.length; i++) { if
447
                         * (trs[i].toUpperCase().equals(text.toUpperCase())) esta = true; }
448
                         */
449
                        if (!esta) {
450
                                askQuestion();
451
                        } else {
452
                                ct.transition(values[0], values[1]);
453
                                // Si es la transici?n que finaliza una geometria hay que
454
                                // redibujar la vista.
455

    
456
                                askQuestion();
457
                                /*
458
                                 * if ((ret & Automaton.AUTOMATON_FINISHED) ==
459
                                 * Automaton.AUTOMATON_FINISHED) { popCadTool();
460
                                 * 
461
                                 * if (cadToolStack.isEmpty()) { pushCadTool(new
462
                                 * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
463
                                 * SelectionCadTool());
464
                                 * PluginServices.getMainFrame().setSelectedTool("selection"); }
465
                                 * 
466
                                 * askQuestion();
467
                                 * 
468
                                 * getMapControl().drawMap(false); } else { if (((CadTool)
469
                                 * cadToolStack.peek()).getAutomaton().checkState('c')) {
470
                                 * getMapControl().drawMap(false); }
471
                                 * 
472
                                 * if (!questionAsked) { askQuestion(); } }
473
                                 * 
474
                                 * configureMenu();
475
                                 */
476
                        }
477
                }
478
                configureMenu();
479
                PluginServices.getMainFrame().enableControls();
480
        }
481

    
482
        /**
483
         * DOCUMENT ME!
484
         * 
485
         * @param text
486
         *            DOCUMENT ME!
487
         * @param source
488
         *            DOCUMENT ME!
489
         * @param sel
490
         *            DOCUMENT ME!
491
         * @param values
492
         *            DOCUMENT ME!
493
         */
494
        private void transition(VectorialEditableAdapter source, double value) {
495
                questionAsked = true;
496
                if (!cadToolStack.isEmpty()) {
497
                        CADTool ct = (CADTool) cadToolStack.peek();
498
                        ct.transition(value);
499
                        askQuestion();
500
                }
501
                configureMenu();
502
                PluginServices.getMainFrame().enableControls();
503
        }
504

    
505
        private void transition(VectorialEditableAdapter source, String option) {
506
                questionAsked = true;
507
                if (!cadToolStack.isEmpty()) {
508
                        CADTool ct = (CADTool) cadToolStack.peek();
509
                        ct.transition(option);
510
                        askQuestion();
511
                }
512
                configureMenu();
513
                PluginServices.getMainFrame().enableControls();
514
        }
515

    
516
        /**
517
         * DOCUMENT ME!
518
         * 
519
         * @param value
520
         *            DOCUMENT ME!
521
         */
522
        public void setGrid(boolean value) {
523
                getGrid().setUseGrid(value);
524
                getGrid().setViewPort(getMapControl().getViewPort());
525
                getMapControl().drawMap(false);
526
        }
527

    
528
        /**
529
         * DOCUMENT ME!
530
         * 
531
         * @param activated
532
         *            DOCUMENT ME!
533
         */
534
        public void setSnapping(boolean activated) {
535
                snapping = activated;
536
        }
537

    
538
        /**
539
         * DOCUMENT ME!
540
         * 
541
         * @param x
542
         *            DOCUMENT ME!
543
         * @param y
544
         *            DOCUMENT ME!
545
         * @param dist
546
         *            DOCUMENT ME!
547
         */
548
        public void getSnapPoint(double x, double y, double dist) {
549
        }
550

    
551
        /**
552
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
553
         */
554
        public ToolListener getListener() {
555
                return new ToolListener() {
556
                        /**
557
                         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
558
                         */
559
                        public Cursor getCursor() {
560
                                return null;
561
                        }
562

    
563
                        /**
564
                         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
565
                         */
566
                        public boolean cancelDrawing() {
567
                                return false;
568
                        }
569
                };
570
        }
571

    
572
        /**
573
         * DOCUMENT ME!
574
         * 
575
         * @return DOCUMENT ME!
576
         */
577
        public CADTool getCadTool() {
578
                return (CADTool) cadToolStack.peek();
579
        }
580

    
581
        /**
582
         * DOCUMENT ME!
583
         * 
584
         * @param cadTool
585
         *            DOCUMENT ME!
586
         */
587
        public void pushCadTool(CADTool cadTool) {
588
                cadToolStack.push(cadTool);
589
                cadTool.setCadToolAdapter(this);
590
                // cadTool.initializeStatus();
591
                // cadTool.setVectorialAdapter(vea);
592
                /*
593
                 * int ret = cadTool.transition(null, editableFeatureSource, selection,
594
                 * new double[0]);
595
                 * 
596
                 * if ((ret & Automaton.AUTOMATON_FINISHED) ==
597
                 * Automaton.AUTOMATON_FINISHED) { popCadTool();
598
                 * 
599
                 * if (cadToolStack.isEmpty()) { pushCadTool(new
600
                 * com.iver.cit.gvsig.gui.cad.smc.gen.CADTool());//new
601
                 * SelectionCadTool());
602
                 * PluginServices.getMainFrame().setSelectedTool("selection"); }
603
                 * 
604
                 * askQuestion();
605
                 * 
606
                 * getMapControl().drawMap(false); }
607
                 */
608
        }
609

    
610
        /**
611
         * DOCUMENT ME!
612
         */
613
        public void popCadTool() {
614
                cadToolStack.pop();
615
        }
616

    
617
        /**
618
         * DOCUMENT ME!
619
         */
620
        public void askQuestion() {
621
                CADTool cadtool = (CADTool) cadToolStack.peek();
622
                /*
623
                 * if (cadtool..getStatus()==0){
624
                 * PluginServices.getMainFrame().addTextToConsole("\n"
625
                 * +cadtool.getName()); }
626
                 */
627
                View vista = (View) PluginServices.getMDIManager().getActiveView();
628
                vista.getConsolePanel().addText("\n" + cadtool.getQuestion() + ">");
629
                // ***PluginServices.getMainFrame().addTextToConsole("\n" +
630
                // cadtool.getQuestion());
631
                questionAsked = true;
632

    
633
        }
634

    
635
        /**
636
         * DOCUMENT ME!
637
         * 
638
         * @param cadTool
639
         *            DOCUMENT ME!
640
         */
641
        public void setCadTool(CADTool cadTool) {
642
                cadToolStack.clear();
643
                pushCadTool(cadTool);
644
                askQuestion();
645
        }
646

    
647
        /**
648
         * DOCUMENT ME!
649
         * 
650
         * @return DOCUMENT ME!
651
         */
652
        public VectorialEditableAdapter getVectorialAdapter() {
653
                return vea;
654
        }
655

    
656
        /**
657
         * DOCUMENT ME!
658
         * 
659
         * @param editableFeatureSource
660
         *            DOCUMENT ME!
661
         * @param selection
662
         *            DOCUMENT ME!
663
         */
664
        public void setVectorialAdapter(VectorialEditableAdapter vea) {
665
                this.vea = vea;
666
        }
667

    
668
        /**
669
         * DOCUMENT ME!
670
         * 
671
         * @return DOCUMENT ME!
672
         */
673
        /*
674
         * public CadMapControl getCadMapControl() { return cadMapControl; }
675
         */
676
        /**
677
         * DOCUMENT ME!
678
         * 
679
         * @param cadMapControl
680
         *            DOCUMENT ME!
681
         */
682
        /*
683
         * public void setCadMapControl(CadMapControl cadMapControl) {
684
         * this.cadMapControl = cadMapControl; }
685
         */
686

    
687
        /**
688
         * Elimina las geometr?as seleccionadas actualmente
689
         */
690
        private void delete() {
691
                vea.startComplexRow();
692
                FBitSet selection = getVectorialAdapter().getSelection();
693
                try {
694
                        int[] indexesToDel = new int[selection.cardinality()];
695
                        int j = 0;
696
                        for (int i = selection.nextSetBit(0); i >= 0; i = selection
697
                                        .nextSetBit(i + 1)) {
698
                                indexesToDel[j++] = i;
699
                                // /vea.removeRow(i);
700
                        }
701
                        for (j = indexesToDel.length - 1; j >= 0; j--) {
702
                                vea.removeRow(indexesToDel[j]);
703
                        }
704
                } catch (DriverIOException e) {
705
                        e.printStackTrace();
706
                } catch (IOException e) {
707
                        e.printStackTrace();
708
                } finally {
709
                        try {
710
                                vea.endComplexRow();
711
                        } catch (IOException e1) {
712
                                e1.printStackTrace();
713
                        } catch (DriverIOException e1) {
714
                                e1.printStackTrace();
715
                        }
716
                }
717
                System.out.println("clear Selection");
718
                selection.clear();
719
                getMapControl().drawMap(false);
720
        }
721

    
722
        /**
723
         * DOCUMENT ME!
724
         * 
725
         * @param b
726
         */
727
        public void setAdjustGrid(boolean b) {
728
                getGrid().setAdjustGrid(b);
729
        }
730

    
731
        /**
732
         * DOCUMENT ME!
733
         * 
734
         * @param actionCommand
735
         */
736
        public void keyPressed(String actionCommand) {
737
                if (actionCommand.equals("eliminar")) {
738
                        delete();
739
                } else if (actionCommand.equals("escape")) {
740
                        if (getMapControl().getTool().equals("cadtooladapter")) {
741
                                CADTool ct = (CADTool) cadToolStack.peek();
742
                                ct.end();
743
                                cadToolStack.clear();
744
                                pushCadTool(new SelectionCADTool());
745
                                getVectorialAdapter().getSelection().clear();
746
                                getMapControl().drawMap(false);
747
                                PluginServices.getMainFrame().setSelectedTool("SELCAD");
748
                                askQuestion();
749
                        }
750
                }
751

    
752
                PluginServices.getMainFrame().enableControls();
753

    
754
        }
755

    
756
        public CADGrid getGrid() {
757
                return cadgrid;
758
        }
759

    
760
        /**
761
         * @return Returns the spatialCache.
762
         */
763
        public SpatialIndex getSpatialCache() {
764
                return spatialCache;
765
        }
766

    
767
        /**
768
         * @param spatialCache
769
         *            The spatialCache to set.
770
         */
771
        public void setSpatialCache(SpatialIndex spatialCache) {
772
                this.spatialCache = spatialCache;
773
        }
774
}