Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / MapOverviewPanListener.java @ 14821

History | View | Annotate | Download (5.84 KB)

1
/* 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 com.iver.cit.gvsig.project.documents.view.toolListeners;
42

    
43
import java.awt.Cursor;
44
import java.awt.Image;
45
import java.awt.Point;
46
import java.awt.Toolkit;
47
import java.awt.event.InputEvent;
48
import java.awt.event.MouseEvent;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51

    
52
import javax.swing.ImageIcon;
53

    
54
import com.iver.andami.PluginServices;
55
import com.iver.cit.gvsig.fmap.MapControl;
56
import com.iver.cit.gvsig.fmap.ViewPort;
57
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
58
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent;
59
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener;
60
import com.iver.cit.gvsig.project.documents.view.MapOverview;
61

    
62

    
63
/**
64
 * DOCUMENT ME!
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class MapOverviewPanListener implements PanListener {
69
        private final Image icursor = PluginServices
70
                .getIconTheme().get("crux-cursor").getImage();
71
        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(icursor,
72
                        new Point(16, 16), "");
73
        protected MapControl mapControl;
74

    
75
        /**
76
         * Crea un nuevo ZoomOutListenerImpl.
77
         *
78
         * @param mapControl DOCUMENT ME!
79
         */
80
        public MapOverviewPanListener(MapControl mapControl) {
81
                this.mapControl = mapControl;
82
        }
83

    
84
        /**
85
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
86
         */
87
        public Cursor getCursor() {
88
                return cur;
89
        }
90

    
91
        /**
92
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
93
         */
94
        public boolean cancelDrawing() {
95
                return true;
96
        }
97

    
98
        /*
99
        public void move(MoveEvent event) throws BehaviorException {
100
                if (!checkModifiers(event.getEvent().getModifiers())){
101
                        return;
102
                }
103
                
104
                ViewPort vp = mapControl.getMapContext().getViewPort();
105
                MapOverview mov=(MapOverview) this.mapControl;
106
                ViewPort vpView=mov.getAssociatedMapContext().getViewPort();
107
                if (vp.getExtent() != null) {
108
                        Point2D p = vp.toMapPoint(event.getTo());
109
                        Rectangle2D r = (Rectangle2D) vpView.getExtent().clone();
110
                        r.setRect(p.getX() - (r.getWidth() / 2),
111
                                p.getY() - (r.getHeight() / 2), r.getWidth(), r.getHeight());
112
                        //vpView.setExtent(r);
113
                        double scale;
114
                        double escalaX;
115
                        double escalaY;
116
                        double newHeight;
117
                        double newWidth;
118
                        double xCenter = r.getCenterX();
119
                        double yCenter = r.getCenterY();
120

121
                        escalaX = mapControl.getWidth() / r.getWidth();
122
                        escalaY = mapControl.getHeight() / r.getHeight();
123
                        Rectangle2D adjustedExtent = new Rectangle2D.Double();
124

125
                        if (escalaX < escalaY) {
126
                                scale = escalaX;
127
                                newHeight = mapControl.getHeight() / scale;
128
                                adjustedExtent.setRect(xCenter - (r.getWidth() / 2.0),
129
                                        yCenter - (newHeight / 2.0), r.getWidth(), newHeight);
130
                        } else {
131
                                scale = escalaY;
132
                                newWidth = mapControl.getWidth() / scale;
133
                                adjustedExtent.setRect(xCenter - (newWidth / 2.0),
134
                                        yCenter - (r.getHeight() / 2.0), newWidth,
135
                                        r.getHeight());
136
                        }
137
                        mov.refreshOverView(adjustedExtent);
138
                }
139

140
        }
141
        */
142
        
143
        /** 
144
         * Es llamado mientras se hace del 'Dragg' del 
145
         * raton. Pinta el recuadro de la forma.
146
         **/
147
        public void move(MoveEvent event) throws BehaviorException {
148
                
149
                
150
                if (!checkModifiers(event.getEvent())){
151
                        return;
152
                }
153
                System.out.println("mapOvervierPan");
154
                MapOverview mov=(MapOverview) this.mapControl;
155
                ViewPort vp = mov.getViewPort();
156
                ViewPort vpView=mov.getAssociatedMapContext().getViewPort();
157

    
158
                if (vp.getExtent() != null && vpView.getExtent() != null) {
159
                        
160
                        // recogemos la forma de la vista actual
161
                        Rectangle2D curRectangle = (Rectangle2D)vpView.getAdjustedExtent();
162
                        // traducimos las coordenadas en px de la ultima posicion del raton 
163
                        // a coordenadas de la vista 
164
                        Point2D thePoint= vp.toMapPoint( event.getTo());
165
                        
166
                        Rectangle2D realRectangle = new Rectangle2D.Double();                
167
                        double width =curRectangle.getWidth();
168
                        double height =curRectangle.getHeight();
169
                        // Creamos un rectangulo del mismo tama�o
170
                        // con la coordenadas del punto del raton,
171
                        // teniendo en cuenta que estas sera el 
172
                        // centro del recuadro
173
                        realRectangle.setRect(
174
                                        thePoint.getX() - (width/2),
175
                                        thePoint.getY() - (height/2),
176
                                        width,
177
                                        height                                
178
                        );
179
                        // cambiamos la posicion
180
                        mov.refreshOverView(realRectangle);
181
                        vpView.setExtent(realRectangle);
182
                        mov.getAssociatedMapContext().invalidate();
183
                }
184
        }
185
        
186
        /** 
187
         * Comprueba que el estado de los botones
188
         * sea el deseado para esta herramienta.
189
         **/
190
        private boolean checkModifiers(MouseEvent event) {
191
                
192
                int modifiers = event.getModifiers();
193
                /*
194
                int keyPressedMask = InputEvent.BUTTON2_MASK;
195
                
196
                *** No se porque el boton derecho del raton devuelve
197
                *** un modificador 'Meta + BUTTON3'. Pensaba que deberia
198
                *** devolver 'BUTTON2' ???? 
199
                */                
200
                int keyPressedMask = InputEvent.BUTTON3_MASK;
201
                return ((modifiers & keyPressedMask) == keyPressedMask);
202
        }
203
}