root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toolListeners / LinkListener.java @ 1774
History | View | Annotate | Download (5.81 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.toolListeners; |
42 |
|
43 |
import java.awt.Cursor; |
44 |
import java.awt.Image; |
45 |
import java.awt.Point; |
46 |
import java.awt.Toolkit; |
47 |
import java.awt.geom.Point2D; |
48 |
import java.util.BitSet; |
49 |
|
50 |
import javax.swing.ImageIcon; |
51 |
|
52 |
import org.apache.log4j.Logger; |
53 |
import org.xml.sax.SAXException; |
54 |
|
55 |
import com.hardcode.gdbms.engine.data.DataSource; |
56 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
57 |
import com.iver.andami.PluginServices; |
58 |
import com.iver.andami.messages.NotificationManager; |
59 |
import com.iver.cit.gvsig.fmap.DriverException; |
60 |
import com.iver.cit.gvsig.fmap.MapControl; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
62 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
64 |
import com.iver.cit.gvsig.fmap.operations.strategies.QueryByPointVisitor; |
65 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
66 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
67 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
68 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
69 |
import com.iver.cit.gvsig.gui.View; |
70 |
import com.iver.cit.gvsig.gui.Panels.LinkPanel; |
71 |
import com.iver.cit.gvsig.project.ProjectView; |
72 |
|
73 |
|
74 |
/**
|
75 |
* Listener que implementa PointListener para hacer el hiperlink.
|
76 |
*
|
77 |
* @author Vicente Caballero Navarro
|
78 |
*
|
79 |
*/
|
80 |
public class LinkListener implements PointListener { |
81 |
private static Logger logger = Logger.getLogger(InfoListener.class.getName()); |
82 |
private final Image img = new ImageIcon(MapControl.class.getResource( |
83 |
"images/LinkCursor.gif")).getImage();
|
84 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img, |
85 |
new Point(16, 16), ""); |
86 |
private MapControl mapCtrl;
|
87 |
private BitSet[] bitset; |
88 |
private FLayer[] layers; |
89 |
private String field; |
90 |
private String ext=""; |
91 |
private int type; |
92 |
|
93 |
/**
|
94 |
* Crea un nuevo AreaListenerImpl.
|
95 |
*
|
96 |
* @param mc DOCUMENT ME!
|
97 |
*/
|
98 |
public LinkListener(MapControl mc) {
|
99 |
this.mapCtrl = mc;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*
|
105 |
* @param event DOCUMENT ME!
|
106 |
* @throws BehaviorException
|
107 |
*
|
108 |
* @throws DriverException
|
109 |
* @throws SAXException
|
110 |
*
|
111 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
112 |
*/
|
113 |
public void point(PointEvent event) throws BehaviorException { |
114 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
115 |
View view=(View)PluginServices.getMDIManager().getActiveView(); |
116 |
FLayer[] sel = mapCtrl.getMapContext().getLayers().getActives();
|
117 |
|
118 |
bitset = new BitSet[sel.length]; |
119 |
layers = new FLayer[sel.length];
|
120 |
|
121 |
for (int i = 0; i < sel.length; i++) { |
122 |
FLayer laCapa = (FLayer) sel[i]; |
123 |
|
124 |
if ((laCapa instanceof VectorialData) && |
125 |
(laCapa instanceof AlphanumericData)) {
|
126 |
QueryByPointVisitor visitor = new QueryByPointVisitor();
|
127 |
visitor.setLayer(laCapa); |
128 |
visitor.setQueriedPoint(pReal); |
129 |
visitor.setTolerance(mapCtrl.getMapContext().getViewPort() |
130 |
.toMapDistance(3));
|
131 |
try {
|
132 |
((VectorialData) laCapa).process(visitor); |
133 |
} catch (DriverException e) {
|
134 |
throw new BehaviorException("No se pudo procesar la capa",e); |
135 |
} catch (VisitException e) {
|
136 |
throw new RuntimeException(e); |
137 |
} |
138 |
bitset[i] = visitor.getBitSet(); |
139 |
layers[i] = laCapa; |
140 |
} |
141 |
} |
142 |
|
143 |
if (bitset != null) { |
144 |
for (int i = 0; i < bitset.length; i++) { |
145 |
try {
|
146 |
ProjectView model=view.getModel(); |
147 |
type=model.getTypeLink(); |
148 |
field=model.getSelectedField(); |
149 |
//field = "NOM_PROVIN";
|
150 |
//ext=".png";
|
151 |
ext=model.getExtLink(); |
152 |
DataSource ds;
|
153 |
try {
|
154 |
ds = ((AlphanumericData) layers[i]).getRecordset(); |
155 |
} catch (DriverException e1) {
|
156 |
throw new BehaviorException("",e1); |
157 |
} |
158 |
ds.start(); |
159 |
|
160 |
boolean exist=false; |
161 |
int idField;
|
162 |
idField = ds.getFieldIndexByName(field); |
163 |
if (idField != -1) |
164 |
{ |
165 |
for (int j = bitset[i].nextSetBit(0); j >= 0; |
166 |
j = bitset[i].nextSetBit(j + 1))
|
167 |
{ |
168 |
LinkPanel linkpanel = new LinkPanel(field,
|
169 |
ds.getFieldValue(j, idField).toString(),ext,type); |
170 |
PluginServices.getMDIManager().addView(linkpanel); |
171 |
|
172 |
} |
173 |
} |
174 |
|
175 |
logger.debug("ds.stop()");
|
176 |
ds.stop(); |
177 |
|
178 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
179 |
NotificationManager.addError("Error formateando los resultados", e);
|
180 |
} |
181 |
} |
182 |
|
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
188 |
*/
|
189 |
public Cursor getCursor() { |
190 |
return cur;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
195 |
*/
|
196 |
public boolean cancelDrawing() { |
197 |
return false; |
198 |
} |
199 |
} |