Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / tools / PanListenerImpl.java @ 33411

History | View | Annotate | Download (4.46 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.Point2D;
45
import java.awt.geom.Rectangle2D;
46
47
import javax.swing.ImageIcon;
48
49 27411 jpiera
import org.gvsig.fmap.geom.GeometryLocator;
50
import org.gvsig.fmap.geom.GeometryManager;
51
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
52
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
53 21500 vcaballero
import org.gvsig.fmap.geom.primitive.Envelope;
54 27019 jpiera
import org.gvsig.fmap.geom.util.UtilFunctions;
55 21203 vcaballero
import org.gvsig.fmap.mapcontext.ViewPort;
56
import org.gvsig.fmap.mapcontrol.MapControl;
57
import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent;
58
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener;
59 27411 jpiera
import org.slf4j.Logger;
60
import org.slf4j.LoggerFactory;
61 21203 vcaballero
62
63
64
/**
65
 * <p>Listener for moving the extent of the associated {@link MapControl MapControl} object
66
 *  according the movement between the initial and final points of line determined by the movement
67
 *  dragging with the third button of the mouse.</p>
68 21500 vcaballero
 *
69 21203 vcaballero
 * <p>Updates the extent of its <code>ViewPort</code> with the new position.</p>
70
 *
71
 * @author Vicente Caballero Navarro
72
 */
73
public class PanListenerImpl implements PanListener {
74 27411 jpiera
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
75
        private static final Logger logger = LoggerFactory.getLogger(PanListenerImpl.class);
76 21203 vcaballero
        /**
77
         * The image to display when the cursor is active.
78
         */
79
        private final Image ipan = new ImageIcon(MapControl.class.getResource(
80
                                "images/Hand.gif")).getImage();
81
82
        /**
83
         * The cursor used to work with this tool listener.
84 21500 vcaballero
         *
85 21203 vcaballero
         * @see #getCursor()
86
         */
87 23645 vcaballero
//        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(ipan,
88
//                        new Point(16, 16), "");
89 21203 vcaballero
90
        /**
91
         * Reference to the <code>MapControl</code> object that uses.
92
         */
93
        private MapControl mapControl;
94
95
        /**
96
           * <p>Creates a new listener for changing the position of the extent of the associated {@link MapControl MapControl} object.</p>
97 21500 vcaballero
         *
98 21203 vcaballero
         * @param mapControl the <code>MapControl</code> where will be applied the changes
99
         */
100
        public PanListenerImpl(MapControl mapControl) {
101
                this.mapControl = mapControl;
102
        }
103
104
        /*
105
         * (non-Javadoc)
106
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PanListener#move(com.iver.cit.gvsig.fmap.tools.Events.MoveEvent)
107
         */
108
        public void move(MoveEvent event) {
109
                ViewPort vp = mapControl.getMapContext().getViewPort();
110
111
                Point2D from = vp.toMapPoint(event.getFrom());
112
                Point2D to = vp.toMapPoint(event.getTo());
113
114 21500 vcaballero
115 21203 vcaballero
                Rectangle2D extent = vp.getExtent();
116 21500 vcaballero
                double x = extent.getX() - (to.getX() - from.getX());
117
                double y = extent.getY() - (to.getY() - from.getY());
118
                double width = extent.getWidth();
119
                double height = extent.getHeight();
120 27411 jpiera
                Envelope r;
121
                try {
122
                        r = geomManager.createEnvelope(x, y, x+width, y+height, SUBTYPES.GEOM2D);
123
                        vp.setEnvelope(r);
124
                } catch (CreateEnvelopeException e) {
125
                        logger.error("Error creating the envelope", e);
126
                }
127
128 21203 vcaballero
        }
129
130
        /*
131
         * (non-Javadoc)
132
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
133
         */
134 23645 vcaballero
        public Image getImageCursor() {
135
                return ipan;
136 21203 vcaballero
        }
137
138
        /*
139
         * (non-Javadoc)
140
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
141
         */
142
        public boolean cancelDrawing() {
143
                return true;
144
        }
145
}