Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toolListeners / LinkListener.java @ 6247

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

    
54
import com.hardcode.gdbms.engine.data.DataSource;
55
import com.iver.andami.PluginServices;
56
import com.iver.andami.messages.NotificationManager;
57
import com.iver.cit.gvsig.fmap.DriverException;
58
import com.iver.cit.gvsig.fmap.MapControl;
59
import com.iver.cit.gvsig.fmap.layers.FBitSet;
60
import com.iver.cit.gvsig.fmap.layers.FLayer;
61
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
62
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
63
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
64
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
65
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
66
import com.iver.cit.gvsig.gui.View;
67
import com.iver.cit.gvsig.gui.panels.LinkPanel;
68
import com.iver.cit.gvsig.project.ProjectView;
69

    
70

    
71
/**
72
 * Listener que implementa PointListener para hacer el hiperlink.
73
 *
74
 * @author Vicente Caballero Navarro
75
 *
76
 */
77
public class LinkListener implements PointListener {
78
        private static Logger logger = Logger.getLogger(InfoListener.class.getName());
79
        private final Image img = new ImageIcon(MapControl.class.getResource(
80
                                "images/LinkCursor.gif")).getImage();
81
        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
82
                        new Point(16, 16), "");
83
        private MapControl mapCtrl;
84
        private BitSet[] bitset;
85
        private FLayer[] layers;
86
        private String field;
87
        private String ext="";
88
        private int type;
89

    
90
        /**
91
         * Crea un nuevo AreaListenerImpl.
92
         *
93
         * @param mc DOCUMENT ME!
94
         */
95
        public LinkListener(MapControl mc) {
96
                this.mapCtrl = mc;
97
        }
98

    
99
        /**
100
         * DOCUMENT ME!
101
         *
102
         * @param event DOCUMENT ME!
103
         * @throws BehaviorException
104
         *
105
         * @throws DriverException
106
         * @throws SAXException
107
         *
108
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
109
         */
110
        public void point(PointEvent event) throws BehaviorException {
111
                Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
112
                View view=(View)PluginServices.getMDIManager().getActiveView();
113
                FLayer[] sel = mapCtrl.getMapContext().getLayers().getActives();
114

    
115
                bitset = new BitSet[sel.length];
116
                layers = new FLayer[sel.length];
117

    
118
                for (int i = 0; i < sel.length; i++) {
119
                        FLayer laCapa = (FLayer) sel[i];
120
            if (laCapa instanceof FLyrVect)
121
            {
122
                    // Tolerancia de 3 pixels
123
                FLyrVect lyrVect = (FLyrVect) laCapa;
124
                double tol = mapCtrl.getViewPort().toMapDistance(3);
125

    
126
                FBitSet newBitSet;
127
                try {
128
                    newBitSet = lyrVect.queryByPoint(pReal, tol);
129
                    bitset[i] = newBitSet;
130
                    layers[i] = laCapa;
131
                } catch (DriverException e) {
132
                    // TODO Auto-generated catch block
133
                    e.printStackTrace();
134
                    throw new BehaviorException("Fallo al consultar " + lyrVect.getName());
135
                }
136
            }
137
                        /* if ((laCapa instanceof VectorialData) &&
138
                                        (laCapa instanceof AlphanumericData)) {
139
                                QueryByPointVisitor visitor = new QueryByPointVisitor();
140
                                visitor.setLayer(laCapa);
141
                                visitor.setQueriedPoint(pReal);
142
                                visitor.setTolerance(mapCtrl.getMapContext().getViewPort()
143
                                                                                        .toMapDistance(3));
144
                                try {
145
                                        ((VectorialData) laCapa).process(visitor);
146
                                } catch (DriverException e) {
147
                                        throw new BehaviorException("No se pudo procesar la capa",e);
148
                                } catch (VisitException e) {
149
                                        throw new RuntimeException(e);
150
                                }
151
                                bitset[i] = visitor.getBitSet();
152
                                layers[i] = laCapa;
153
                        } */
154
                }
155

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

    
167
                                        ds.start();
168

    
169
                                        //boolean exist=false;
170
                                        int idField;
171
                    idField = ds.getFieldIndexByName(field);
172
                    if (idField != -1)
173
                    {
174
                                                for (int j = bitset[i].nextSetBit(0); j >= 0;
175
                                                                j = bitset[i].nextSetBit(j + 1))
176
                                                {
177
                                                        LinkPanel linkpanel = new LinkPanel(field,
178
                                                                        ds.getFieldValue(j, idField).toString(),ext,type);
179
                                                                PluginServices.getMDIManager().addView(linkpanel);
180

    
181
                                                }
182
                        }
183

    
184
                                        logger.debug("ds.stop()");
185
                                        ds.stop();
186

    
187
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
188
                                        NotificationManager.addError("Error formateando los resultados", e);
189
                                } catch (DriverException e) {
190
                                        NotificationManager.addError("Error formateando los resultados", e);
191
                                }
192
                        }
193

    
194
                }
195
        }
196

    
197
        /**
198
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
199
         */
200
        public Cursor getCursor() {
201
                return cur;
202
        }
203

    
204
        /**
205
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
206
         */
207
        public boolean cancelDrawing() {
208
                return false;
209
        }
210

    
211
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
212
                // TODO Auto-generated method stub
213

    
214
        }
215
}