Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toolListeners / LinkListener.java @ 6877

History | View | Annotate | Download (6.58 KB)

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