root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / tools / ZoomInListenerImpl.java @ 38564
History | View | Annotate | Download (5.73 KB)
1 | 21203 | vcaballero | /* 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 org.gvsig.fmap.mapcontrol.tools; |
||
42 | |||
43 | import java.awt.Image; |
||
44 | import java.awt.geom.Rectangle2D; |
||
45 | |||
46 | 38564 | jjdelcerro | import org.gvsig.fmap.IconThemeHelper; |
47 | 35151 | jjdelcerro | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
48 | 27411 | jpiera | import org.gvsig.fmap.geom.GeometryLocator; |
49 | import org.gvsig.fmap.geom.GeometryManager; |
||
50 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
51 | 21500 | vcaballero | import org.gvsig.fmap.geom.primitive.Envelope; |
52 | 21203 | vcaballero | import org.gvsig.fmap.mapcontext.MapContext; |
53 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
54 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
55 | 21711 | vcaballero | import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
56 | 21203 | vcaballero | import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
57 | 38564 | jjdelcerro | import org.slf4j.Logger; |
58 | import org.slf4j.LoggerFactory; |
||
59 | 21203 | vcaballero | |
60 | |||
61 | |||
62 | /**
|
||
63 | * <p>Listener for doing a <i>zoom in</i> operation of the extent of the <code>ViewPort</code> of the associated {@link MapControl MapControl}
|
||
64 | * object, defining a rectangular area.</p>
|
||
65 | 21500 | vcaballero | *
|
66 | 21203 | vcaballero | * <p>If the area defined is smaller than 3 pixels x 3 pixels holds the zoom, otherwise, calculates the new extent <i>r</i>
|
67 | * with this equations:
|
||
68 | * <code><br>
|
||
69 | * double factor = 1/MapContext.ZOOMINFACTOR;<br>
|
||
70 | * Rectangle2D rect = event.getWorldCoordRect();<br>
|
||
71 | * Rectangle2D.Double r = new Rectangle2D.Double();<br>
|
||
72 | 21500 | vcaballero | * ViewPort vp = mapCtrl.getMapContext().getViewPort();<br>
|
73 | 21203 | vcaballero | * double nuevoX = rect.getMaxX() - ((vp.getExtent().getWidth() * factor) / 2.0);<br>
|
74 | * double nuevoY = rect.getMaxY() - ((vp.getExtent().getHeight() * factor) / 2.0);<br>
|
||
75 | * Rectangle2D.Double r; // This will be the new extent<br>
|
||
76 | * r.x = nuevoX;<br>
|
||
77 | * r.y = nuevoY;<br>
|
||
78 | * r.width = vp.getExtent().getWidth() * factor;<br>
|
||
79 | * r.height = vp.getExtent().getHeight() * factor;<br>
|
||
80 | * vp.setExtent(r);
|
||
81 | * </code>
|
||
82 | * </p>
|
||
83 | 21500 | vcaballero | *
|
84 | 21203 | vcaballero | * <p>The ultimately extent will be an adaptation from that, calculated by the <code>ViewPort</code>
|
85 | * bearing in mind the ratio of the available rectangle where display the graphical information.</p>
|
||
86 | *
|
||
87 | * @see MapContext#ZOOMINFACTOR
|
||
88 | 21500 | vcaballero | * @see ViewPort#setEnvelope(Envelope)
|
89 | 21203 | vcaballero | * @see ZoomOutListenerImpl
|
90 | * @see ZoomOutRightButtonListener
|
||
91 | *
|
||
92 | * @author Vicente Caballero Navarro
|
||
93 | */
|
||
94 | public class ZoomInListenerImpl implements RectangleListener { |
||
95 | 27411 | jpiera | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
96 | private static final Logger logger = LoggerFactory.getLogger(ZoomInListenerImpl.class); |
||
97 | |||
98 | 21203 | vcaballero | /**
|
99 | * The image to display when the cursor is active.
|
||
100 | */
|
||
101 | 38564 | jjdelcerro | // private final Image izoomin;
|
102 | 21203 | vcaballero | |
103 | /**
|
||
104 | * Reference to the <code>MapControl</code> object that uses.
|
||
105 | */
|
||
106 | private MapControl mapCtrl;
|
||
107 | |||
108 | |||
109 | 35151 | jjdelcerro | /**
|
110 | *
|
||
111 | */
|
||
112 | public ZoomInListenerImpl() {
|
||
113 | 38564 | jjdelcerro | // this.izoomin = PluginServices.getIconTheme().get("cursor-zoom-in").getImage();
|
114 | 35151 | jjdelcerro | } |
115 | |||
116 | /**
|
||
117 | 21203 | vcaballero | * <p>Creates a new <code>ZoomInListenerImpl</code> object.</p>
|
118 | *
|
||
119 | * @param mapCtrl the <code>MapControl</code> where is defined the rectangle
|
||
120 | */
|
||
121 | public ZoomInListenerImpl(MapControl mapCtrl) {
|
||
122 | 35151 | jjdelcerro | this();
|
123 | 21203 | vcaballero | this.mapCtrl = mapCtrl;
|
124 | } |
||
125 | |||
126 | /*
|
||
127 | * (non-Javadoc)
|
||
128 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
|
||
129 | */
|
||
130 | 21711 | vcaballero | public void rectangle(EnvelopeEvent event) { |
131 | Envelope rect = event.getWorldCoordRect(); |
||
132 | 21203 | vcaballero | Rectangle2D pixelRect = event.getPixelCoordRect();
|
133 | |||
134 | 21500 | vcaballero | |
135 | 21203 | vcaballero | ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
136 | |||
137 | if ((pixelRect.getWidth() < 3) && (pixelRect.getHeight() < 3)) |
||
138 | { |
||
139 | if (vp.getExtent()!=null){ |
||
140 | double factor = 1/MapContext.ZOOMINFACTOR; |
||
141 | 22179 | jmvivo | double x = rect.getMaximum(0) - |
142 | 21203 | vcaballero | ((vp.getExtent().getWidth() * factor) / 2.0);
|
143 | 22179 | jmvivo | double y = rect.getMaximum(1) - |
144 | 21203 | vcaballero | ((vp.getExtent().getHeight() * factor) / 2.0);
|
145 | 21500 | vcaballero | double width = vp.getExtent().getWidth() * factor;
|
146 | double height = vp.getExtent().getHeight() * factor;
|
||
147 | 27411 | jpiera | Envelope r; |
148 | try {
|
||
149 | r = geomManager.createEnvelope(x, y, x + width, y + height, SUBTYPES.GEOM2D); |
||
150 | vp.setEnvelope(r); |
||
151 | } catch (CreateEnvelopeException e) {
|
||
152 | logger.error("Error creating the envelope", e);
|
||
153 | } |
||
154 | |||
155 | 21203 | vcaballero | } |
156 | } |
||
157 | else
|
||
158 | { |
||
159 | 21711 | vcaballero | vp.setEnvelope(event.getWorldCoordRect()); |
160 | 21203 | vcaballero | } |
161 | } |
||
162 | |||
163 | /*
|
||
164 | * (non-Javadoc)
|
||
165 | 23645 | vcaballero | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
166 | 21203 | vcaballero | */
|
167 | 23645 | vcaballero | public Image getImageCursor() { |
168 | 38564 | jjdelcerro | return IconThemeHelper.getImage("cursor-zoom-in"); |
169 | 21203 | vcaballero | } |
170 | |||
171 | /*
|
||
172 | * (non-Javadoc)
|
||
173 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
174 | */
|
||
175 | public boolean cancelDrawing() { |
||
176 | 32937 | jjdelcerro | logger.debug("cancelDrawing true");
|
177 | 21203 | vcaballero | return true; |
178 | } |
||
179 | } |