Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / saveraster / SaveRasterTocMenuEntry.java @ 31496

History | View | Annotate | Download (5.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.saveraster;
20

    
21
import javax.swing.Icon;
22

    
23
import org.gvsig.andami.PluginServices;
24
import org.gvsig.app.project.documents.view.ViewDocument;
25
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
26
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
27
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
28
import org.gvsig.app.project.documents.view.toc.ITocItem;
29
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
30
import org.gvsig.fmap.mapcontext.MapContext;
31
import org.gvsig.fmap.mapcontext.layers.FLayer;
32
import org.gvsig.fmap.mapcontrol.MapControl;
33
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
34
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
35
import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior;
36
import org.gvsig.raster.gui.IGenericToolBarMenuItem;
37
import org.gvsig.raster.util.RasterToolsUtil;
38
import org.gvsig.rastertools.saveraster.map.SaveRasterListener;
39

    
40

    
41
/**
42
 * Punto de entrada para la funcionalidad de salvar a raster
43
 * 
44
 * 22/07/2008
45
 * @author Nacho Brodin nachobrodin@gmail.com
46
 */
47
public class SaveRasterTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem {
48
        static private SaveRasterTocMenuEntry singleton  = null;
49

    
50
        /**
51
         * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
52
         * getSingleton()
53
         */
54
        private SaveRasterTocMenuEntry() {}
55

    
56
        /**
57
         * Devuelve un objeto unico a dicha clase
58
         * @return
59
         */
60
        static public SaveRasterTocMenuEntry getSingleton() {
61
                if (singleton == null)
62
                        singleton = new SaveRasterTocMenuEntry();
63
                return singleton;
64
        }
65
        /*
66
         * (non-Javadoc)
67
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
68
         */
69
        public String getGroup() {
70
                return "RasterExport";
71
        }
72

    
73
        /*
74
         * (non-Javadoc)
75
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
76
         */
77
        public int getGroupOrder() {
78
                return 50;
79
        }
80

    
81
        /*
82
         * (non-Javadoc)
83
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
84
         */
85
        public int getOrder() {
86
                return 0;
87
        }
88

    
89
        /*
90
         * (non-Javadoc)
91
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
92
         */
93
        public String getText() {
94
                return RasterToolsUtil.getText(this, "salvar_raster_geo");
95
        }
96

    
97
        /*
98
         * (non-Javadoc)
99
         * @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[])
100
         */
101
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
102
                return true;
103
        }
104

    
105
        /*
106
         * (non-Javadoc)
107
         * @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[])
108
         */
109
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
110
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
111
                if (f == null)
112
                        return false;
113

    
114
                if (f instanceof AbstractViewPanel) {
115
                        AbstractViewPanel vista = (AbstractViewPanel) f;
116
                        ViewDocument model = vista.getModel();
117
                        MapContext mapa = model.getMapContext();
118
                        if (mapa.getLayers().getLayersCount() > 0) 
119
                                return true;
120
                }
121

    
122
                return false;
123
        }
124

    
125
        /*
126
         * (non-Javadoc)
127
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
128
         */
129
        public void execute(ITocItem item, FLayer[] selectedItems) {
130
                DefaultViewPanel theView = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
131
                MapControl mapCtrl = theView.getMapControl();
132

    
133
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
134
                // la barra de estado
135
                StatusBarListener sbl = new StatusBarListener(mapCtrl);
136

    
137
                RasterToolsUtil.messageBoxInfo("start_save", null);
138
                loadSaveRasterListener(mapCtrl, sbl);
139
                mapCtrl.setTool("saveRaster");
140
        }
141
        
142
        /**
143
         * Carga el listener de salvar a raster en el MapControl.
144
         */
145
        private void loadSaveRasterListener(MapControl m_MapControl, StatusBarListener sbl) {
146
                // Si no se ha cargado el listener a?n lo cargamos.
147
                if (m_MapControl.getNamesMapTools().get("saveRaster") == null) {
148
                        SaveRasterListener srl = new SaveRasterListener(m_MapControl);
149
                        m_MapControl.addBehavior("saveRaster", new Behavior[] { new RectangleBehavior(srl), new MouseMovementBehavior(sbl) });
150
                }
151
        }
152
        
153
        /*
154
         * (non-Javadoc)
155
         * @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
156
         */
157
        public Icon getIcon() {
158
                return PluginServices.getIconTheme().get("save-raster");
159
        }
160
}