svn-gvsig-desktop / tags / v1_1_Build_1009 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / RectangleSelectionListener.java @ 12649
History | View | Annotate | Download (3.86 KB)
1 | 1100 | fjp | /* 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 | 457 | fernando | package com.iver.cit.gvsig.fmap.tools; |
42 | |||
43 | 3963 | caballero | import com.hardcode.driverManager.DriverLoadException; |
44 | 1050 | vcaballero | import com.iver.cit.gvsig.fmap.DriverException; |
45 | 1223 | fernando | import com.iver.cit.gvsig.fmap.MapControl; |
46 | 3422 | fjp | 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 | 1050 | vcaballero | import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
50 | import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
||
51 | |||
52 | 457 | fernando | import java.awt.Cursor; |
53 | import java.awt.Image; |
||
54 | import java.awt.Point; |
||
55 | import java.awt.Toolkit; |
||
56 | 3422 | fjp | import java.awt.geom.Rectangle2D; |
57 | 457 | fernando | |
58 | import javax.swing.ImageIcon; |
||
59 | |||
60 | |||
61 | 1050 | vcaballero | /**
|
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 | 1223 | fernando | private final Image img = new ImageIcon(MapControl.class.getResource( |
69 | 1050 | vcaballero | "images/RectSelectCursor.gif")).getImage();
|
70 | 457 | fernando | private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img, |
71 | 1050 | vcaballero | new Point(16, 16), ""); |
72 | 1223 | fernando | private MapControl mapCtrl;
|
73 | 1050 | vcaballero | |
74 | 457 | fernando | /**
|
75 | 1050 | vcaballero | * Crea un nuevo AreaListenerImpl.
|
76 | *
|
||
77 | * @param mc MapControl.
|
||
78 | */
|
||
79 | 1223 | fernando | public RectangleSelectionListener(MapControl mc) {
|
80 | 1050 | vcaballero | this.mapCtrl = mc;
|
81 | } |
||
82 | 457 | fernando | |
83 | /**
|
||
84 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
|
||
85 | */
|
||
86 | 1050 | vcaballero | public void rectangle(RectangleEvent event) throws BehaviorException { |
87 | 3963 | caballero | try {
|
88 | 3422 | fjp | // 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 | 3963 | caballero | { |
94 | 3422 | fjp | if (actives[i] instanceof FLyrVect) { |
95 | FLyrVect lyrVect = (FLyrVect) actives[i]; |
||
96 | 3963 | caballero | FBitSet oldBitSet = lyrVect.getSource().getRecordset().getSelection(); |
97 | 3422 | fjp | FBitSet newBitSet = lyrVect.queryByRect(rect); |
98 | if (event.getEvent().isControlDown())
|
||
99 | newBitSet.xor(oldBitSet); |
||
100 | 3963 | caballero | lyrVect.getRecordset().setSelection(newBitSet); |
101 | 3422 | fjp | } |
102 | } |
||
103 | 3963 | caballero | |
104 | 750 | fernando | } catch (DriverException e) {
|
105 | throw new BehaviorException("No se pudo hacer la selecci?n"); |
||
106 | 3963 | caballero | } catch (DriverLoadException e) {
|
107 | 12446 | caballero | throw new BehaviorException("No se pudo hacer la selecci?n"); |
108 | 750 | fernando | } |
109 | 457 | fernando | } |
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 | } |