root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / MapOverviewPanListener.java @ 7771
History | View | Annotate | Download (5.74 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.cit.gvsig.fmap.MapControl; |
55 |
import com.iver.cit.gvsig.fmap.ViewPort; |
56 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
57 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
58 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener; |
59 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
60 |
|
61 |
|
62 |
/**
|
63 |
* DOCUMENT ME!
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
*/
|
67 |
public class MapOverviewPanListener implements PanListener { |
68 |
private final Image icursor = new ImageIcon(MapControl.class.getResource( |
69 |
"images/CruxCursor.png")).getImage();
|
70 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(icursor, |
71 |
new Point(16, 16), ""); |
72 |
protected MapControl mapControl;
|
73 |
|
74 |
/**
|
75 |
* Crea un nuevo ZoomOutListenerImpl.
|
76 |
*
|
77 |
* @param mapControl DOCUMENT ME!
|
78 |
*/
|
79 |
public MapOverviewPanListener(MapControl mapControl) {
|
80 |
this.mapControl = mapControl;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
85 |
*/
|
86 |
public Cursor getCursor() { |
87 |
return cur;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
92 |
*/
|
93 |
public boolean cancelDrawing() { |
94 |
return true; |
95 |
} |
96 |
|
97 |
/*
|
98 |
public void move(MoveEvent event) throws BehaviorException {
|
99 |
if (!checkModifiers(event.getEvent().getModifiers())){
|
100 |
return;
|
101 |
}
|
102 |
|
103 |
ViewPort vp = mapControl.getMapContext().getViewPort();
|
104 |
MapOverview mov=(MapOverview) this.mapControl;
|
105 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort();
|
106 |
if (vp.getExtent() != null) {
|
107 |
Point2D p = vp.toMapPoint(event.getTo());
|
108 |
Rectangle2D r = (Rectangle2D) vpView.getExtent().clone();
|
109 |
r.setRect(p.getX() - (r.getWidth() / 2),
|
110 |
p.getY() - (r.getHeight() / 2), r.getWidth(), r.getHeight());
|
111 |
//vpView.setExtent(r);
|
112 |
double scale;
|
113 |
double escalaX;
|
114 |
double escalaY;
|
115 |
double newHeight;
|
116 |
double newWidth;
|
117 |
double xCenter = r.getCenterX();
|
118 |
double yCenter = r.getCenterY();
|
119 |
|
120 |
escalaX = mapControl.getWidth() / r.getWidth();
|
121 |
escalaY = mapControl.getHeight() / r.getHeight();
|
122 |
Rectangle2D adjustedExtent = new Rectangle2D.Double();
|
123 |
|
124 |
if (escalaX < escalaY) {
|
125 |
scale = escalaX;
|
126 |
newHeight = mapControl.getHeight() / scale;
|
127 |
adjustedExtent.setRect(xCenter - (r.getWidth() / 2.0),
|
128 |
yCenter - (newHeight / 2.0), r.getWidth(), newHeight);
|
129 |
} else {
|
130 |
scale = escalaY;
|
131 |
newWidth = mapControl.getWidth() / scale;
|
132 |
adjustedExtent.setRect(xCenter - (newWidth / 2.0),
|
133 |
yCenter - (r.getHeight() / 2.0), newWidth,
|
134 |
r.getHeight());
|
135 |
}
|
136 |
mov.refreshOverView(adjustedExtent);
|
137 |
}
|
138 |
|
139 |
}
|
140 |
*/
|
141 |
|
142 |
/**
|
143 |
* Es llamado mientras se hace del 'Dragg' del
|
144 |
* raton. Pinta el recuadro de la forma.
|
145 |
**/
|
146 |
public void move(MoveEvent event) throws BehaviorException { |
147 |
|
148 |
|
149 |
if (!checkModifiers(event.getEvent())){
|
150 |
return;
|
151 |
} |
152 |
System.out.println("mapOvervierPan"); |
153 |
MapOverview mov=(MapOverview) this.mapControl;
|
154 |
ViewPort vp = mov.getViewPort(); |
155 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
156 |
|
157 |
if (vp.getExtent() != null && vpView.getExtent() != null) { |
158 |
|
159 |
// recogemos la forma de la vista actual
|
160 |
Rectangle2D curRectangle = (Rectangle2D)vpView.getAdjustedExtent(); |
161 |
// traducimos las coordenadas en px de la ultima posicion del raton
|
162 |
// a coordenadas de la vista
|
163 |
Point2D thePoint= vp.toMapPoint( event.getTo());
|
164 |
|
165 |
Rectangle2D realRectangle = new Rectangle2D.Double(); |
166 |
double width =curRectangle.getWidth();
|
167 |
double height =curRectangle.getHeight();
|
168 |
// Creamos un rectangulo del mismo tama?o
|
169 |
// con la coordenadas del punto del raton,
|
170 |
// teniendo en cuenta que estas sera el
|
171 |
// centro del recuadro
|
172 |
realRectangle.setRect( |
173 |
thePoint.getX() - (width/2),
|
174 |
thePoint.getY() - (height/2),
|
175 |
width, |
176 |
height |
177 |
); |
178 |
// cambiamos la posicion
|
179 |
mov.refreshOverView(realRectangle); |
180 |
} |
181 |
} |
182 |
|
183 |
/**
|
184 |
* Comprueba que el estado de los botones
|
185 |
* sea el deseado para esta herramienta.
|
186 |
**/
|
187 |
private boolean checkModifiers(MouseEvent event) { |
188 |
|
189 |
int modifiers = event.getModifiers();
|
190 |
/*
|
191 |
int keyPressedMask = InputEvent.BUTTON2_MASK;
|
192 |
|
193 |
*** No se porque el boton derecho del raton devuelve
|
194 |
*** un modificador 'Meta + BUTTON3'. Pensaba que deberia
|
195 |
*** devolver 'BUTTON2' ????
|
196 |
*/
|
197 |
int keyPressedMask = InputEvent.BUTTON3_MASK; |
198 |
return ((modifiers & keyPressedMask) == keyPressedMask);
|
199 |
} |
200 |
} |