Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / saveviewtoraster / SaveViewToRasterTocMenuEntry.java @ 2125

History | View | Annotate | Download (4.55 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.tools.app.basic.tool.saveviewtoraster;
23

    
24
import javax.swing.Icon;
25

    
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.app.project.documents.view.ViewDocument;
29
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
30
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
31
import org.gvsig.app.project.documents.view.toc.ITocItem;
32
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
33
import org.gvsig.fmap.mapcontext.MapContext;
34
import org.gvsig.fmap.mapcontext.layers.FLayer;
35
import org.gvsig.fmap.mapcontrol.MapControl;
36
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
37
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
38
import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior;
39
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
40
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
41
import org.gvsig.raster.tools.app.basic.tool.saveviewtoraster.tool.SaveRasterRectangleTool;
42

    
43

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

    
53
        /**
54
         * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
55
         * getSingleton()
56
         */
57
        private SaveViewToRasterTocMenuEntry() {}
58

    
59
        /**
60
         * Devuelve un objeto unico a dicha clase
61
         * @return
62
         */
63
        static public SaveViewToRasterTocMenuEntry getSingleton() {
64
                if (singleton == null)
65
                        singleton = new SaveViewToRasterTocMenuEntry();
66
                return singleton;
67
        }
68

    
69
        public String getGroup() {
70
                return "RasterExport";
71
        }
72

    
73
        public int getGroupOrder() {
74
                return 50;
75
        }
76

    
77
        public int getOrder() {
78
                return 0;
79
        }
80

    
81
        public String getText() {
82
                return RasterToolsUtil.getText(this, "salvar_raster_geo");
83
        }
84

    
85
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
86
                return true;
87
        }
88

    
89
        @SuppressWarnings("deprecation")
90
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
91
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
92
                if (f == null)
93
                        return false;
94

    
95
                if (f instanceof AbstractViewPanel) {
96
                        AbstractViewPanel vista = (AbstractViewPanel) f;
97
                        ViewDocument model = vista.getModel();
98
                        MapContext mapa = model.getMapContext();
99
                        if (mapa.getLayers().getLayersCount() > 0) 
100
                                return true;
101
                }
102

    
103
                return false;
104
        }
105

    
106
        public void execute(ITocItem item, FLayer[] selectedItems) {
107
                AbstractViewPanel theView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
108
                MapControl mapCtrl = theView.getMapControl();
109

    
110
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
111
                // la barra de estado
112
                StatusBarListener sbl = new StatusBarListener(mapCtrl);
113

    
114
                RasterToolsUtil.messageBoxInfo("start_save", theView);
115
                loadSaveRasterListener(mapCtrl, sbl, theView.getViewDocument().getName());
116
                mapCtrl.setTool("SaveRasterRectangleTool");
117
        }
118
        
119
        /**
120
         * Carga el listener de salvar a raster en el MapControl.
121
         */
122
        private void loadSaveRasterListener(MapControl m_MapControl, StatusBarListener sbl, String viewName) {
123
                // Si no se ha cargado el listener a?n lo cargamos.
124
                if (m_MapControl.getNamesMapTools().get("SaveRasterRectangleTool") == null) {
125
                        SaveRasterRectangleTool srl = new SaveRasterRectangleTool(m_MapControl, viewName);
126
                        m_MapControl.addBehavior("SaveRasterRectangleTool", new Behavior[] { new RectangleBehavior(srl), new MouseMovementBehavior(sbl) });
127
                }
128
        }
129
        
130
        public Icon getIcon() {
131
                return IconThemeHelper.getImageIcon("view-export-georeferenced-raster");
132
        }
133
        
134
}