root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / InfoListener.java @ 33657
History | View | Annotate | Download (5.56 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.Image; |
44 |
import java.awt.Point; |
45 |
import java.util.HashMap; |
46 |
import java.util.Map; |
47 |
|
48 |
import javax.swing.JDialog; |
49 |
|
50 |
import org.gvsig.andami.PluginServices; |
51 |
import org.gvsig.andami.messages.NotificationManager; |
52 |
import org.gvsig.app.project.documents.view.info.gui.FInfoDialog; |
53 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
54 |
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint; |
55 |
import org.gvsig.fmap.mapcontrol.MapControl; |
56 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
57 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.LayersDynObjectSetComponent; |
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 |
import org.gvsig.tools.dynobject.DynObjectSet; |
62 |
|
63 |
/**
|
64 |
* Listener that looks for information at the point selected by one
|
65 |
* click of any mouse's button, in the active layers of the associated
|
66 |
* <code>MapControl</code>, and displays that data on a {@link FInfoDialog
|
67 |
* FInfoDialog} dialog.
|
68 |
*
|
69 |
* @author -2009 Vicente Caballero Navarro
|
70 |
* @author 2009- gvSIG Team
|
71 |
*/
|
72 |
public class InfoListener implements PointListener { |
73 |
|
74 |
/**
|
75 |
* Object used to log messages for this listener.
|
76 |
*/
|
77 |
// private static final Logger logger = LoggerFactory.getLogger(InfoListener.class);
|
78 |
|
79 |
/**
|
80 |
* The image to display when the cursor is active.
|
81 |
*/
|
82 |
private final Image img = PluginServices.getIconTheme() |
83 |
.get("cursor-query-information").getImage();
|
84 |
|
85 |
/**
|
86 |
* Reference to the <code>MapControl</code> object that uses.
|
87 |
*/
|
88 |
private MapControl mapCtrl;
|
89 |
|
90 |
/**
|
91 |
* Radius as tolerance around the selected point, the area will be used to
|
92 |
* look for information.
|
93 |
*/
|
94 |
private static int TOL = 7; |
95 |
|
96 |
/**
|
97 |
* <p>
|
98 |
* Creates a new <code>InfoListener</code> object.
|
99 |
* </p>
|
100 |
*
|
101 |
* @param mc
|
102 |
* the <code>MapControl</code> where will be applied the changes
|
103 |
*/
|
104 |
public InfoListener(MapControl mc) {
|
105 |
this.mapCtrl = mc;
|
106 |
} |
107 |
|
108 |
public void point(PointEvent event) throws BehaviorException { |
109 |
try {
|
110 |
|
111 |
Point imagePoint =
|
112 |
new Point((int) event.getPoint().getX(), (int) event.getPoint() |
113 |
.getY()); |
114 |
|
115 |
int numLayersInfoable = 0; |
116 |
double tol = mapCtrl.getViewPort().toMapDistance(TOL);
|
117 |
|
118 |
FLayer[] sel = mapCtrl.getMapContext().getLayers().getActives();
|
119 |
Map<String, DynObjectSet> layer2info = |
120 |
new HashMap<String, DynObjectSet>(sel.length); |
121 |
|
122 |
for (int i = 0; i < sel.length; i++) { |
123 |
FLayer laCapa = sel[i]; |
124 |
if (laCapa instanceof InfoByPoint) { |
125 |
InfoByPoint layer = (InfoByPoint) laCapa; |
126 |
DynObjectSet info = |
127 |
layer.getInfo(imagePoint, tol, null, false); |
128 |
layer2info.put(laCapa.getName(), info); |
129 |
numLayersInfoable++; |
130 |
} |
131 |
} |
132 |
|
133 |
// TODO: set the writable parameter to true to activate
|
134 |
// edition of the info by point information.
|
135 |
LayersDynObjectSetComponent infoComponent = |
136 |
MapControlLocator.getMapControlManager() |
137 |
.createLayersDynObjectSetComponent(layer2info, false);
|
138 |
FInfoDialog dlgInfo = new FInfoDialog(infoComponent);
|
139 |
|
140 |
if (numLayersInfoable > 0) { |
141 |
if (PluginServices.getMainFrame() == null) { |
142 |
JDialog dialog = new JDialog(); |
143 |
dlgInfo.setPreferredSize(dlgInfo.getSize()); |
144 |
dialog.getContentPane().add(dlgInfo); |
145 |
dialog.setModal(false);
|
146 |
dialog.pack(); |
147 |
dialog.setVisible(true);
|
148 |
|
149 |
} else {
|
150 |
dlgInfo = |
151 |
(FInfoDialog) PluginServices.getMDIManager().addWindow( |
152 |
dlgInfo); |
153 |
} |
154 |
|
155 |
} |
156 |
} catch (Exception e) { |
157 |
NotificationManager.addError("Info by Point", e);
|
158 |
e.printStackTrace(); |
159 |
} |
160 |
} |
161 |
|
162 |
public Image getImageCursor() { |
163 |
return img;
|
164 |
} |
165 |
|
166 |
public boolean cancelDrawing() { |
167 |
return false; |
168 |
} |
169 |
|
170 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
171 |
// Nothing to do
|
172 |
} |
173 |
} |