root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / RasterModule.java @ 17491
History | View | Annotate | Download (15.9 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.fmap.raster.util.Configuration; |
26 |
import org.gvsig.fmap.raster.util.ConfigurationEvent; |
27 |
import org.gvsig.fmap.raster.util.ConfigurationListener; |
28 |
import org.gvsig.raster.RasterLibrary; |
29 |
import org.gvsig.raster.RasterLibrary; |
30 |
import org.gvsig.raster.gui.preferences.RasterPreferences; |
31 |
import org.gvsig.raster.gui.properties.dialog.RasterPropertiesTocMenuEntry; |
32 |
import org.gvsig.raster.gui.wizards.FileOpenRaster; |
33 |
import org.gvsig.rastertools.analysisview.ViewRasterAnalysisTocMenuEntry; |
34 |
import org.gvsig.rastertools.clipping.ClippingTocMenuEntry; |
35 |
import org.gvsig.rastertools.colortable.ColorTableTocMenuEntry; |
36 |
import org.gvsig.rastertools.filter.FilterTocMenuEntry; |
37 |
import org.gvsig.rastertools.geolocation.GeoLocationTocMenuEntry; |
38 |
import org.gvsig.rastertools.histogram.HistogramTocMenuEntry; |
39 |
import org.gvsig.rastertools.overviews.OverviewsTocMenuEntry; |
40 |
import org.gvsig.rastertools.properties.panels.BandSetupPanel; |
41 |
import org.gvsig.rastertools.properties.panels.EnhancedPanel; |
42 |
import org.gvsig.rastertools.properties.panels.InfoPanel; |
43 |
import org.gvsig.rastertools.properties.panels.PanSharpeningPanel; |
44 |
import org.gvsig.rastertools.properties.panels.ScalePanel; |
45 |
import org.gvsig.rastertools.properties.panels.TransparencyPanel; |
46 |
import org.gvsig.rastertools.rasterresolution.ZoomPixelCursorTocMenuEntry; |
47 |
import org.gvsig.rastertools.roi.ui.ROIManagerTocMenuEntry; |
48 |
import org.gvsig.rastertools.saveas.SaveAsTocMenuEntry; |
49 |
import org.gvsig.rastertools.selectrasterlayer.SelectImageListener; |
50 |
|
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.andami.plugins.Extension; |
53 |
import com.iver.cit.gvsig.fmap.MapContext; |
54 |
import com.iver.cit.gvsig.fmap.MapControl; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
56 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
57 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
58 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
59 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
60 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
61 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
62 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
63 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
64 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
65 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
66 |
/**
|
67 |
* Extensi?n que adapta a FMap y gvSIG la nueva implementaci?n de raster. Para
|
68 |
* el cuadro de Propiedades de visualizaci?n de raster contiene el contenedor
|
69 |
* base se registran la entrada del men? del TOC y los paneles en el cuadro.
|
70 |
* Para la parte de FMap contiene una nueva capa raster y los drivers
|
71 |
* necesarios.
|
72 |
*
|
73 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
74 |
*/
|
75 |
public class RasterModule extends Extension implements ConfigurationListener { |
76 |
/**
|
77 |
* Contador global de las capas generadas para raster
|
78 |
*/
|
79 |
public static int layerCount = 1; |
80 |
|
81 |
/**
|
82 |
* Indica si en el panel de preferencias se refresca automaticamente la vista
|
83 |
* para mostrar los cambios
|
84 |
*/
|
85 |
public static boolean autoRefreshView = true; |
86 |
|
87 |
/**
|
88 |
* Indica si se debe preguntar las coordenadas al cargar una capa que no las
|
89 |
* tenga
|
90 |
*/
|
91 |
public static boolean askCoordinates = false; |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
96 |
*/
|
97 |
public void execute(String actionCommand) { |
98 |
View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
99 |
MapControl mapCtrl = theView.getMapControl(); |
100 |
|
101 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
102 |
// la barra de estado
|
103 |
StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
104 |
|
105 |
if (actionCommand.equals("SELECTIMAGE")) { |
106 |
loadSelectRasterListener(mapCtrl, sbl); |
107 |
mapCtrl.setTool("selectRasterLayer");
|
108 |
} |
109 |
} |
110 |
|
111 |
/**
|
112 |
* Carga el listener de selecci?n de raster en el MapControl.
|
113 |
*/
|
114 |
private void loadSelectRasterListener(MapControl mapCtrl, StatusBarListener sbl) { |
115 |
if (mapCtrl.getNamesMapTools().get("selectRasterLayer") == null) { |
116 |
SelectImageListener sil = new SelectImageListener(mapCtrl);
|
117 |
mapCtrl.addMapTool("selectRasterLayer", new Behavior[] { new PointBehavior(sil), new MouseMovementBehavior(sbl) }); |
118 |
mapCtrl.setTool("selectRasterLayer");
|
119 |
} |
120 |
} |
121 |
|
122 |
/*
|
123 |
* (non-Javadoc)
|
124 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
125 |
*/
|
126 |
public void initialize() { |
127 |
Configuration.addValueChangedListener(this); |
128 |
loadConfigurationValues(); |
129 |
|
130 |
registerIcons(); |
131 |
RasterLibrary.wakeUp(); |
132 |
|
133 |
// DiagSignalHandler.install("ALRM");
|
134 |
|
135 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
136 |
prefs.put("DataFolder", System.getProperty("user.home")); |
137 |
|
138 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
139 |
|
140 |
// Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
|
141 |
if (!extensionPoints.containsKey("RasterSEPropertiesDialog")) { |
142 |
extensionPoints.put(new ExtensionPoint("RasterSEPropertiesDialog", "Raster Properties registrable panels (register instances of javax.swing.JPanel)")); |
143 |
} |
144 |
|
145 |
// A?adimos la configuracion de Raster a gvSIG
|
146 |
extensionPoints.add("AplicationPreferences","RasterPreferences", new RasterPreferences()); |
147 |
|
148 |
// A?adimos paneles al cuadro de propiedades.
|
149 |
extensionPoints.add("RasterSEPropertiesDialog", "info", InfoPanel.class); |
150 |
extensionPoints.add("RasterSEPropertiesDialog", "bands_panel", BandSetupPanel.class); |
151 |
extensionPoints.add("RasterSEPropertiesDialog", "transparencia", TransparencyPanel.class); |
152 |
extensionPoints.add("RasterSEPropertiesDialog", "realce", EnhancedPanel.class); |
153 |
extensionPoints.add("RasterSEPropertiesDialog", "pansharp", PanSharpeningPanel.class); |
154 |
extensionPoints.add("RasterSEPropertiesDialog", "scale_panel", ScalePanel.class); |
155 |
|
156 |
// A?adimos las entradas del men? del toc de raster
|
157 |
extensionPoints.add("View_TocActions", "HistogramPanel", new HistogramTocMenuEntry()); |
158 |
extensionPoints.add("View_TocActions", "ClippingPanel", new ClippingTocMenuEntry()); |
159 |
extensionPoints.add("View_TocActions", "FilterPanel", new FilterTocMenuEntry()); |
160 |
extensionPoints.add("View_TocActions", "RasterSEProperties", new RasterPropertiesTocMenuEntry()); |
161 |
extensionPoints.add("View_TocActions", "ZoomPixelCursor", new ZoomPixelCursorTocMenuEntry()); |
162 |
extensionPoints.add("View_TocActions", "SaveAs", new SaveAsTocMenuEntry()); |
163 |
extensionPoints.add("View_TocActions", "ViewRasterAnalysis", new ViewRasterAnalysisTocMenuEntry()); |
164 |
extensionPoints.add("View_TocActions", "ViewColorTable", new ColorTableTocMenuEntry()); |
165 |
extensionPoints.add("View_TocActions", "GeoLocation", new GeoLocationTocMenuEntry()); |
166 |
extensionPoints.add("View_TocActions", "RoisManager", new ROIManagerTocMenuEntry()); |
167 |
extensionPoints.add("View_TocActions", "Overviews", new OverviewsTocMenuEntry()); |
168 |
|
169 |
// A?adimos nuestra extension para el tratamiento de la apertura de ficheros
|
170 |
// dentro de gvSIG
|
171 |
extensionPoints.add("FileExtendingOpenDialog", "FileOpenRaster", FileOpenRaster.class); |
172 |
|
173 |
//Alias
|
174 |
LayerFactory.registerLayerClassForName("com.iver.cit.gvsig.fmap.layers.FLyrRaster", FLyrRasterSE.class);
|
175 |
LayerFactory.registerLayerClassForName("com.iver.cit.gvsig.fmap.layers.StatusLayerRaster", StatusLayerRaster.class);
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* Registra los iconos a utilizar en andami.
|
180 |
*/
|
181 |
private void registerIcons(){ |
182 |
PluginServices.getIconTheme().registerDefault( |
183 |
"forward-icon",
|
184 |
this.getClass().getClassLoader().getResource("images/forward.png") |
185 |
); |
186 |
PluginServices.getIconTheme().registerDefault( |
187 |
"backward-icon",
|
188 |
this.getClass().getClassLoader().getResource("images/backward.png") |
189 |
); |
190 |
PluginServices.getIconTheme().registerDefault( |
191 |
"map-ok-ico",
|
192 |
MapControl.class.getResource("images/map_ico_ok.gif")
|
193 |
); |
194 |
PluginServices.getIconTheme().registerDefault( |
195 |
"crux-cursor",
|
196 |
MapControl.class.getResource("images/CruxCursor.png")
|
197 |
); |
198 |
PluginServices.getIconTheme().registerDefault( |
199 |
"addlayer-icon",
|
200 |
this.getClass().getClassLoader().getResource("images/addlayer.png") |
201 |
); |
202 |
PluginServices.getIconTheme().registerDefault( |
203 |
"delall-icon",
|
204 |
this.getClass().getClassLoader().getResource("images/delall.png") |
205 |
); |
206 |
PluginServices.getIconTheme().registerDefault( |
207 |
"rotar-icon",
|
208 |
this.getClass().getClassLoader().getResource("images/Rotar.gif") |
209 |
); |
210 |
PluginServices.getIconTheme().registerDefault( |
211 |
"hor-arrow-icon",
|
212 |
this.getClass().getClassLoader().getResource("images/FlechaHorizCursor.gif") |
213 |
); |
214 |
PluginServices.getIconTheme().registerDefault( |
215 |
"ver-arrow-icon",
|
216 |
this.getClass().getClassLoader().getResource("images/FlechaVertCursor.gif") |
217 |
); |
218 |
PluginServices.getIconTheme().registerDefault( |
219 |
"inclder-arrow-icon",
|
220 |
this.getClass().getClassLoader().getResource("images/FlechaInclDerCursor.gif") |
221 |
); |
222 |
PluginServices.getIconTheme().registerDefault( |
223 |
"inclizq-arrow-icon",
|
224 |
this.getClass().getClassLoader().getResource("images/FlechaInclIzqCursor.gif") |
225 |
); |
226 |
PluginServices.getIconTheme().registerDefault( |
227 |
"shear-y-icon",
|
228 |
this.getClass().getClassLoader().getResource("images/y.gif") |
229 |
); |
230 |
PluginServices.getIconTheme().registerDefault( |
231 |
"shear-x-icon",
|
232 |
this.getClass().getClassLoader().getResource("images/x.gif") |
233 |
); |
234 |
PluginServices.getIconTheme().registerDefault( |
235 |
"hand-icon",
|
236 |
this.getClass().getClassLoader().getResource("images/Hand.gif") |
237 |
); |
238 |
|
239 |
PluginServices.getIconTheme().registerDefault( |
240 |
"back-icon",
|
241 |
this.getClass().getClassLoader().getResource("images/back.png") |
242 |
); |
243 |
PluginServices.getIconTheme().registerDefault( |
244 |
"next-icon",
|
245 |
this.getClass().getClassLoader().getResource("images/next.png") |
246 |
); |
247 |
PluginServices.getIconTheme().registerDefault( |
248 |
"undo-icon",
|
249 |
this.getClass().getClassLoader().getResource("images/undo.png") |
250 |
); |
251 |
PluginServices.getIconTheme().registerDefault( |
252 |
"zoom-pixel-cursor",
|
253 |
this.getClass().getClassLoader().getResource("images/ZoomPixelCursor.gif") |
254 |
); |
255 |
|
256 |
PluginServices.getIconTheme().registerDefault( |
257 |
"save-raster",
|
258 |
this.getClass().getClassLoader().getResource("images/Rectangle.png") |
259 |
); |
260 |
|
261 |
PluginServices.getIconTheme().registerDefault( |
262 |
"pixel-increase",
|
263 |
this.getClass().getClassLoader().getResource("images/increase.png") |
264 |
); |
265 |
|
266 |
PluginServices.getIconTheme().registerDefault( |
267 |
"select-raster",
|
268 |
this.getClass().getClassLoader().getResource("images/stock_toggle-info.png") |
269 |
); |
270 |
PluginServices.getIconTheme().registerDefault( |
271 |
"select-raster",
|
272 |
this.getClass().getClassLoader().getResource("images/stock_toggle-info.png") |
273 |
); |
274 |
PluginServices.getIconTheme().registerDefault( |
275 |
"export-icon",
|
276 |
this.getClass().getClassLoader().getResource("images/export.png") |
277 |
); |
278 |
PluginServices.getIconTheme().registerDefault( |
279 |
"pref-raster-icon",
|
280 |
this.getClass().getClassLoader().getResource("images/raster-pref.png") |
281 |
); |
282 |
PluginServices.getIconTheme().registerDefault( |
283 |
"import-icon",
|
284 |
this.getClass().getClassLoader().getResource("images/import.png") |
285 |
); |
286 |
PluginServices.getIconTheme().registerDefault( |
287 |
"save-icon",
|
288 |
this.getClass().getClassLoader().getResource("images/save.png") |
289 |
); |
290 |
PluginServices.getIconTheme().registerDefault( |
291 |
"reset-icon",
|
292 |
this.getClass().getClassLoader().getResource("images/reset.png") |
293 |
); |
294 |
PluginServices.getIconTheme().registerDefault( |
295 |
"tfwload-icon",
|
296 |
this.getClass().getClassLoader().getResource("images/load.png") |
297 |
); |
298 |
PluginServices.getIconTheme().registerDefault( |
299 |
"centerraster-icon",
|
300 |
this.getClass().getClassLoader().getResource("images/center_image.png") |
301 |
); |
302 |
} |
303 |
/*
|
304 |
* (non-Javadoc)
|
305 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
306 |
*/
|
307 |
public boolean isEnabled() { |
308 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
309 |
if (f == null) { |
310 |
return false; |
311 |
} |
312 |
if (f.getClass() == View.class) { |
313 |
View vista = (View) f; |
314 |
IProjectView model = vista.getModel(); |
315 |
MapContext mapa = model.getMapContext(); |
316 |
FLayers layers = mapa.getLayers(); |
317 |
for (int i = 0; i < layers.getLayersCount(); i++) |
318 |
if (layers.getLayer(i) instanceof FLyrRasterSE) |
319 |
return true; |
320 |
} |
321 |
return false; |
322 |
} |
323 |
|
324 |
/**
|
325 |
* Mostramos el control si hay alguna capa cargada.
|
326 |
*/
|
327 |
public boolean isVisible() { |
328 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
329 |
if (f == null) |
330 |
return false; |
331 |
|
332 |
if (f instanceof View) { |
333 |
View vista = (View) f; |
334 |
IProjectView model = vista.getModel(); |
335 |
MapContext mapa = model.getMapContext(); |
336 |
if (mapa.getLayers().getLayersCount() > 0) |
337 |
return true; |
338 |
} |
339 |
|
340 |
return false; |
341 |
} |
342 |
|
343 |
/**
|
344 |
* Carga los valores de configuracion iniciales
|
345 |
*/
|
346 |
private void loadConfigurationValues() { |
347 |
autoRefreshView = Configuration.getValue("general_auto_preview", Boolean.TRUE).booleanValue(); |
348 |
askCoordinates = Configuration.getValue("general_ask_coordinates", Boolean.FALSE).booleanValue(); |
349 |
RasterLibrary.defaultNumberOfClasses = Configuration.getValue("general_defaultNumberOfClasses", Integer.valueOf(RasterLibrary.defaultNumberOfClasses)).intValue(); |
350 |
RasterLibrary.cacheSize = Configuration.getValue("cache_size", Long.valueOf(RasterLibrary.cacheSize)).longValue(); |
351 |
RasterLibrary.pageSize = Configuration.getValue("cache_pagesize", Double.valueOf(RasterLibrary.pageSize)).doubleValue(); |
352 |
RasterLibrary.pagsPerGroup = Configuration.getValue("cache_pagspergroup", Integer.valueOf(RasterLibrary.pagsPerGroup)).intValue(); |
353 |
RasterLibrary.blockHeight = Configuration.getValue("cache_blockheight", Integer.valueOf(RasterLibrary.blockHeight)).intValue(); |
354 |
RasterLibrary.noDataEnabled = Configuration.getValue("nodata_enabled", Boolean.valueOf(RasterLibrary.noDataEnabled)).booleanValue(); |
355 |
RasterLibrary.noDataValue = Configuration.getValue("nodata_value", Double.valueOf(RasterLibrary.noDataValue)).doubleValue(); |
356 |
} |
357 |
|
358 |
/*
|
359 |
* (non-Javadoc)
|
360 |
* @see org.gvsig.raster.util.ConfigurationListener#actionConfigurationChanged(org.gvsig.raster.util.ConfigurationEvent)
|
361 |
*/
|
362 |
public void actionConfigurationChanged(ConfigurationEvent e) { |
363 |
if (e.getKey().equals("general_auto_preview")) { |
364 |
autoRefreshView = ((Boolean) e.getValue()).booleanValue();
|
365 |
return;
|
366 |
} |
367 |
|
368 |
if (e.getKey().equals("general_ask_coordinates")) { |
369 |
askCoordinates = ((Boolean) e.getValue()).booleanValue();
|
370 |
return;
|
371 |
} |
372 |
|
373 |
if (e.getKey().equals("general_defaultNumberOfClasses")) { |
374 |
RasterLibrary.defaultNumberOfClasses = ((Integer) e.getValue()).intValue();
|
375 |
return;
|
376 |
} |
377 |
|
378 |
if (e.getKey().equals("cache_size")) { |
379 |
RasterLibrary.cacheSize = ((Long) e.getValue()).longValue();
|
380 |
return;
|
381 |
} |
382 |
|
383 |
if (e.getKey().equals("cache_pagesize")) { |
384 |
RasterLibrary.pageSize = ((Double) e.getValue()).doubleValue();
|
385 |
return;
|
386 |
} |
387 |
|
388 |
if (e.getKey().equals("cache_pagspergroup")) { |
389 |
RasterLibrary.pagsPerGroup = ((Integer) e.getValue()).intValue();
|
390 |
return;
|
391 |
} |
392 |
|
393 |
if (e.getKey().equals("cache_blockheight")) { |
394 |
RasterLibrary.blockHeight = ((Integer) e.getValue()).intValue();
|
395 |
return;
|
396 |
} |
397 |
|
398 |
if (e.getKey().equals("nodata_enabled")) { |
399 |
RasterLibrary.noDataEnabled = ((Boolean) e.getValue()).booleanValue();
|
400 |
return;
|
401 |
} |
402 |
|
403 |
if (e.getKey().equals("nodata_value")) { |
404 |
RasterLibrary.noDataValue = ((Double) e.getValue()).doubleValue();
|
405 |
return;
|
406 |
} |
407 |
} |
408 |
} |