Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / GenericToolBarModule.java @ 22576

History | View | Annotate | Download (8.61 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
package org.gvsig.rastertools;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
23

    
24
import javax.swing.JPanel;
25
import javax.swing.JToolBar;
26

    
27
import org.gvsig.raster.util.RasterToolsUtil;
28
import org.gvsig.raster.util.extensionPoints.ExtensionPoint;
29
import org.gvsig.rastertools.analysisview.ViewRasterAnalysisTocMenuEntry;
30
import org.gvsig.rastertools.clipping.ClippingTocMenuEntry;
31
import org.gvsig.rastertools.colortable.ColorTableTocMenuEntry;
32
import org.gvsig.rastertools.enhanced.EnhancedTocMenuEntry;
33
import org.gvsig.rastertools.filter.FilterTocMenuEntry;
34
import org.gvsig.rastertools.generictoolbar.GenericToolBarMenuItem;
35
import org.gvsig.rastertools.generictoolbar.GenericToolBarPanel;
36
import org.gvsig.rastertools.geolocation.GeoLocationTocMenuEntry;
37
import org.gvsig.rastertools.histogram.HistogramTocMenuEntry;
38
import org.gvsig.rastertools.overviews.OverviewsTocMenuEntry;
39
import org.gvsig.rastertools.properties.RasterPropertiesTocMenuEntry;
40
import org.gvsig.rastertools.reproject.ReprojectTocMenuEntry;
41
import org.gvsig.rastertools.roi.ROIManagerTocMenuEntry;
42
import org.gvsig.rastertools.saveas.SaveAsTocMenuEntry;
43
import org.gvsig.rastertools.saveraster.SaveRasterTocMenuEntry;
44
import org.gvsig.rastertools.selectrasterlayer.SelectLayerTocMenuEntry;
45
import org.gvsig.rastertools.vectorizacion.VectorizationTocMenuEntry;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.plugins.Extension;
49
import com.iver.andami.ui.mdiFrame.MDIFrame;
50
import com.iver.cit.gvsig.fmap.MapContext;
51
import com.iver.cit.gvsig.project.documents.view.IProjectView;
52
import com.iver.cit.gvsig.project.documents.view.gui.View;
53
/**
54
 * Extension para la barra de herramientas generica
55
 * 
56
 * @version 13/02/2008
57
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
58
 */
59
public class GenericToolBarModule extends Extension {
60
        private GenericToolBarPanel toolBar = null;
61
        
62
        /**
63
         * Crea y devuelve la barra de herramientas
64
         * @return
65
         */
66
        private GenericToolBarPanel getGenericToolBarPanel() {
67
                if (toolBar == null) {
68
                        MDIFrame f = (MDIFrame) PluginServices.getMainFrame();
69
                        if (f == null)
70
                                return null;
71
                        for (int i = 0; i < f.getContentPane().getComponentCount(); i++) {
72
                                if (f.getContentPane().getComponent(i) instanceof JPanel) {
73
                                        JPanel panel = (JPanel) f.getContentPane().getComponent(i);
74
                                        for (int j = 0; j < panel.getComponentCount(); j++) {
75
                                                if (panel.getComponent(i) instanceof JToolBar) {
76
                                                        toolBar = new GenericToolBarPanel();
77
                                                        panel.add(toolBar, BorderLayout.PAGE_START);
78
                                                        return toolBar;
79
                                                }
80
                                        }
81
                                }
82
                        }
83
                } else {
84
                        toolBar.setPreferredSize(new Dimension(300, getToolbarHeight()));
85
                }
86
                
87
                return toolBar;
88
        }
89

    
90
        /**
91
         * Obtenemos el alto de cualquier toolbar que este visible en gvSIG y no sea
92
         * nuestro para poder asignarselo al GenericToolBar como PreferredSize. En
93
         * caso de no encontrar ninguno que cumpla las condiciones, se devolver? 24
94
         * @return
95
         */
96
        private int getToolbarHeight() {
97
                if ((PluginServices.getMainFrame() == null) ||
98
                                (PluginServices.getMainFrame().getToolbars() == null) ||
99
                                (PluginServices.getMainFrame().getToolbars().length <= 0))
100
                        return 24;
101
                
102
                for (int i = 0; i < PluginServices.getMainFrame().getToolbars().length; i++) {
103
                        if ((PluginServices.getMainFrame().getToolbars()[i].getHeight() > 16) &&
104
                                        ((Object) PluginServices.getMainFrame().getToolbars()[i] != (Object) toolBar))
105
                                return PluginServices.getMainFrame().getToolbars()[i].getHeight();
106
                }
107
                return 24;
108
        }
109
        
110
        /*
111
         * (non-Javadoc)
112
         * @see com.iver.andami.plugins.IExtension#initialize()
113
         */
114
        public void initialize() {
115
                registerIcons();
116
                
117
                // Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
118
                ExtensionPoint point = ExtensionPoint.getExtensionPoint("GenericToolBarGroup");
119
                point.setDescription("Punto de extension para los grupos de menus del GenericToolBarPanel");
120

    
121
                point.register("RasterLayer", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "capa_raster"), PluginServices.getIconTheme().get("layer-icon")));
122
                point.register("RasterProcess", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "process_raster"), PluginServices.getIconTheme().get("process-icon")));
