Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / toc / WCSZoomToPixelTocMenuEntry.java @ 7304

History | View | Annotate | Download (3.77 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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

    
42
package com.iver.cit.gvsig.gui.toc;
43

    
44
import java.awt.event.ActionEvent;
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47

    
48
import javax.swing.JMenuItem;
49

    
50
import com.iver.andami.PluginServices;
51
import com.iver.cit.gvsig.fmap.ViewPort;
52
import com.iver.cit.gvsig.fmap.layers.FLayer;
53
import com.iver.cit.gvsig.fmap.layers.FLyrWCS;
54
import com.iver.cit.gvsig.project.documents.view.toc.TocMenuEntry;
55
import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu;
56

    
57
/** 
58
 * This class implements the TOC meny entry to do a zoom to pixel.
59
 * Zooming to a pixel causes to change the view's zoom to fit in the coverage's native
60
 * resolution.
61
 * 
62
 * Entrada de men? para la activaci?n de la funcionalidad de zoom a un
63
 * pixel.
64
 * @author Jaume - jaume.dominguez@iver.es
65
 */
66
public class WCSZoomToPixelTocMenuEntry extends TocMenuEntry {
67
        public static final int ZOOM_TO_VIEW_CENTER = 0x2;
68
        private JMenuItem properties;
69
        FLayer lyr = null;
70
        public int zoomType = ZOOM_TO_VIEW_CENTER;
71
        
72
        public void initialize(FPopupMenu m) {
73
                super.initialize(m);
74
                
75
                if (isTocItemBranch()) {
76
                        lyr = getNodeLayer();
77
                    // Opciones para capas raster
78
                    if ((lyr instanceof FLyrWCS)) {
79
                            properties = new JMenuItem(PluginServices.getText(this, "Zoom_pixel"));
80
                            getMenu().add( properties );
81
                            properties.setFont(FPopupMenu.theFont);
82
                            getMenu().setEnabled(true);
83
                            // LWS getMenu().addSeparator();
84
                            properties.addActionListener(this);
85
                     }
86
                }
87
        }
88
        /**
89
         * Calculates the zoom that fits the coverage native resolution.
90
         * 
91
         * TODO fix the little loss of accuracy caused by a floating point issue
92
         */
93
        public void actionPerformed(ActionEvent e) {
94
                //System.out.println("Zoom a un pixel");
95
                
96
            ViewPort v = getMapContext().getViewPort();
97
            
98
            double w2 = v.getImageWidth()/2D;
99
            double h2 = v.getImageHeight()/2D;
100
            double wcOriginCenterX = v.getExtent().getMinX()+((v.getExtent().getMaxX()-v.getExtent().getMinX())/2D);
101
            double wcOriginCenterY = v.getExtent().getMinY()+((v.getExtent().getMaxY()-v.getExtent().getMinY())/2D);
102

    
103
            Point2D maxRes = ((FLyrWCS) lyr).getMaxResolution();
104
            //double wcDstMinX = wcOriginCenterX-w2*maxRes;
105
            double wcDstMinX = wcOriginCenterX-w2*maxRes.getX();
106
            //double wcDstMinY = wcOriginCenterY+h2*maxRes;
107
            double wcDstMinY = wcOriginCenterY+h2*maxRes.getY();
108
            //double wcDstWidth = w2*maxRes*2D;
109
            double wcDstWidth = w2*maxRes.getX()*2D;
110
               //double wcDstHeight = h2*maxRes*2D;
111
            double wcDstHeight = h2*maxRes.getY()*2D;
112
            
113
            getMapContext().getViewPort().setExtent(
114
                            new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight));
115

    
116
        }
117
}
118