Statistics
| Revision:

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

History | View | Annotate | Download (4.96 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.geom.Point2D;
48
import java.awt.geom.Rectangle2D;
49
import java.util.ArrayList;
50

    
51
import javax.swing.ImageIcon;
52

    
53
import org.apache.log4j.Logger;
54

    
55
import com.iver.cit.gvsig.fmap.MapControl;
56
import com.iver.cit.gvsig.fmap.ViewPort;
57
import com.iver.cit.gvsig.fmap.layers.FLayer;
58
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
59
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
60
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
61
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
62

    
63

    
64
/**
65
 *
66
 * @author Nacho Brodin (brodin_ign@gva.es)
67
 */
68
public class ZoomPixelCursorListener implements PointListener {
69
        private static Logger         logger = Logger.getLogger(ZoomPixelCursorListener.class.getName());
70
        private final Image         img = new ImageIcon(MapControl.class.getResource(
71
                                                                            "images/ZoomPixelCursor.gif")).getImage();
72
        private Cursor                         cur = Toolkit.getDefaultToolkit().createCustomCursor(        img,
73
                                                                                                                                                                        new Point(16, 16), "");
74
        private MapControl                 mapCtrl;
75

    
76
        /**
77
         * Crea un nuevo AreaListenerImpl.
78
         *
79
         * @param mc DOCUMENT ME!
80
         */
81
        public ZoomPixelCursorListener(MapControl mc) {
82
                this.mapCtrl = mc;
83
        }
84

    
85
        /* (non-Javadoc)
86
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
87
         */
88
        public void point(PointEvent event) throws BehaviorException {
89
                Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
90
                Point imagePoint = new Point((int) event.getPoint().getX(), (int) event.getPoint().getY());
91
                ViewPort v = mapCtrl.getMapContext().getViewPort();
92

    
93
                FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
94
                Rectangle2D ext = null;
95
                try{
96
                        ext = actives[0].getFullExtent();
97
                } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
98
                        e1.printStackTrace();
99
                }
100

    
101
            ArrayList attr = ((FLyrRaster)actives[0]).getSource().getAttributes();
102
            int width = 0, height = 0;
103
                   for (int i=0; i<attr.size(); i++) {
104
                        Object[] a = (Object []) attr.get(i);
105
                        if (a[0].toString().equals("Width"))
106
                                width = ((Integer)a[1]).intValue();
107
                        if (a[0].toString().equals("Height"))
108
                                height = ((Integer)a[1]).intValue();
109
                }
110

    
111

    
112
                   if(        ext != null &&
113
                           width != 0 &&
114
                        height != 0){
115

    
116
                double wcOriginCenterX = pReal.getX();
117
                double wcOriginCenterY = pReal.getY();
118

    
119
                //Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
120
                        double relacionPixelWcWidth =  (ext.getMaxX() - ext.getMinX())/width;
121
                        double relacionPixelWcHeight = (ext.getMaxY() - ext.getMinY())/height;
122
                        double desplazamientoX = ext.getMinX();
123
                        double desplazamientoY = ext.getMinY();
124

    
125
                        double wcOriginX = wcOriginCenterX - ((v.getImageWidth()*relacionPixelWcWidth)/2);
126
                        double wcOriginY = wcOriginCenterY - ((v.getImageHeight()*relacionPixelWcHeight)/2);
127

    
128
                        double wcDstMinX = wcOriginX;
129
                        double wcDstMinY = wcOriginY;
130
                        double wcDstMaxX = wcDstMinX + (v.getImageWidth()*relacionPixelWcWidth);
131
                        double wcDstMaxY = wcDstMinY + (v.getImageHeight()*relacionPixelWcHeight);
132

    
133
                        double wcDstWidth = wcDstMaxX - wcDstMinX;
134
                        double wcDstHeight = wcDstMaxY - wcDstMinY;
135

    
136
                        ext = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight);
137
                mapCtrl.getMapContext().getViewPort().setExtent(ext);
138
                   }
139
        }
140

    
141
        /**
142
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
143
         */
144
        public Cursor getCursor() {
145
                return cur;
146
        }
147

    
148
        /**
149
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
150
         */
151
        public boolean cancelDrawing() {
152
                return false;
153
        }
154

    
155
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
156
                // TODO Auto-generated method stub
157

    
158
        }
159

    
160
}