Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / LinkListener.java @ 23642

History | View | Annotate | Download (5.44 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.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.net.URI;
50
import javax.swing.ImageIcon;
51
import javax.swing.JOptionPane;
52

    
53
import org.apache.log4j.Logger;
54
import org.gvsig.fmap.data.ReadException;
55
import org.gvsig.fmap.mapcontext.layers.FLayer;
56
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
57
import org.gvsig.fmap.mapcontrol.MapControl;
58
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
59
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
60
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
61

    
62
import com.iver.andami.PluginServices;
63
import com.iver.andami.persistence.generate.PluginsStatus;
64
import com.iver.cit.gvsig.gui.panels.LinkPanel;
65
import com.iver.cit.gvsig.project.documents.view.gui.View;
66

    
67

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

    
83
        /**
84
         * The image to display when the cursor is active.
85
         */
86
        private final Image img = PluginServices.getIconTheme()
87
                .get("cursor-hiperlink").getImage();
88

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

    
97
        /**
98
         * Reference to the <code>MapControl</code> object that uses.
99
         */
100
        private MapControl mapCtrl;
101

    
102
        /**
103
         * Identifies the link as an image.
104
         */
105
        public static final int TYPELINKIMAGE=0;
106

    
107
        /**
108
         * Identifies the link as text.
109
         */
110
        public static final int TYPELINKTEXT=1;
111

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

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

    
130
                URI[] uri=null;
131

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

    
160
        /*
161
         * (non-Javadoc)
162
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
163
         */
164
        public Image getImageCursor() {
165
                return img;
166
        }
167

    
168
        /*
169
         * (non-Javadoc)
170
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
171
         */
172
        public boolean cancelDrawing() {
173
                return false;
174
        }
175

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