123
                point.register("GeoRaster", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "transformaciones_geograficas"), PluginServices.getIconTheme().get("transgeo-icon")));
124
                point.register("RasterExport", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "raster_export"), PluginServices.getIconTheme().get("raster-export")));
125
                
126
                point = ExtensionPoint.getExtensionPoint("GenericToolBarMenu");
127
                point.setDescription("Punto de extension para los submenus del GenericToolBarPanel");
128
                point.register("RasterProperties", RasterPropertiesTocMenuEntry.getSingleton());
129
                point.register("SelectLayer", SelectLayerTocMenuEntry.getSingleton());
130
                point.register("HistogramPanel", HistogramTocMenuEntry.getSingleton());
131
                point.register("ViewColorTable", ColorTableTocMenuEntry.getSingleton());
132
                point.register("Overviews", OverviewsTocMenuEntry.getSingleton());
133
                point.register("RoisManager", ROIManagerTocMenuEntry.getSingleton());
134
                point.register("ViewRasterAnalysis", ViewRasterAnalysisTocMenuEntry.getSingleton());
135
                
136
                point.register("SaveAs", SaveAsTocMenuEntry.getSingleton());
137
                point.register("ClippingPanel", ClippingTocMenuEntry.getSingleton());
138
                point.register("SaveRaster", SaveRasterTocMenuEntry.getSingleton());
139
                
140
                point.register("FilterPanel", FilterTocMenuEntry.getSingleton());
141
                point.register("EnhancedPanel", EnhancedTocMenuEntry.getSingleton());
142
                point.register("GeoLocation", GeoLocationTocMenuEntry.getSingleton());
143
                point.register("Vectorization", VectorizationTocMenuEntry.getSingleton());
144
                ReprojectTocMenuEntry menuEntry = ReprojectTocMenuEntry.getSingleton();
145
                point.register(menuEntry.getText(), menuEntry);
146

    
147
                if (getGenericToolBarPanel() != null)
148
                        getGenericToolBarPanel().reloadMenuGroup();
149
        }
150
        
151
        /**
152
         * Registra los iconos a utilizar en la botonera.
153
         */
154
        private void registerIcons() {
155
                PluginServices.getIconTheme().register(
156
                                "layer-icon",
157
                                this.getClass().getClassLoader().getResource("images/rasterlayer.png")
158
                        );
159
                PluginServices.getIconTheme().register(
160
                                "process-icon",
161
                                this.getClass().getClassLoader().getResource("images/icon_process.gif")
162
                        );
163
                PluginServices.getIconTheme().register(
164
                                "transgeo-icon",
165
                                this.getClass().getClassLoader().getResource("images/rastertransgeo.gif")
166
                        );
167
                PluginServices.getIconTheme().registerDefault(
168
                                "raster-export",
169
                                this.getClass().getClassLoader().getResource("images/raster-export.png")
170
                        );
171
        }
172

    
173
        /*
174
         * (non-Javadoc)
175
         * @see com.iver.andami.plugins.IExtension#isEnabled()
176
         */
177
        public boolean isEnabled() {
178
                return false;
179
        }
180

    
181
        /**
182
         * Establece si la barra de herramientas esta visible
183
         * @param enabled
184
         */
185
        private void setToolBarVisible(boolean enabled) {
186
                if (getGenericToolBarPanel() == null)
187
                        return;
188

    
189
                toolBar.setVisible(enabled);
190
        }
191
        
192
        /*
193
         * (non-Javadoc)
194
         * @see com.iver.andami.plugins.IExtension#isVisible()
195
         */
196
        public boolean isVisible() {
197
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
198
                if (f == null) {
199
                        setToolBarVisible(false);
200
                        return false;
201
                }
202

    
203
                if (f instanceof View) {
204
                        View vista = (View) f;
205
                        IProjectView model = vista.getModel();
206
                        MapContext mapa = model.getMapContext();
207
                        if (mapa.getLayers().getLayersCount() > 0) {
208
                                setToolBarVisible(true);
209
                                if (getGenericToolBarPanel() != null) {
210
                                        getGenericToolBarPanel().setLayers(mapa.getLayers());
211
                                }
212
                                return true;
213
                        }
214
                }
215

    
216
                setToolBarVisible(false);
217
                return false;                        
218
        }
219
        
220
        public void execute(String actionCommand) {}
221
}