root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / LinkListener.java @ 29596
History | View | Annotate | Download (5.32 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 org.gvsig.app.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.gvsig.andami.PluginServices; |
51 |
import org.gvsig.app.gui.panels.LinkPanel; |
52 |
import org.gvsig.app.project.documents.view.gui.View; |
53 |
import org.gvsig.fmap.dal.exception.ReadException; |
54 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
55 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
56 |
import org.gvsig.fmap.mapcontrol.MapControl; |
57 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
58 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
59 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener; |
60 |
import org.slf4j.Logger; |
61 |
import org.slf4j.LoggerFactory; |
62 |
|
63 |
|
64 |
|
65 |
/**
|
66 |
* <p>Listener that gets, if exists, the associated link at the feature that's at the position selection of an active, selected
|
67 |
* and vector layer of the associated <code>MapControl</code>; and displays
|
68 |
* that linked data (image, text, ...) on a dialog.</p>
|
69 |
*
|
70 |
* <p>Listens a single click of any mouse's button.</p>
|
71 |
*
|
72 |
* @author Vicente Caballero Navarro
|
73 |
*/
|
74 |
public class LinkListener implements PointListener { |
75 |
/**
|
76 |
* Object used to log messages for this listener.
|
77 |
*/
|
78 |
private static final Logger logger = LoggerFactory |
79 |
.getLogger(InfoListener.class); |
80 |
|
81 |
/**
|
82 |
* The image to display when the cursor is active.
|
83 |
*/
|
84 |
private final Image img = PluginServices.getIconTheme() |
85 |
.get("cursor-hiperlink").getImage();
|
86 |
|
87 |
/**
|
88 |
* The cursor used to work with this tool listener.
|
89 |
*
|
90 |
* @see #getCursor()
|
91 |
*/
|
92 |
// private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
|
93 |
// new Point(16, 16), "");
|
94 |
|
95 |
/**
|
96 |
* Reference to the <code>MapControl</code> object that uses.
|
97 |
*/
|
98 |
private MapControl mapCtrl;
|
99 |
|
100 |
/**
|
101 |
* Identifies the link as an image.
|
102 |
*/
|
103 |
public static final int TYPELINKIMAGE=0; |
104 |
|
105 |
/**
|
106 |
* Identifies the link as text.
|
107 |
*/
|
108 |
public static final int TYPELINKTEXT=1; |
109 |
|
110 |
/**
|
111 |
* <p>Creates a new <code>LinkListener</code> object.</p>
|
112 |
*
|
113 |
* @param mc the <code>MapControl</code> where will be applied the changes
|
114 |
*/
|
115 |
public LinkListener(MapControl mc) {
|
116 |
this.mapCtrl = mc;
|
117 |
} |
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
122 |
*/
|
123 |
public void point(PointEvent event) throws BehaviorException { |
124 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
125 |
View view=(View)PluginServices.getMDIManager().getActiveWindow(); |
126 |
FLayer[] sel = mapCtrl.getMapContext().getLayers().getActives();
|
127 |
|
128 |
URI[] uri=null; |
129 |
|
130 |
for (int i = 0; i < sel.length; i++) { |
131 |
FLayer laCapa = sel[i]; |
132 |
if (laCapa.allowLinks())
|
133 |
{ |
134 |
FLyrVect lyrVect = (FLyrVect) laCapa; |
135 |
double tol = mapCtrl.getViewPort().toMapDistance(3); |
136 |
try {
|
137 |
uri=lyrVect.getLink(pReal,tol); |
138 |
} catch (ReadException e) {
|
139 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Error" + |
140 |
" Error accediendo a la fuente de datos.");
|
141 |
return;
|
142 |
} |
143 |
if (uri == null){ |
144 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Error" + |
145 |
" no has seleccionado una geometr�a para realizar HyperLink.");
|
146 |
return;
|
147 |
} |
148 |
for(int j=0; j<uri.length;j++){ |
149 |
if(uri[j]!=null){ |
150 |
LinkPanel lpanel = new LinkPanel (uri[j], lyrVect.getLinkProperties().getType());
|
151 |
PluginServices.getMDIManager().addWindow(lpanel); |
152 |
} |
153 |
} |
154 |
} |
155 |
} |
156 |
} |
157 |
|
158 |
/*
|
159 |
* (non-Javadoc)
|
160 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
161 |
*/
|
162 |
public Image getImageCursor() { |
163 |
return img;
|
164 |
} |
165 |
|
166 |
/*
|
167 |
* (non-Javadoc)
|
168 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
169 |
*/
|
170 |
public boolean cancelDrawing() { |
171 |
return false; |
172 |
} |
173 |
|
174 |
/*
|
175 |
* (non-Javadoc)
|
176 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
177 |
*/
|
178 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
179 |
} |
180 |
} |