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