Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / RasterModule.java @ 15774

History | View | Annotate | Download (12 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;
20

    
21
import java.util.prefs.Preferences;
22

    
23
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
24
import org.gvsig.fmap.raster.layers.StatusLayerRaster;
25
import org.gvsig.raster.gui.properties.dialog.RasterPropertiesTocMenuEntry;
26
import org.gvsig.raster.gui.wizards.FileOpenRaster;
27
import org.gvsig.rastertools.analysisview.ViewRasterAnalysisTocMenuEntry;
28
import org.gvsig.rastertools.clipping.ClippingTocMenuEntry;
29
import org.gvsig.rastertools.colortable.ColorTableTocMenuEntry;
30
import org.gvsig.rastertools.filter.FilterTocMenuEntry;
31
import org.gvsig.rastertools.geolocation.GeoLocationTocMenuEntry;
32
import org.gvsig.rastertools.histogram.HistogramTocMenuEntry;
33
import org.gvsig.rastertools.properties.panels.BandSetupPanel;
34
import org.gvsig.rastertools.properties.panels.EnhancedPanel;
35
import org.gvsig.rastertools.properties.panels.InfoPanel;
36
import org.gvsig.rastertools.properties.panels.PanSharpeningPanel;
37
import org.gvsig.rastertools.properties.panels.ScalePanel;
38
import org.gvsig.rastertools.properties.panels.TransparencyPanel;
39
import org.gvsig.rastertools.rasterresolution.ZoomPixelCursorTocMenuEntry;
40
import org.gvsig.rastertools.roi.ui.ROIManagerTocMenuEntry;
41
import org.gvsig.rastertools.saveas.SaveAsTocMenuEntry;
42
import org.gvsig.rastertools.selectrasterlayer.SelectImageListener;
43

    
44
import com.iver.andami.PluginServices;
45
import com.iver.andami.plugins.Extension;
46
import com.iver.cit.gvsig.fmap.MapContext;
47
import com.iver.cit.gvsig.fmap.MapControl;
48
import com.iver.cit.gvsig.fmap.layers.FLayers;
49
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
50
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
51
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
52
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
53
import com.iver.cit.gvsig.project.documents.view.IProjectView;
54
import com.iver.cit.gvsig.project.documents.view.gui.View;
55
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
56
import com.iver.utiles.extensionPoints.ExtensionPoint;
57
import com.iver.utiles.extensionPoints.ExtensionPoints;
58
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
59
/**
60
 * Extensi?n que adapta a FMap y gvSIG la nueva implementaci?n de raster. Para
61
 * el cuadro de Propiedades de visualizaci?n de raster contiene el contenedor
62
 * base se registran la entrada del men? del TOC y los paneles en el cuadro.
63
 * Para la parte de FMap contiene una nueva capa raster y los drivers
64
 * necesarios.
65
 *
66
 * @author Nacho Brodin (nachobrodin@gmail.com)
67
 */
68
public class RasterModule extends Extension{
69
        /**
70
         * Contador global de las capas generadas para raster
71
         */
72
        public static int           layerCount = 1;
73

    
74
        /*
75
         * (non-Javadoc)
76
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
77
         */
78
        public void execute(String actionCommand) {
79
                View theView = (View) PluginServices.getMDIManager().getActiveWindow();
80
                MapControl mapCtrl = theView.getMapControl();
81

    
82
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
83
                // la barra de estado
84
                StatusBarListener sbl = new StatusBarListener(mapCtrl);
85

    
86
                if (actionCommand.equals("SELECTIMAGE")) {
87
                        loadSelectRasterListener(mapCtrl, sbl);
88
                        mapCtrl.setTool("selectRasterLayer");
89
                }                
90
        }
91

    
92
        /**
93
         * Carga el listener de selecci?n de raster en el MapControl.
94
         */
95
        private void loadSelectRasterListener(MapControl mapCtrl, StatusBarListener sbl) {
96
                if (mapCtrl.getNamesMapTools().get("selectRasterLayer") == null) {
97
                        SelectImageListener sil = new SelectImageListener(mapCtrl);
98
                        mapCtrl.addMapTool("selectRasterLayer", new Behavior[] { new PointBehavior(sil), new MouseMovementBehavior(sbl) });
99
                        mapCtrl.setTool("selectRasterLayer");
100
                }
101
        }
102
        
103
        /*
104
         * (non-Javadoc)
105
         * @see com.iver.andami.plugins.IExtension#initialize()
106
         */
107
        public void initialize() {
108
                // DiagSignalHandler.install("ALRM");
109

    
110
                Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
111
                prefs.put("DataFolder", System.getProperty("user.home"));
112

    
113
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
114

    
115
                // Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
116
                if (!extensionPoints.containsKey("RasterSEPropertiesDialog")) {
117
                        extensionPoints.put(new ExtensionPoint("RasterSEPropertiesDialog", "Raster Properties registrable panels (register instances of javax.swing.JPanel)"));
118
                }
119

    
120
                // A?adimos paneles al cuadro de propiedades.
121
                extensionPoints.add("RasterSEPropertiesDialog", "info", InfoPanel.class);
122
                extensionPoints.add("RasterSEPropertiesDialog", "bands_panel", BandSetupPanel.class);
123
                extensionPoints.add("RasterSEPropertiesDialog", "transparencia", TransparencyPanel.class);
124
                extensionPoints.add("RasterSEPropertiesDialog", "realce", EnhancedPanel.class);
125
                extensionPoints.add("RasterSEPropertiesDialog", "pansharp", PanSharpeningPanel.class);
126
                extensionPoints.add("RasterSEPropertiesDialog", "scale_panel", ScalePanel.class);
127

    
128
                // A?adimos la entrada del toc de la ventana de Histograma.
129
                extensionPoints.add("View_TocActions", "HistogramPanel", new HistogramTocMenuEntry());
130

    
131
                // A?adimos la entrada del toc de la ventana de Recorte.
132
                extensionPoints.add("View_TocActions", "ClippingPanel", new ClippingTocMenuEntry());
133

    
134
                // A?adimos la entrada del toc de la ventana de Filtros.
135
                extensionPoints.add("View_TocActions", "FilterPanel", new FilterTocMenuEntry());
136

    
137
                // A?adimos la entrada del toc del cuadro de Propiedades. Como se llama igual sustituye a la vieja.
138
                extensionPoints.add("View_TocActions", "RasterSEProperties", new RasterPropertiesTocMenuEntry());
139

    
140
                // A?adimos la entrada del toc de zoom a la resoluci?n del raster.
141
                extensionPoints.add("View_TocActions", "ZoomPixelCursor", new ZoomPixelCursorTocMenuEntry());
142

    
143
                // A?adimos la entrada del toc de zoom Salvar Como.
144
                extensionPoints.add("View_TocActions", "SaveAs", new SaveAsTocMenuEntry());
145

    
146
                // A?adimos la entrada del toc de la vista de analisis.
147
                extensionPoints.add("View_TocActions", "ViewRasterAnalysis", new ViewRasterAnalysisTocMenuEntry());
148

    
149
                // A?adimos la entrada del toc de la vista de analisis.
150
                extensionPoints.add("View_TocActions", "ViewColorTable", new ColorTableTocMenuEntry());
151
                
152
                // A?adimos la entrada del toc de la vista de analisis.
153
                extensionPoints.add("View_TocActions", "GeoLocation", new GeoLocationTocMenuEntry());
154

    
155
            // A?adimos la entrada del toc de la vista de analisis.
156
                extensionPoints.add("View_TocActions", "RoisManager", new ROIManagerTocMenuEntry());
157
                
158
                // A?adimos nuestra extension para el tratamiento de la apertura de ficheros
159
                // dentro de gvSIG
160
                extensionPoints.add("FileExtendingOpenDialog", "FileOpenRaster", FileOpenRaster.class);
161
                
162
                //Alias
163
                LayerFactory.registerLayerClassForName("com.iver.cit.gvsig.fmap.layers.FLyrRaster", FLyrRasterSE.class);
164
                LayerFactory.registerLayerClassForName("com.iver.cit.gvsig.fmap.layers.StatusLayerRaster", StatusLayerRaster.class);
165
                registerIcons();
166
        }
167

    
168
        /**
169
         * Registra los iconos a utilizar en andami.
170
         */
171
        private void registerIcons(){
172
                PluginServices.getIconTheme().registerDefault(
173
                                "map-ok-ico",
174
                                MapControl.class.getResource("images/map_ico_ok.gif")
175
                        );
176
                PluginServices.getIconTheme().registerDefault(
177
                                "crux-cursor",
178
                                MapControl.class.getResource("images/CruxCursor.png")
179
                        );
180
                PluginServices.getIconTheme().registerDefault(
181
                                "addlayer-icon",
182
                                this.getClass().getClassLoader().getResource("images/addlayer.png")
183
                        );
184
                PluginServices.getIconTheme().registerDefault(
185
                                "delall-icon",
186
                                this.getClass().getClassLoader().getResource("images/delall.png")
187
                        );
188
                PluginServices.getIconTheme().registerDefault(
189
                                "rotar-icon",
190
                                this.getClass().getClassLoader().getResource("images/Rotar.gif")
191
                        );
192
                PluginServices.getIconTheme().registerDefault(
193
                                "hor-arrow-icon",
194
                                this.getClass().getClassLoader().getResource("images/FlechaHorizCursor.gif")
195
                        );
196
                PluginServices.getIconTheme().registerDefault(
197
                                "ver-arrow-icon",
198
                                this.getClass().getClassLoader().getResource("images/FlechaVertCursor.gif")
199
                        );
200
                PluginServices.getIconTheme().registerDefault(
201
                                "inclder-arrow-icon",
202
                                this.getClass().getClassLoader().getResource("images/FlechaInclDerCursor.gif")
203
                        );
204
                PluginServices.getIconTheme().registerDefault(
205
                                "inclizq-arrow-icon",
206
                                this.getClass().getClassLoader().getResource("images/FlechaInclIzqCursor.gif")
207
                        );
208
                PluginServices.getIconTheme().registerDefault(
209
                                "shear-y-icon",
210
                                this.getClass().getClassLoader().getResource("images/y.gif")
211
                        );
212
                PluginServices.getIconTheme().registerDefault(
213
                                "shear-x-icon",
214
                                this.getClass().getClassLoader().getResource("images/x.gif")
215
                        );
216
                PluginServices.getIconTheme().registerDefault(
217
                                "hand-icon",
218
                                this.getClass().getClassLoader().getResource("images/Hand.gif")
219
                        );
220
                
221
                PluginServices.getIconTheme().registerDefault(
222
                                "back-icon",
223
                                this.getClass().getClassLoader().getResource("images/back.png")
224
                        );
225
                PluginServices.getIconTheme().registerDefault(
226
                                "next-icon",
227
                                this.getClass().getClassLoader().getResource("images/next.png")
228
                        );
229
                PluginServices.getIconTheme().registerDefault(
230
                                "undo-icon",
231
                                this.getClass().getClassLoader().getResource("images/undo.png")
232
                        );
233
                PluginServices.getIconTheme().registerDefault(
234
                                "zoom-pixel-cursor",
235
                                this.getClass().getClassLoader().getResource("images/ZoomPixelCursor.gif")
236
                        );
237
                
238
                PluginServices.getIconTheme().registerDefault(
239
                                "save-raster",
240
                                this.getClass().getClassLoader().getResource("images/Rectangle.png")
241
                        );
242
                
243
                PluginServices.getIconTheme().registerDefault(
244
                                "pixel-increase",
245
                                this.getClass().getClassLoader().getResource("images/increase.png")
246
                        );
247
                
248
                PluginServices.getIconTheme().registerDefault(
249
                                "select-raster",
250
                                this.getClass().getClassLoader().getResource("images/stock_toggle-info.png")
251
                        );
252
                PluginServices.getIconTheme().registerDefault(
253
                                "select-raster",
254
                                this.getClass().getClassLoader().getResource("images/stock_toggle-info.png")
255
                        );
256
                PluginServices.getIconTheme().registerDefault(
257
                                "duplicate-icon",
258
                                this.getClass().getClassLoader().getResource("images/duplicate_icon.png")
259
                        );
260
                PluginServices.getIconTheme().registerDefault(
261
                                "save-icon",
262
                                this.getClass().getClassLoader().getResource("images/save.png")
263
                        );
264
                PluginServices.getIconTheme().registerDefault(
265
                                "reset-icon",
266
                                this.getClass().getClassLoader().getResource("images/reset.png")
267
                        );
268
        }
269
        /*
270
         * (non-Javadoc)
271
         * @see com.iver.andami.plugins.IExtension#isEnabled()
272
         */
273
        public boolean isEnabled() {
274
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
275
                if (f == null) {
276
                        return false;
277
                }
278
                if (f.getClass() == View.class) {
279
                        View vista = (View) f;
280
                        IProjectView model = vista.getModel();
281
                        MapContext mapa = model.getMapContext();
282
                        FLayers layers = mapa.getLayers();
283
                        for (int i = 0; i < layers.getLayersCount(); i++) 
284
                                if (layers.getLayer(i) instanceof FLyrRasterSE) 
285
                                        return true;
286
                }
287
                return false;
288
        }
289

    
290
        /**
291
         * Mostramos el control si hay alguna capa cargada.
292
         */
293
        public boolean isVisible() {
294
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
295
                if (f == null)
296
                        return false;
297

    
298
                if (f instanceof View) {
299
                        View vista = (View) f;
300
                        IProjectView model = vista.getModel();
301
                        MapContext mapa = model.getMapContext();
302
                        if (mapa.getLayers().getLayersCount() > 0) 
303
                                return true;
304
                }
305

    
306
                return false;
307
        }
308
}