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