Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1010 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / RectangleSelectionListener.java @ 12804

History | View | Annotate | Download (3.86 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.fmap.tools;
42

    
43
import com.hardcode.driverManager.DriverLoadException;
44
import com.iver.cit.gvsig.fmap.DriverException;
45
import com.iver.cit.gvsig.fmap.MapControl;
46
import com.iver.cit.gvsig.fmap.layers.FBitSet;
47
import com.iver.cit.gvsig.fmap.layers.FLayer;
48
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
49
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent;
50
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener;
51

    
52
import java.awt.Cursor;
53
import java.awt.Image;
54
import java.awt.Point;
55
import java.awt.Toolkit;
56
import java.awt.geom.Rectangle2D;
57

    
58
import javax.swing.ImageIcon;
59

    
60

    
61
/**
62
 * Implementaci?n de la interfaz RectangleListener como herramienta para
63
 * realizar una selecci?n por rect?ngulo.
64
 *
65
 * @author Vicente Caballero Navarro
66
 */
67
public class RectangleSelectionListener implements RectangleListener {
68
        private final Image img = new ImageIcon(MapControl.class.getResource(
69
                                "images/RectSelectCursor.gif")).getImage();
70
        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
71
                        new Point(16, 16), "");
72
        private MapControl mapCtrl;
73

    
74
        /**
75
         * Crea un nuevo AreaListenerImpl.
76
         *
77
         * @param mc MapControl.
78
         */
79
        public RectangleSelectionListener(MapControl mc) {
80
                this.mapCtrl = mc;
81
        }
82

    
83
        /**
84
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
85
         */
86
        public void rectangle(RectangleEvent event) throws BehaviorException {
87
                try {
88
                        // mapCtrl.getMapContext().selectByRect(event.getWorldCoordRect());
89
            Rectangle2D rect = event.getWorldCoordRect();
90
            FLayer[] actives = mapCtrl.getMapContext()
91
                .getLayers().getActives();
92
            for (int i=0; i < actives.length; i++)
93
            {
94
                if (actives[i] instanceof FLyrVect) {
95
                    FLyrVect lyrVect = (FLyrVect) actives[i];
96
                    FBitSet oldBitSet = lyrVect.getSource().getRecordset().getSelection();
97
                    FBitSet newBitSet = lyrVect.queryByRect(rect);
98
                    if (event.getEvent().isControlDown())
99
                        newBitSet.xor(oldBitSet);
100
                    lyrVect.getRecordset().setSelection(newBitSet);
101
                }
102
            }
103

    
104
                } catch (DriverException e) {
105
                        throw new BehaviorException("No se pudo hacer la selecci?n");
106
                } catch (DriverLoadException e) {
107
                        throw new BehaviorException("No se pudo hacer la selecci?n");
108
                }
109
        }
110

    
111
        /**
112
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
113
         */
114
        public Cursor getCursor() {
115
                return cur;
116
        }
117

    
118
        /**
119
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
120
         */
121
        public boolean cancelDrawing() {
122
                return false;
123
        }
124
}