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