root / tags / v2_0_0_Build_2050 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / MapOverviewPanListener.java @ 38653
History | View | Annotate | Download (7.14 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.event.InputEvent; |
45 |
import java.awt.event.MouseEvent; |
46 |
import java.awt.geom.Point2D; |
47 |
|
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.app.gui.styling.SymbolSelector; |
50 |
import org.gvsig.app.project.documents.view.MapOverview; |
51 |
import org.gvsig.fmap.geom.GeometryLocator; |
52 |
import org.gvsig.fmap.geom.GeometryManager; |
53 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
54 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
55 |
import org.gvsig.fmap.geom.primitive.Envelope; |
56 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
57 |
import org.gvsig.fmap.mapcontext.ViewPort; |
58 |
import org.gvsig.fmap.mapcontrol.MapControl; |
59 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
60 |
import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent; |
61 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener; |
62 |
import org.slf4j.Logger; |
63 |
import org.slf4j.LoggerFactory; |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
/**
|
69 |
* <p>Listener for moving the extent of the associated {@link MapOverview MapOverview} object
|
70 |
* according the movement between the initial and final points of line determined by the movement
|
71 |
* dragging with the third button of the mouse.</p>
|
72 |
*
|
73 |
* <p>Updates the extent of its <code>ViewPort</code> with the new position.</p>
|
74 |
*
|
75 |
* @author Vicente Caballero Navarro
|
76 |
*/
|
77 |
public class MapOverviewPanListener implements PanListener { |
78 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
79 |
private static final Logger logger = LoggerFactory.getLogger(MapOverviewPanListener.class); |
80 |
|
81 |
/**
|
82 |
* The image to display when the cursor is active.
|
83 |
*/
|
84 |
private final Image icursor = PluginServices.getIconTheme().get("cursor-crux").getImage(); |
85 |
|
86 |
/**
|
87 |
* The cursor used to work with this tool listener.
|
88 |
*
|
89 |
* @see #getCursor()
|
90 |
*/
|
91 |
// private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(icursor,
|
92 |
// new Point(16, 16), "");
|
93 |
|
94 |
/**
|
95 |
* Reference to the <code>MapControl</code> object that uses.
|
96 |
*/
|
97 |
protected MapControl mapControl;
|
98 |
|
99 |
/**
|
100 |
* <p>Creates a new listener for changing the position of the extent of the associated {@link MapOverview MapOverview} object.</p>
|
101 |
*
|
102 |
* @param mapControl the <code>MapControl</code> object which represents the <code>MapOverview</code>
|
103 |
*/
|
104 |
public MapOverviewPanListener(MapControl mapControl) {
|
105 |
this.mapControl = mapControl;
|
106 |
} |
107 |
|
108 |
/*
|
109 |
* (non-Javadoc)
|
110 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
111 |
*/
|
112 |
public Image getImageCursor() { |
113 |
return icursor;
|
114 |
} |
115 |
|
116 |
/*
|
117 |
* (non-Javadoc)
|
118 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
119 |
*/
|
120 |
public boolean cancelDrawing() { |
121 |
return true; |
122 |
} |
123 |
|
124 |
/*
|
125 |
public void move(MoveEvent event) throws BehaviorException {
|
126 |
if (!checkModifiers(event.getEvent().getModifiers())){
|
127 |
return;
|
128 |
}
|
129 |
|
130 |
ViewPort vp = mapControl.getMapContext().getViewPort();
|
131 |
MapOverview mov=(MapOverview) this.mapControl;
|
132 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort();
|
133 |
if (vp.getExtent() != null) {
|
134 |
Point2D p = vp.toMapPoint(event.getTo());
|
135 |
Rectangle2D r = (Rectangle2D) vpView.getExtent().clone();
|
136 |
r.setRect(p.getX() - (r.getWidth() / 2),
|
137 |
p.getY() - (r.getHeight() / 2), r.getWidth(), r.getHeight());
|
138 |
//vpView.setExtent(r);
|
139 |
double scale;
|
140 |
double escalaX;
|
141 |
double escalaY;
|
142 |
double newHeight;
|
143 |
double newWidth;
|
144 |
double xCenter = r.getCenterX();
|
145 |
double yCenter = r.getCenterY();
|
146 |
|
147 |
escalaX = mapControl.getWidth() / r.getWidth();
|
148 |
escalaY = mapControl.getHeight() / r.getHeight();
|
149 |
Rectangle2D adjustedExtent = new Rectangle2D.Double();
|
150 |
|
151 |
if (escalaX < escalaY) {
|
152 |
scale = escalaX;
|
153 |
newHeight = mapControl.getHeight() / scale;
|
154 |
adjustedExtent.setRect(xCenter - (r.getWidth() / 2.0),
|
155 |
yCenter - (newHeight / 2.0), r.getWidth(), newHeight);
|
156 |
} else {
|
157 |
scale = escalaY;
|
158 |
newWidth = mapControl.getWidth() / scale;
|
159 |
adjustedExtent.setRect(xCenter - (newWidth / 2.0),
|
160 |
yCenter - (r.getHeight() / 2.0), newWidth,
|
161 |
r.getHeight());
|
162 |
}
|
163 |
mov.refreshOverView(adjustedExtent);
|
164 |
}
|
165 |
|
166 |
}
|
167 |
*/
|
168 |
|
169 |
/*
|
170 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PanListener#move(MoveEvent)
|
171 |
*/
|
172 |
public void move(MoveEvent event) throws BehaviorException { |
173 |
|
174 |
|
175 |
if (!checkModifiers(event.getEvent())){
|
176 |
return;
|
177 |
} |
178 |
System.out.println("mapOvervierPan"); |
179 |
MapOverview mov=(MapOverview) this.mapControl;
|
180 |
ViewPort vp = mov.getViewPort(); |
181 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
182 |
|
183 |
if (vp.getExtent() != null && vpView.getExtent() != null) { |
184 |
|
185 |
// recogemos la forma de la vista actual
|
186 |
Envelope curEnvelope = vpView.getAdjustedExtent(); |
187 |
// traducimos las coordenadas en px de la ultima posicion del raton
|
188 |
// a coordenadas de la vista
|
189 |
Point2D thePoint= vp.toMapPoint( event.getTo());
|
190 |
|
191 |
double diffx =
|
192 |
(curEnvelope.getMaximum(0) - curEnvelope.getMinimum(0)) / 2; |
193 |
double diffy =
|
194 |
(curEnvelope.getMaximum(1) - curEnvelope.getMinimum(1)) / 2; |
195 |
// Creamos un envelope del mismo tama�o
|
196 |
// con la coordenadas del punto del raton,
|
197 |
// teniendo en cuenta que estas sera el
|
198 |
// centro del recuadro
|
199 |
|
200 |
Envelope envelope; |
201 |
try {
|
202 |
envelope = geomManager.createEnvelope( |
203 |
thePoint.getX() - diffx, |
204 |
thePoint.getY() - diffy, |
205 |
thePoint.getX() + diffx, |
206 |
thePoint.getY() + diffy, |
207 |
SUBTYPES.GEOM2D |
208 |
); |
209 |
// cambiamos la posicion
|
210 |
mov.refreshOverView(envelope); |
211 |
vpView.setEnvelope(envelope); |
212 |
} catch (CreateEnvelopeException e) {
|
213 |
logger.error("Error creating the envelope", e);
|
214 |
} |
215 |
mov.getAssociatedMapContext().invalidate(); |
216 |
} |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Determines if has pressed the button 3 of the mouse.
|
221 |
*/
|
222 |
private boolean checkModifiers(MouseEvent event) { |
223 |
|
224 |
int modifiers = event.getModifiers();
|
225 |
/*
|
226 |
int keyPressedMask = InputEvent.BUTTON2_MASK;
|
227 |
|
228 |
*** No se porque el boton derecho del raton devuelve
|
229 |
*** un modificador 'Meta + BUTTON3'. Pensaba que deberia
|
230 |
*** devolver 'BUTTON2' ????
|
231 |
*/
|
232 |
int keyPressedMask = InputEvent.BUTTON3_MASK; |
233 |
return ((modifiers & keyPressedMask) == keyPressedMask);
|
234 |
} |
235 |
} |