Statistics
| Revision:

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

History | View | Annotate | Download (4.92 KB)

1 11662 nacho
/* 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 12425 nacho
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
22 13703 nacho
import org.gvsig.fmap.raster.layers.ILayerState;
23 13300 nacho
import org.gvsig.fmap.raster.layers.IRasterLayerActions;
24 11662 nacho
25
import com.iver.andami.PluginServices;
26
import com.iver.cit.gvsig.ProjectExtension;
27
import com.iver.cit.gvsig.fmap.MapControl;
28
import com.iver.cit.gvsig.fmap.layers.FLayer;
29
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
30
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
31
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
32
import com.iver.cit.gvsig.project.Project;
33
import com.iver.cit.gvsig.project.documents.view.gui.View;
34
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
35
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
36
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
37
38
/**
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 *
41
 * Entrada de men? para la activaci?n de la funcionalidad de zoom a un
42
 * pixel centrado en el cursor.
43
 */
44
public class ZoomPixelCursorTocMenuEntry extends AbstractTocContextMenuAction {
45
        public static final int ZOOM_TO_IMAGE_CENTER = 0x1;
46
        public static final int ZOOM_TO_VIEW_CENTER = 0x2;
47
        FLayer lyr = null;
48
        public int zoomType = ZOOM_TO_VIEW_CENTER;
49
50
        /*
51
         *  (non-Javadoc)
52
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroup()
53
         */
54
        public String getGroup() {
55
                return "group2"; //FIXME
56
        }
57
58
        /*
59
         *  (non-Javadoc)
60
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getGroupOrder()
61
         */
62
        public int getGroupOrder() {
63
                return 20;
64
        }
65
66
        /*
67
         *  (non-Javadoc)
68
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getOrder()
69
         */
70
        public int getOrder() {
71
                return 2;
72
        }
73
74
        /*
75
         *  (non-Javadoc)
76
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
77
         */
78
        public String getText() {
79
                return PluginServices.getText(this, "Zoom_pixel");
80
        }
81
82
        /*
83
         *  (non-Javadoc)
84
         * @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[])
85
         */
86
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
87 13703 nacho
                if(getNodeLayer(item) instanceof ILayerState)
88
                        if(!((ILayerState)getNodeLayer(item)).isOpen())
89
                                return false;
90 11662 nacho
                return true;
91
        }
92
93
        /*
94
         *  (non-Javadoc)
95
         * @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[])
96
         */
97
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
98
                if (isTocItemBranch(item)) {
99 14135 nbrodin
                        if(selectedItems == null || selectedItems.length != 1)
100
                                return false;
101 13300 nacho
                        if((getNodeLayer(item) instanceof FLyrRasterSE) &&
102
                           ((FLyrRasterSE)getNodeLayer(item)).isActionEnabled(IRasterLayerActions.ZOOM_PIXEL_RESOLUTION))
103
                                return getNodeLayer(item) instanceof FLyrRasterSE;
104 11662 nacho
                }
105
                return false;
106
107
        }
108
109
        /**
110
         * M?todo que se ejecuta cuando se pulsa la entrada en el men? contextual del TOC
111
         * correspondiente a "Zoom a la resoluci?n del raster". Aqu? se crear? el mapTool si
112
         * no se ha hecho antes y se cargar?.
113
         */
114
        public void execute(ITocItem item, FLayer[] selectedItems) {
115
                if(selectedItems.length == 1) {
116
                lyr = getNodeLayer(item);
117
                    View vista = (View) PluginServices.getMDIManager().getActiveWindow();
118
                    MapControl mapCtrl = vista.getMapControl();
119
                    //Si no se ha cargado el listener a?n lo cargamos.
120
                if(mapCtrl.getNamesMapTools().get("zoom_pixel_cursor_SE") == null) {
121
                        //Crea el listener del zoom a la resoluci?n del raster
122
                        StatusBarListener sbl = new StatusBarListener(mapCtrl);
123
                        ZoomPixelCursorListener zp = new ZoomPixelCursorListener(mapCtrl);
124
                        mapCtrl.addMapTool("zoom_pixel_cursor_SE", new Behavior[]{
125
                                                                new PointBehavior(zp), new MouseMovementBehavior(sbl)});
126
                }
127
                    mapCtrl.setTool("zoom_pixel_cursor_SE");
128
                    Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
129
                        project.setModified(true);
130
131
                }
132
        }
133
}