svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toolListeners / MapOverviewChangeZoomListener.java @ 44455
History | View | Annotate | Download (6.69 KB)
1 | 40435 | jjdelcerro | /**
|
---|---|---|---|
2 | 40558 | jjdelcerro | * gvSIG. Desktop Geographic Information System.
|
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | 40558 | jjdelcerro | /**
|
25 | *
|
||
26 | */
|
||
27 | 40435 | jjdelcerro | package org.gvsig.app.project.documents.view.toolListeners; |
28 | |||
29 | import java.awt.Image; |
||
30 | import java.awt.event.InputEvent; |
||
31 | import java.awt.event.MouseEvent; |
||
32 | import java.awt.geom.Point2D; |
||
33 | import java.awt.geom.Rectangle2D; |
||
34 | |||
35 | import org.gvsig.andami.PluginServices; |
||
36 | import org.gvsig.app.gui.styling.SymbolSelector; |
||
37 | import org.gvsig.app.project.documents.view.MapOverview; |
||
38 | import org.gvsig.fmap.geom.GeometryLocator; |
||
39 | import org.gvsig.fmap.geom.GeometryManager; |
||
40 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
41 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
42 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
43 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
44 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
45 | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
||
46 | import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
||
47 | import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent; |
||
48 | import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener; |
||
49 | import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
||
50 | import org.slf4j.Logger; |
||
51 | import org.slf4j.LoggerFactory; |
||
52 | |||
53 | |||
54 | /**
|
||
55 | * <p>Listener for changes of the zoom caused by selecting a rectangular area on the associated
|
||
56 | * {@link MapOverview MapOverview} object with the first button of the mouse.</p>
|
||
57 | *
|
||
58 | * <p>If the kind of action was a movement on the associated object,
|
||
59 | * updates the <i>extent</i> of its rectangular area.</p>
|
||
60 | *
|
||
61 | * <p>If the kind of action is the selection of a rectangular area, and is bigger than 3x3 pixels,
|
||
62 | * applies a <i>zoom in</i> operation centering its <code>ViewPort</code> according the equivalent <i>extent</i>
|
||
63 | * in map coordinates.</p>
|
||
64 | *
|
||
65 | * @see ViewPort
|
||
66 | *
|
||
67 | * @author jmvivo
|
||
68 | */
|
||
69 | public class MapOverviewChangeZoomListener implements RectangleListener, PanListener { |
||
70 | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
71 | private static final Logger logger = LoggerFactory.getLogger(MapOverviewChangeZoomListener.class); |
||
72 | /**
|
||
73 | * The image to display when the cursor is active.
|
||
74 | */
|
||
75 | private final Image izoomin = PluginServices.getIconTheme() |
||
76 | .get("cursor-zoom-in").getImage();
|
||
77 | |||
78 | /**
|
||
79 | * The cursor used to work with this tool listener.
|
||
80 | *
|
||
81 | * @see #getCursor()
|
||
82 | */
|
||
83 | // private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin,new Point(16, 16), "");
|
||
84 | |||
85 | /**
|
||
86 | * Reference to the <code>MapControl</code> object that uses.
|
||
87 | */
|
||
88 | protected MapControl mapControl;
|
||
89 | |||
90 | /**
|
||
91 | * <p>Creates a new listener for changes of zoom at the associated {@link MapOverview MapOverview} object.</p>
|
||
92 | *
|
||
93 | * @param mapControl the <code>MapControl</code> object which represents the <code>MapOverview</code>
|
||
94 | */
|
||
95 | public MapOverviewChangeZoomListener(MapControl mapControl) {
|
||
96 | this.mapControl=mapControl;
|
||
97 | } |
||
98 | |||
99 | /*
|
||
100 | * (non-Javadoc)
|
||
101 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
|
||
102 | */
|
||
103 | public void rectangle(EnvelopeEvent event) throws BehaviorException { |
||
104 | |||
105 | if (!checkModifiers(event.getEvent())){
|
||
106 | return;
|
||
107 | } |
||
108 | MapOverview mov=(MapOverview) this.mapControl;
|
||
109 | ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
||
110 | ViewPort vp = mov.getViewPort(); |
||
111 | |||
112 | if (vp.getExtent() != null && vpView.getExtent() != null) { |
||
113 | |||
114 | // Recuperamos las coordenadas del evento en px
|
||
115 | Rectangle2D pxRectangle = event.getPixelCoordRect();
|
||
116 | // Recuperamos las coordenadas del evento en coordenadas de la vista de localizador
|
||
117 | Envelope realRectangle = event.getWorldCoordRect(); |
||
118 | |||
119 | if ((pxRectangle.getWidth() < 3) && (pxRectangle.getHeight() < 3)) |
||
120 | { |
||
121 | // rectangulo < 3 px no hacemos nada
|
||
122 | return;
|
||
123 | |||
124 | } else {
|
||
125 | // Cambiamos la extension de la vista asociada al localizador
|
||
126 | vpView.setEnvelope(realRectangle); |
||
127 | mov.getAssociatedMapContext().invalidate(); |
||
128 | vpView.setEnvelope(realRectangle); |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | |||
133 | /*
|
||
134 | * (non-Javadoc)
|
||
135 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
||
136 | */
|
||
137 | public Image getImageCursor() { |
||
138 | return izoomin;
|
||
139 | } |
||
140 | |||
141 | /* (non-Javadoc)
|
||
142 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
143 | */
|
||
144 | public boolean cancelDrawing() { |
||
145 | return true; //??? |
||
146 | } |
||
147 | |||
148 | /*
|
||
149 | * (non-Javadoc)
|
||
150 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PanListener#move(com.iver.cit.gvsig.fmap.tools.Events.MoveEvent)
|
||
151 | */
|
||
152 | public void move(MoveEvent event) throws BehaviorException { |
||
153 | |||
154 | |||
155 | if (!checkModifiers(event.getEvent())){
|
||
156 | return;
|
||
157 | } |
||
158 | // System.out.println("mapOvervierChangeZoom");
|
||
159 | MapOverview mov=(MapOverview) this.mapControl;
|
||
160 | ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
||
161 | ViewPort vp = mov.getViewPort(); |
||
162 | |||
163 | if (vp.getExtent() != null && vpView.getExtent() != null) { |
||
164 | |||
165 | // Creamos un recuadro con las coordenadas del raton
|
||
166 | // traducidas a la del mapa
|
||
167 | // Rectangle2D realRectangle = new Rectangle2D.Double();
|
||
168 | Point2D p1=vp.toMapPoint(event.getFrom());
|
||
169 | Point2D p2=vp.toMapPoint(event.getTo());
|
||
170 | Envelope realRectangle = null;
|
||
171 | double x=0; |
||
172 | double y=0; |
||
173 | double xMax=0; |
||
174 | double yMax=0; |
||
175 | if (p1.getX()<p2.getX()){
|
||
176 | x=p1.getX(); |
||
177 | xMax=p2.getX(); |
||
178 | }else{
|
||
179 | x=p2.getX(); |
||
180 | xMax=p1.getX(); |
||
181 | } |
||
182 | if (p1.getY()<p2.getY()){
|
||
183 | y=p1.getY(); |
||
184 | yMax=p2.getY(); |
||
185 | }else{
|
||
186 | y=p2.getY(); |
||
187 | yMax=p1.getY(); |
||
188 | } |
||
189 | try {
|
||
190 | realRectangle = geomManager.createEnvelope(x,y,xMax,yMax, SUBTYPES.GEOM2D); |
||
191 | } catch (CreateEnvelopeException e) {
|
||
192 | logger.error("Error creating the envelope", e);
|
||
193 | } |
||
194 | |||
195 | // realRectangle.setFrameFromDiagonal(vp.toMapPoint(event.getFrom()),vp.toMapPoint(event.getTo()));
|
||
196 | |||
197 | // Establecemos la forma
|
||
198 | mov.refreshOverView(realRectangle); |
||
199 | } |
||
200 | |||
201 | |||
202 | |||
203 | } |
||
204 | |||
205 | /**
|
||
206 | * Determines if has pressed the button 1 of the mouse.
|
||
207 | */
|
||
208 | private boolean checkModifiers(MouseEvent event) { |
||
209 | int modifiers = event.getModifiers();
|
||
210 | int keyPressedMask = InputEvent.BUTTON1_MASK; |
||
211 | return ((modifiers & keyPressedMask) == keyPressedMask);
|
||
212 | } |
||
213 | } |