Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / LinkListener.java @ 24759

History | View | Annotate | Download (5.3 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.project.documents.view.toolListeners;
42

    
43
import java.awt.Component;
44
import java.awt.Image;
45
import java.awt.geom.Point2D;
46
import java.net.URI;
47

    
48
import javax.swing.JOptionPane;
49

    
50
import org.apache.log4j.Logger;
51
import org.gvsig.fmap.dal.exception.ReadException;
52
import org.gvsig.fmap.mapcontext.layers.FLayer;
53
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
54
import org.gvsig.fmap.mapcontrol.MapControl;
55
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
56
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
57
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
58

    
59
import com.iver.andami.PluginServices;
60
import com.iver.cit.gvsig.gui.panels.LinkPanel;
61
import com.iver.cit.gvsig.project.documents.view.gui.View;
62

    
63

    
64
/**
65
 * <p>Listener that gets, if exists, the associated link at the feature that's at the position selection of an active, selected
66
 *  and vector layer of the associated <code>MapControl</code>; and displays
67
 *  that linked data (image, text, ...) on a dialog.</p>
68
 *
69
 * <p>Listens a single click of any mouse's button.</p>
70
 *
71
 * @author Vicente Caballero Navarro
72
 */
73
public class LinkListener implements PointListener {
74
        /**
75
         * Object used to log messages for this listener.
76
         */
77
        private static Logger logger = Logger.getLogger(InfoListener.class.getName());
78

    
79
        /**
80
         * The image to display when the cursor is active.
81
         */
82
        private final Image img = PluginServices.getIconTheme()
83
                .get("cursor-hiperlink").getImage();
84

    
85
        /**
86
         * The cursor used to work with this tool listener.
87
         *
88
         * @see #getCursor()
89
         */
90
//        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
91
//                        new Point(16, 16), "");
92

    
93
        /**
94
         * Reference to the <code>MapControl</code> object that uses.
95
         */
96
        private MapControl mapCtrl;
97

    
98
        /**
99
         * Identifies the link as an image.
100
         */
101
        public static final int TYPELINKIMAGE=0;
102

    
103
        /**
104
         * Identifies the link as text.
105
         */
106
        public static final int TYPELINKTEXT=1;
107

    
108
        /**
109
         * <p>Creates a new <code>LinkListener</code> object.</p>
110
         *
111
         * @param mc the <code>MapControl</code> where will be applied the changes
112
         */
113
        public LinkListener(MapControl mc) {
114
                this.mapCtrl = mc;
115
        }
116

    
117
        /*
118
         * (non-Javadoc)
119
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
120
         */
121
        public void point(PointEvent event) throws BehaviorException {
122
                Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
123
                View view=(View)PluginServices.getMDIManager().getActiveWindow();
124
                FLayer[] sel = mapCtrl.getMapContext().getLayers().getActives();
125

    
126
                URI[] uri=null;
127

    
128
                for (int i = 0; i < sel.length; i++) {
129
                        FLayer laCapa = sel[i];
130
            if (laCapa.allowLinks())
131
            {
132
                    FLyrVect lyrVect = (FLyrVect) laCapa;
133
                    double tol = mapCtrl.getViewPort().toMapDistance(3);
134
                    try {
135
                                        uri=lyrVect.getLink(pReal,tol);
136
                                } catch (ReadException e) {
137
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Error" +
138
                                    " Error accediendo a la fuente de datos.");
139
                    return;
140
                                }
141
                    if (uri == null){
142
                            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Error" +
143
                                            " no has seleccionado una geometr�a para realizar HyperLink.");
144
                            return;
145
                    }
146
                    for(int j=0; j<uri.length;j++){
147
                            if(uri[j]!=null){
148
                                    LinkPanel lpanel = new LinkPanel (uri[j], lyrVect.getLinkProperties().getType());
149
                                    PluginServices.getMDIManager().addWindow(lpanel);
150
                            }
151
                    }
152
            }
153
                }
154
        }
155

    
156
        /*
157
         * (non-Javadoc)
158
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
159
         */
160
        public Image getImageCursor() {
161
                return img;
162
        }
163

    
164
        /*
165
         * (non-Javadoc)
166
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
167
         */
168
        public boolean cancelDrawing() {
169
                return false;
170
        }
171

    
172
        /*
173
         * (non-Javadoc)
174
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
175
         */
176
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
177
        }
178
}