Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / rasterresolution / ZoomPixelCursorTocMenuEntry.java @ 12425

History | View | Annotate | Download (4.47 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.rastertools.rasterresolution;
20

    
21
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
22

    
23
import com.iver.andami.PluginServices;
24
import com.iver.cit.gvsig.ProjectExtension;
25
import com.iver.cit.gvsig.fmap.MapControl;
26
import com.iver.cit.gvsig.fmap.layers.FLayer;
27
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
28
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
29
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
30
import com.iver.cit.gvsig.project.Project;
31
import com.iver.cit.gvsig.project.documents.view.gui.View;
32
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
33
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
34
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
35

    
36
/**
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 *
39
 * Entrada de men? para la activaci?n de la funcionalidad de zoom a un
40
 * pixel centrado en el cursor.
41
 */
42
public class ZoomPixelCursorTocMenuEntry extends AbstractTocContextMenuAction {
43
        public static final int ZOOM_TO_IMAGE_CENTER = 0x1;
44
        public static final int ZOOM_TO_VIEW_CENTER = 0x2;
45
        FLayer lyr = null;
46
        public int zoomType = ZOOM_TO_VIEW_CENTER;
47

    
48
        /*
49
         *  (non-Javadoc)
50
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroup()
51
         */
52
        public String getGroup() {
53
                return "group2"; //FIXME
54
        }
55

    
56
        /*
57
         *  (non-Javadoc)
58
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroupOrder()
59
         */
60
        public int getGroupOrder() {
61
                return 20;
62
        }
63

    
64
        /*
65
         *  (non-Javadoc)
66
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getOrder()
67
         */
68
        public int getOrder() {
69
                return 2;
70
        }
71

    
72
        /*
73
         *  (non-Javadoc)
74
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
75
         */
76
        public String getText() {
77
                return PluginServices.getText(this, "Zoom_pixel");
78
        }
79

    
80
        /*
81
         *  (non-Javadoc)
82
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
83
         */
84
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
85
                return true;
86
        }
87

    
88
        /*
89
         *  (non-Javadoc)
90
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
91
         */
92
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
93
                if (isTocItemBranch(item)) {
94
                        return getNodeLayer(item) instanceof FLyrRasterSE;
95
                }
96
                return false;
97

    
98
        }
99

    
100
        /**
101
         * M?todo que se ejecuta cuando se pulsa la entrada en el men? contextual del TOC 
102
         * correspondiente a "Zoom a la resoluci?n del raster". Aqu? se crear? el mapTool si 
103
         * no se ha hecho antes y se cargar?.
104
         */
105
        public void execute(ITocItem item, FLayer[] selectedItems) {
106
                if(selectedItems.length == 1) {
107
                lyr = getNodeLayer(item);
108
                    View vista = (View) PluginServices.getMDIManager().getActiveWindow();
109
                    MapControl mapCtrl = vista.getMapControl();
110
                    //Si no se ha cargado el listener a?n lo cargamos.
111
                if(mapCtrl.getNamesMapTools().get("zoom_pixel_cursor_SE") == null) {
112
                        //Crea el listener del zoom a la resoluci?n del raster
113
                        StatusBarListener sbl = new StatusBarListener(mapCtrl);
114
                        ZoomPixelCursorListener zp = new ZoomPixelCursorListener(mapCtrl);
115
                        mapCtrl.addMapTool("zoom_pixel_cursor_SE", new Behavior[]{
116
                                                                new PointBehavior(zp), new MouseMovementBehavior(sbl)});
117
                }
118
                    mapCtrl.setTool("zoom_pixel_cursor_SE");
119
                    Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
120
                        project.setModified(true);
121

    
122
                }
123
        }
124
}