svn-gvsig-desktop / tags / v2_0_0_Build_2011 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / LinkListener.java @ 33527
History | View | Annotate | Download (5.36 KB)
1 | 14821 | jmvivo | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 7771 | caballero | *
|
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 | 14821 | jmvivo | * Av. Blasco Ib��ez, 50
|
24 | 7771 | caballero | * 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 | 29596 | jpiera | package org.gvsig.app.project.documents.view.toolListeners; |
42 | 7771 | caballero | |
43 | import java.awt.Component; |
||
44 | import java.awt.Image; |
||
45 | import java.awt.geom.Point2D; |
||
46 | 13558 | evercher | import java.net.URI; |
47 | 24759 | jmvivo | |
48 | 7771 | caballero | import javax.swing.JOptionPane; |
49 | |||
50 | 29596 | jpiera | import org.gvsig.andami.PluginServices; |
51 | import org.gvsig.app.gui.panels.LinkPanel; |
||
52 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
53 | 24759 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
54 | 20994 | jmvivo | 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 | 28033 | cordinyana | import org.slf4j.Logger; |
61 | import org.slf4j.LoggerFactory; |
||
62 | 7771 | caballero | |
63 | |||
64 | |||
65 | /**
|
||
66 | 20098 | jmvivo | * <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 | 7771 | caballero | *
|
70 | 20098 | jmvivo | * <p>Listens a single click of any mouse's button.</p>
|
71 | *
|
||
72 | 7771 | caballero | * @author Vicente Caballero Navarro
|
73 | */
|
||
74 | public class LinkListener implements PointListener { |
||
75 | 20098 | jmvivo | /**
|
76 | * Object used to log messages for this listener.
|
||
77 | */
|
||
78 | 28033 | cordinyana | private static final Logger logger = LoggerFactory |
79 | .getLogger(InfoListener.class); |
||
80 | 20098 | jmvivo | |
81 | /**
|
||
82 | * The image to display when the cursor is active.
|
||
83 | */
|
||
84 | 14821 | jmvivo | private final Image img = PluginServices.getIconTheme() |
85 | .get("cursor-hiperlink").getImage();
|
||
86 | 20098 | jmvivo | |
87 | /**
|
||
88 | * The cursor used to work with this tool listener.
|
||
89 | 21359 | vcaballero | *
|
90 | 20098 | jmvivo | * @see #getCursor()
|
91 | */
|
||
92 | 23642 | vcaballero | // private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
|
93 | // new Point(16, 16), "");
|
||
94 | 20098 | jmvivo | |
95 | /**
|
||
96 | * Reference to the <code>MapControl</code> object that uses.
|
||
97 | */
|
||
98 | 7771 | caballero | private MapControl mapCtrl;
|
99 | 21359 | vcaballero | |
100 | 20098 | jmvivo | /**
|
101 | * Identifies the link as an image.
|
||
102 | */
|
||
103 | 10165 | caballero | public static final int TYPELINKIMAGE=0; |
104 | 21359 | vcaballero | |
105 | 20098 | jmvivo | /**
|
106 | * Identifies the link as text.
|
||
107 | */
|
||
108 | 10165 | caballero | public static final int TYPELINKTEXT=1; |
109 | 7771 | caballero | |
110 | /**
|
||
111 | 20098 | jmvivo | * <p>Creates a new <code>LinkListener</code> object.</p>
|
112 | 21359 | vcaballero | *
|
113 | 20098 | jmvivo | * @param mc the <code>MapControl</code> where will be applied the changes
|
114 | 7771 | caballero | */
|
115 | public LinkListener(MapControl mc) {
|
||
116 | this.mapCtrl = mc;
|
||
117 | } |
||
118 | |||
119 | 20098 | jmvivo | /*
|
120 | * (non-Javadoc)
|
||
121 | 7771 | caballero | * @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 | 31496 | jjdelcerro | DefaultViewPanel view=(DefaultViewPanel)PluginServices.getMDIManager().getActiveWindow(); |
126 | 7771 | caballero | FLayer[] sel = mapCtrl.getMapContext().getLayers().getActives();
|
127 | |||
128 | 13558 | evercher | URI[] uri=null; |
129 | 7771 | caballero | |
130 | for (int i = 0; i < sel.length; i++) { |
||
131 | 10626 | caballero | FLayer laCapa = sel[i]; |
132 | 13558 | evercher | if (laCapa.allowLinks())
|
133 | 7771 | caballero | { |
134 | 13558 | evercher | FLyrVect lyrVect = (FLyrVect) laCapa; |
135 | double tol = mapCtrl.getViewPort().toMapDistance(3); |
||
136 | 21359 | vcaballero | 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 | 13558 | evercher | if (uri == null){ |
144 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),"Error" + |
||
145 | 14821 | jmvivo | " no has seleccionado una geometr�a para realizar HyperLink.");
|
146 | 13558 | evercher | 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 | 7771 | caballero | } |
155 | } |
||
156 | } |
||
157 | |||
158 | 20098 | jmvivo | /*
|
159 | * (non-Javadoc)
|
||
160 | 23642 | vcaballero | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
161 | 7771 | caballero | */
|
162 | 23642 | vcaballero | public Image getImageCursor() { |
163 | return img;
|
||
164 | 7771 | caballero | } |
165 | |||
166 | 20098 | jmvivo | /*
|
167 | * (non-Javadoc)
|
||
168 | 7771 | caballero | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
169 | */
|
||
170 | public boolean cancelDrawing() { |
||
171 | return false; |
||
172 | } |
||
173 | |||
174 | 20098 | jmvivo | /*
|
175 | * (non-Javadoc)
|
||
176 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
||
177 | */
|
||
178 | 7771 | caballero | public void pointDoubleClick(PointEvent event) throws BehaviorException { |
179 | } |
||
180 | } |