svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / tools / ZoomOutRightButtonListener.java @ 43510
History | View | Annotate | Download (4.16 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40559 | jjdelcerro | * 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 | package org.gvsig.fmap.mapcontrol.tools; |
||
25 | |||
26 | import java.awt.Image; |
||
27 | import java.awt.event.MouseEvent; |
||
28 | import java.awt.geom.Point2D; |
||
29 | |||
30 | import org.gvsig.fmap.IconThemeHelper; |
||
31 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
32 | import org.gvsig.fmap.geom.GeometryLocator; |
||
33 | import org.gvsig.fmap.geom.GeometryManager; |
||
34 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
35 | import org.gvsig.fmap.mapcontext.MapContext; |
||
36 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
37 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
38 | import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
||
39 | import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener; |
||
40 | import org.slf4j.Logger; |
||
41 | import org.slf4j.LoggerFactory; |
||
42 | |||
43 | |||
44 | |||
45 | /**
|
||
46 | 41964 | jjdelcerro | * @deprecated use ZoomOutListenerImpl setting mouseButton to right in the Behavior.
|
47 | 40435 | jjdelcerro | */
|
48 | public class ZoomOutRightButtonListener implements PointListener { |
||
49 | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
50 | private static final Logger logger = LoggerFactory.getLogger(ZoomOutRightButtonListener.class); |
||
51 | 41964 | jjdelcerro | |
52 | 40435 | jjdelcerro | /**
|
53 | * Reference to the <code>MapControl</code> object that uses.
|
||
54 | */
|
||
55 | private MapControl mapControl;
|
||
56 | |||
57 | /**
|
||
58 | * <p>Creates a new <code>ZoomOutRightButtonListener</code> object.</p>
|
||
59 | *
|
||
60 | * @param mapControl the <code>MapControl</code> where will be applied the changes
|
||
61 | */
|
||
62 | public ZoomOutRightButtonListener(MapControl mapControl) {
|
||
63 | this.mapControl = mapControl;
|
||
64 | 41964 | jjdelcerro | logger.warn("Using deprecated class ZoomOutRightButtonListener");
|
65 | 40435 | jjdelcerro | } |
66 | |||
67 | /*
|
||
68 | * (non-Javadoc)
|
||
69 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
||
70 | */
|
||
71 | public void point(PointEvent event) { |
||
72 | if (event.getEvent().getButton() == MouseEvent.BUTTON3){ |
||
73 | logger.debug("Zoom out bot?n derecho");
|
||
74 | ViewPort vp = mapControl.getMapContext().getViewPort(); |
||
75 | Point2D p2 = vp.toMapPoint(event.getPoint());
|
||
76 | |||
77 | double nuevoX;
|
||
78 | double nuevoY;
|
||
79 | double factor = 1 / MapContext.ZOOMOUTFACTOR; |
||
80 | if (vp.getExtent() != null) { |
||
81 | nuevoX = p2.getX() |
||
82 | - ((vp.getExtent().getWidth() * factor) / 2.0);
|
||
83 | nuevoY = p2.getY() |
||
84 | - ((vp.getExtent().getHeight() * factor) / 2.0);
|
||
85 | double x = nuevoX;
|
||
86 | double y = nuevoY;
|
||
87 | double width = vp.getExtent().getWidth() * factor;
|
||
88 | double height = vp.getExtent().getHeight() * factor;
|
||
89 | |||
90 | try {
|
||
91 | vp.setEnvelope(geomManager.createEnvelope(x, y ,x + width, y + height, SUBTYPES.GEOM2D)); |
||
92 | } catch (CreateEnvelopeException e) {
|
||
93 | logger.error("Error creating the envelope", e);
|
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | /*
|
||
100 | * (non-Javadoc)
|
||
101 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
||
102 | */
|
||
103 | public Image getImageCursor() { |
||
104 | return IconThemeHelper.getImage("cursor-zoom-out"); |
||
105 | } |
||
106 | |||
107 | /*
|
||
108 | * (non-Javadoc)
|
||
109 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
110 | */
|
||
111 | public boolean cancelDrawing() { |
||
112 | logger.debug("cancelDrawing true");
|
||
113 | return true; |
||
114 | } |
||
115 | |||
116 | /*
|
||
117 | * (non-Javadoc)
|
||
118 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
||
119 | */
|
||
120 | public void pointDoubleClick(PointEvent event) { |
||
121 | // TODO Auto-generated method stub
|
||
122 | } |
||
123 | } |