Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.app / org.gvsig.raster.wcs.app.wcsclient / src / main / java / org / gvsig / raster / wcs / app / wcsclient / gui / toc / WCSZoomPixelCursorListener.java @ 1174

History | View | Annotate | Download (5.27 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.wcs.app.wcsclient.gui.toc;
23

    
24
import java.awt.Cursor;
25
import java.awt.Image;
26
import java.awt.Point;
27
import java.awt.Toolkit;
28
import java.awt.geom.Point2D;
29

    
30
import org.gvsig.andami.IconThemeHelper;
31
import org.gvsig.fmap.dal.exception.ReadException;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
35
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.fmap.mapcontext.ViewPort;
38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.fmap.mapcontrol.MapControl;
40
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
41
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
42
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
43
import org.gvsig.raster.wcs.app.wcsclient.layer.FLyrWCS;
44

    
45

    
46
/**
47
 * <p>Listener that executes a <i>zoom in</i> operation in the associated <code>MapControl</code>,
48
 *  having as center the point selected.</p>
49
 * 
50
 * <p>Listens a single click of any mouse's button.</p>
51
 * 
52
 * <p>The <i>zoom in</i> factor will depend on the maximum resolution of the <i>WCS</i> layers in
53
 *  the <code>MapControl</code>.</p>
54
 *
55
 * @author Nacho Brodin (brodin_ign@gva.es)
56
 */
57
public class WCSZoomPixelCursorListener implements PointListener {
58
        private static final GeometryManager         geomManager                                 = GeometryLocator.getGeometryManager();
59
        /**
60
         * Object used to log messages for this listener.
61
         */
62
        //private static Logger         logger = Logger.getLogger(WCSZoomPixelCursorListener.class.getName());
63

    
64
        /**
65
         * The image to display when the cursor is active.
66
         */        
67
        private final Image img = IconThemeHelper.getImageIcon("view-previsualize-area").getImage();
68

    
69
        /**
70
         * The cursor used to work with this tool listener.
71
         * 
72
         * @see #getCursor()
73
         */ 
74
        private Cursor                         cur = Toolkit.getDefaultToolkit().createCustomCursor(        img,
75

    
76
        /**
77
         * Reference to the <code>MapControl</code> object that uses.
78
         */                                                                                                                                                                        new Point(16, 16), "");
79
        private MapControl                 mapCtrl;
80

    
81
        /**
82
         * <p>Creates a new <code>WCSZoomPixelCursorListener</code> object.</p>
83
         * 
84
         * @param mc the <code>MapControl</code> where be applied the changes
85
         */
86
        public WCSZoomPixelCursorListener(MapControl mc) {
87
                this.mapCtrl = mc;
88
        }
89
        
90
        /*
91
         * (non-Javadoc)
92
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
93
         */
94
        public void point(PointEvent event) throws BehaviorException {
95
                Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
96
                //Point imagePoint = new Point((int) event.getPoint().getX(), (int) event.getPoint().getY());
97
                ViewPort v = mapCtrl.getMapContext().getViewPort();
98

    
99
                FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives();
100
                Envelope ext = null;
101

    
102
                try {
103
                        ext = actives[0].getFullEnvelope();
104
                } catch (ReadException e) {
105
                        throw new BehaviorException(e.getMessage());
106
                }
107

    
108
                  if(        ext != null ){
109

    
110
                      double w2 = v.getImageWidth()/2D;
111
                      double h2 = v.getImageHeight()/2D;
112
                      double wcOriginX = pReal.getX();
113
                      double wcOriginY = pReal.getY();
114

    
115
                      Point2D maxRes = ((FLyrWCS)actives[0]).getMaxResolution();
116
                      double wcDstMinX = wcOriginX-w2*maxRes.getX();
117
                      double wcDstMinY = wcOriginY-h2*maxRes.getY();
118
                      double wcDstWidth = w2*maxRes.getX()*2D;
119
                      double wcDstHeight = h2*maxRes.getY()*2D;
120

    
121
                      Envelope rect;
122
                        try {
123
                                rect = geomManager.createEnvelope(
124
                                                wcDstMinX, wcDstMinY, wcDstMinX + wcDstWidth, wcDstMinY - wcDstHeight, SUBTYPES.GEOM2D);
125
                        } catch (CreateEnvelopeException e) {
126
                                throw new BehaviorException(e.getMessage());
127
                        }
128
                         mapCtrl.getMapContext().getViewPort().setEnvelope(rect);
129
                  }
130

    
131
        }
132

    
133
        /*
134
         * (non-Javadoc)
135
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
136
         */
137
        public Cursor getCursor() {
138
                return cur;
139
        }
140

    
141
        /*
142
         * (non-Javadoc)
143
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
144
         */
145
        public boolean cancelDrawing() {
146
                return false;
147
        }
148

    
149
        /*
150
         * (non-Javadoc)
151
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
152
         */
153
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
154
        }
155

    
156
        /*
157
         * (non-Javadoc)
158
         * @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#getImageCursor()
159
         */
160
        public Image getImageCursor() {
161
                return img;
162
        }
163
}