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