Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / tools / PanListenerImpl.java @ 43510

History | View | Annotate | Download (3.97 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.geom.Point2D;
28
import java.awt.geom.Rectangle2D;
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.geom.primitive.Envelope;
36
import org.gvsig.fmap.mapcontext.ViewPort;
37
import org.gvsig.fmap.mapcontrol.MapControl;
38
import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent;
39
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42
43
44
45
/**
46
 * <p>Listener for moving the extent of the associated {@link MapControl MapControl} object
47
 *  according the movement between the initial and final points of line determined by the movement
48
 *  dragging with the third button of the mouse.</p>
49
 *
50
 * <p>Updates the extent of its <code>ViewPort</code> with the new position.</p>
51
 *
52
 * @author Vicente Caballero Navarro
53
 */
54
public class PanListenerImpl implements PanListener {
55
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
56
        private static final Logger logger = LoggerFactory.getLogger(PanListenerImpl.class);
57
        /**
58
         * The image to display when the cursor is active.
59
         */
60
//        private final Image ipan = PluginServices.getIconTheme().get("cursor-pan").getImage();
61
62
        /**
63
         * Reference to the <code>MapControl</code> object that uses.
64
         */
65
        private MapControl mapControl;
66
67
        /**
68
           * <p>Creates a new listener for changing the position of the extent of the associated {@link MapControl MapControl} object.</p>
69
         *
70
         * @param mapControl the <code>MapControl</code> where will be applied the changes
71
         */
72
        public PanListenerImpl(MapControl mapControl) {
73
                this.mapControl = mapControl;
74
        }
75
76
        /*
77
         * (non-Javadoc)
78
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PanListener#move(com.iver.cit.gvsig.fmap.tools.Events.MoveEvent)
79
         */
80
        public void move(MoveEvent event) {
81
                ViewPort vp = mapControl.getMapContext().getViewPort();
82
83
                Point2D from = vp.toMapPoint(event.getFrom());
84
                Point2D to = vp.toMapPoint(event.getTo());
85
86
87
                Rectangle2D extent = vp.getExtent();
88
                double x = extent.getX() - (to.getX() - from.getX());
89
                double y = extent.getY() - (to.getY() - from.getY());
90
                double width = extent.getWidth();
91
                double height = extent.getHeight();
92
                Envelope r;
93
                try {
94
                        r = geomManager.createEnvelope(x, y, x+width, y+height, SUBTYPES.GEOM2D);
95
                        vp.setEnvelope(r);
96
                } catch (CreateEnvelopeException e) {
97 41971 jjdelcerro
                        logger.warn("Error creating the envelope", e);
98 40435 jjdelcerro
                }
99
100
        }
101
102
        /*
103
         * (non-Javadoc)
104
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
105
         */
106
        public Image getImageCursor() {
107
                return IconThemeHelper.getImage("cursor-pan");
108
        }
109
110
        /*
111
         * (non-Javadoc)
112
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
113
         */
114
        public boolean cancelDrawing() {
115
                return true;
116
        }
117
}