Statistics
| Revision:

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

History | View | Annotate | Download (6.62 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.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

    
56
import com.hardcode.gdbms.engine.data.DataSource;
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.FBitSet;
62
import com.iver.cit.gvsig.fmap.layers.FLayer;
63
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
64
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
65
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
66
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.panels.LinkPanel;
69
import com.iver.cit.gvsig.project.documents.view.ProjectView;
70
import com.iver.cit.gvsig.project.documents.view.gui.View;
71

    
72

    
73
/**
74
 * Listener que implementa PointListener para hacer el hiperlink.
75
 *
76
 * @author Vicente Caballero Navarro
77
 *
78
 */
79
public class LinkListener implements PointListener {
80
        private static Logger logger = Logger.getLogger(InfoListener.class.getName());
81
        private final Image img = new ImageIcon(MapControl.class.getResource(
82
                                "images/LinkCursor.gif")).getImage();
83
        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
84
                        new Point(16, 16), "");
85
        private MapControl mapCtrl;
86
        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
        public LinkListener(MapControl mc) {
98
                this.mapCtrl = mc;
99
        }
100

    
101
        /**
102
         * DOCUMENT ME!
103
         *
104
         * @param event DOCUMENT ME!
105
         * @throws BehaviorException
106
         *
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
        public void point(PointEvent event) throws BehaviorException {
113
                Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
114
                View view=(View)PluginServices.getMDIManager().getActiveWindow();
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
            if (laCapa instanceof FLyrVect)
123
            {
124
                    // Tolerancia de 3 pixels
125
                FLyrVect lyrVect = (FLyrVect) laCapa;
126
                double tol = mapCtrl.getViewPort().toMapDistance(3);
127

    
128
                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
                                        (laCapa instanceof AlphanumericData)) {
141
                                QueryByPointVisitor visitor = new QueryByPointVisitor();
142
                                visitor.setLayer(laCapa);
143
                                visitor.setQueriedPoint(pReal);
144
                                visitor.setTolerance(mapCtrl.getMapContext().getViewPort()
145
                                                                                        .toMapDistance(3));
146
                                try {
147
                                        ((VectorialData) laCapa).process(visitor);
148
                                } catch (DriverException e) {
149
                                        throw new BehaviorException("No se pudo procesar la capa",e);
150
                                } catch (VisitException e) {
151
                                        throw new RuntimeException(e);
152
                                }
153
                                bitset[i] = visitor.getBitSet();
154
                                layers[i] = laCapa;
155
                        } */
156
                }
157

    
158
                if (bitset != null) {
159
                        for (int i = 0; i < bitset.length; i++) {
160
                                try {
161
                                        ProjectView model=view.getModel();
162
                                        type=model.getTypeLink();
163
                                        field=model.getSelectedField();
164
                                        //field = "NOM_PROVIN";
165
                                        //ext=".png";
166
                                        ext=model.getExtLink();
167
                                        if (layers[i] instanceof AlphanumericData) {
168

    
169
                                                DataSource ds = ((AlphanumericData) layers[i]).getRecordset();
170

    
171
                                                ds.start();
172

    
173
                                                //boolean exist=false;
174
                                                int idField;
175
                                                idField = ds.getFieldIndexByName(field);
176
                                                if (idField != -1)
177
                                                {
178
                                                        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
                                                                PluginServices.getMDIManager().addWindow(linkpanel);
184

    
185
                                                        }
186
                                                }
187

    
188
                                                logger.debug("ds.stop()");
189
                                                ds.stop();
190
                                        }else {
191
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"la_capa_no_tiene_hiperenlace");
192
                                        }
193

    
194
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
195
                                        NotificationManager.addError("Error formateando los resultados", e);
196
                                } catch (DriverException e) {
197
                                        NotificationManager.addError("Error formateando los resultados", e);
198
                                }
199
                        }
200

    
201
                }
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

    
218
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
219
                // TODO Auto-generated method stub
220

    
221
        }
222
}