root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / RasterModule.java @ 13183
History | View | Annotate | Download (10.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.raster.gui.properties.dialog.RasterPropertiesTocMenuEntry; |
24 |
import org.gvsig.raster.gui.wizards.FileOpenRasterDialog; |
25 |
import org.gvsig.rastertools.analysisview.ViewRasterAnalysisTocMenuEntry; |
26 |
import org.gvsig.rastertools.colortable.ColorTableTocMenuEntry; |
27 |
import org.gvsig.rastertools.cutting.CuttingTocMenuEntry; |
28 |
import org.gvsig.rastertools.filter.FilterTocMenuEntry; |
29 |
import org.gvsig.rastertools.geolocation.behavior.GeoRasterBehavior; |
30 |
import org.gvsig.rastertools.geolocation.listener.GeorefPanListener; |
31 |
import org.gvsig.rastertools.geolocation.ui.GeoLocationDialog; |
32 |
import org.gvsig.rastertools.histogram.HistogramTocMenuEntry; |
33 |
import org.gvsig.rastertools.pixelincrease.PixelncreaseDialog; |
34 |
import org.gvsig.rastertools.properties.panels.BandSetupPanel; |
35 |
import org.gvsig.rastertools.properties.panels.EnhancedPanel; |
36 |
import org.gvsig.rastertools.properties.panels.InfoPanel; |
37 |
import org.gvsig.rastertools.properties.panels.PanSharpeningPanel; |
38 |
import org.gvsig.rastertools.properties.panels.TransparencyPanel; |
39 |
import org.gvsig.rastertools.rasterresolution.ZoomPixelCursorTocMenuEntry; |
40 |
import org.gvsig.rastertools.saveas.SaveAsTocMenuEntry; |
41 |
import org.gvsig.rastertools.saveraster.map.SaveRasterListener; |
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.andami.ui.mdiManager.IWindow; |
47 |
import com.iver.cit.gvsig.AddLayer; |
48 |
import com.iver.cit.gvsig.fmap.MapContext; |
49 |
import com.iver.cit.gvsig.fmap.MapControl; |
50 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
51 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
52 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
53 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
54 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
55 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
56 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
57 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
58 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
59 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
60 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
61 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
62 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
63 |
/**
|
64 |
* Extensi?n que adapta a FMap y gvSIG la nueva implementaci?n de raster. Para
|
65 |
* el cuadro de Propiedades de visualizaci?n de raster contiene el contenedor
|
66 |
* base se registran la entrada del men? del TOC y los paneles en el cuadro.
|
67 |
* Para la parte de FMap contiene una nueva capa raster y los drivers
|
68 |
* necesarios.
|
69 |
*
|
70 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
71 |
*/
|
72 |
public class RasterModule extends Extension{ |
73 |
/**
|
74 |
* Contador global de las capas generadas para raster
|
75 |
*/
|
76 |
public static int layerCount = 1; |
77 |
|
78 |
private GeoLocationDialog gld = null; |
79 |
|
80 |
/**
|
81 |
* Asigna la ?ltima ruta seleccionada en cualquier JFileChooser de la
|
82 |
* extensi?n de raster.
|
83 |
* @param value Valor de la ruta
|
84 |
*/
|
85 |
public static void setPath(String value) { |
86 |
Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
87 |
prefs.put("DataFolder", value);
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Obtiene la ?ltima ruta seleccionada en cualquier JFileChooser de la
|
92 |
* extensi?n de raster.
|
93 |
* @return Valor de la ruta
|
94 |
*/
|
95 |
public static String getPath() { |
96 |
Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
97 |
return prefs.get("DataFolder", null); |
98 |
} |
99 |
|
100 |
/*
|
101 |
* (non-Javadoc)
|
102 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
103 |
*/
|
104 |
public void execute(String actionCommand) { |
105 |
View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
106 |
MapControl mapCtrl = theView.getMapControl(); |
107 |
|
108 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
109 |
// la barra de estado
|
110 |
StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
111 |
|
112 |
if (actionCommand.equals("SAVERASTER")) { |
113 |
loadSaveRasterListener(mapCtrl, sbl); |
114 |
mapCtrl.setTool("saveRaster");
|
115 |
} |
116 |
|
117 |
if (actionCommand.equals("PIXELINCREASE")) { |
118 |
IWindow[] win = PluginServices.getMDIManager().getAllWindows();
|
119 |
for (int i = 0; i < win.length; i++) { |
120 |
if (win[i] instanceof PixelncreaseDialog) { |
121 |
PluginServices.getMDIManager().closeWindow(win[i]); |
122 |
return;
|
123 |
} |
124 |
} |
125 |
PixelncreaseDialog pIncrease = new PixelncreaseDialog();
|
126 |
PluginServices.getMDIManager().addWindow(pIncrease); |
127 |
} |
128 |
|
129 |
if (actionCommand.equals("SELECTIMAGE")) { |
130 |
loadSelectRasterListener(mapCtrl, sbl); |
131 |
mapCtrl.setTool("selectRasterLayer");
|
132 |
} |
133 |
|
134 |
if (actionCommand.equals("GEO_PAN")) { |
135 |
boolean isOpen = false; |
136 |
//Comprobamos si no hay capas activas. En este caso no lanzamos la ventana ni activamos la tool
|
137 |
IWindow[] win = PluginServices.getMDIManager().getAllWindows();
|
138 |
for (int i = 0; i < win.length; i++) { |
139 |
if (win[i] instanceof IView) { |
140 |
FLayers lyrs = ((IView)win[i]).getMapControl().getMapContext().getLayers(); |
141 |
FLayer[] actives = lyrs.getActives();
|
142 |
if(actives == null || actives.length == 0) |
143 |
return;
|
144 |
} |
145 |
if(win[i] instanceof GeoLocationDialog) |
146 |
isOpen = true;
|
147 |
} |
148 |
if(gld == null) |
149 |
gld = new GeoLocationDialog();
|
150 |
if(!isOpen) {
|
151 |
gld.calcPosition(); |
152 |
PluginServices.getMDIManager().addWindow(gld); |
153 |
} |
154 |
gld.init(mapCtrl); |
155 |
loadGeoPanListener(mapCtrl, sbl, gld); |
156 |
mapCtrl.setTool("geoPan");
|
157 |
} |
158 |
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Carga el listener de salvar a raster en el MapControl.
|
163 |
*/
|
164 |
private void loadSaveRasterListener(MapControl m_MapControl, StatusBarListener sbl) { |
165 |
// Si no se ha cargado el listener a?n lo cargamos.
|
166 |
if (m_MapControl.getNamesMapTools().get("saveRaster") == null) { |
167 |
SaveRasterListener srl = new SaveRasterListener(m_MapControl);
|
168 |
m_MapControl.addMapTool("saveRaster", new Behavior[] { new RectangleBehavior(srl), new MouseMovementBehavior(sbl) }); |
169 |
} |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Carga el listener de selecci?n de raster en el MapControl.
|
174 |
*/
|
175 |
private void loadSelectRasterListener(MapControl mapCtrl, StatusBarListener sbl) { |
176 |
if (mapCtrl.getNamesMapTools().get("selectRasterLayer") == null) { |
177 |
SelectImageListener sil = new SelectImageListener(mapCtrl);
|
178 |
mapCtrl.addMapTool("selectRasterLayer", new Behavior[] { new PointBehavior(sil), new MouseMovementBehavior(sbl) }); |
179 |
mapCtrl.setTool("selectRasterLayer");
|
180 |
} |
181 |
} |
182 |
|
183 |
/**
|
184 |
* Carga el listener de selecci?n de raster en el MapControl.
|
185 |
*/
|
186 |
private void loadGeoPanListener(MapControl mapCtrl, StatusBarListener sbl, GeoLocationDialog gld) { |
187 |
if (mapCtrl.getNamesMapTools().get("geoPan") == null) { |
188 |
GeorefPanListener pl = new GeorefPanListener(mapCtrl);
|
189 |
GeoRasterBehavior mb = new GeoRasterBehavior(pl, gld);
|
190 |
mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)}); |
191 |
|
192 |
} |
193 |
} |
194 |
|
195 |
/*
|
196 |
* (non-Javadoc)
|
197 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
198 |
*/
|
199 |
public void initialize() { |
200 |
// DiagSignalHandler.install("ALRM");
|
201 |
|
202 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
203 |
prefs.put("DataFolder", System.getProperty("user.home")); |
204 |
|
205 |
InfoPanel info = new InfoPanel();
|
206 |
BandSetupPanel bandSetup = new BandSetupPanel();
|
207 |
TransparencyPanel transpPanel = new TransparencyPanel();
|
208 |
EnhancedPanel enhancedPanel = new EnhancedPanel();
|
209 |
PanSharpeningPanel pansharpeningPanel= new PanSharpeningPanel();
|
210 |
|
211 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
212 |
|
213 |
// Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
|
214 |
if (!extensionPoints.containsKey("RasterSEProperties")) { |
215 |
extensionPoints.put(new ExtensionPoint("RasterSEPropertiesDialog", "Raster Properties registrable panels (register instances of javax.swing.JPanel)")); |
216 |
} |
217 |
// A?adimos paneles al cuadro de propiedades.
|
218 |
extensionPoints.add("RasterSEPropertiesDialog", info.getID(), info);
|
219 |
extensionPoints.add("RasterSEPropertiesDialog", bandSetup.getID(), bandSetup);
|
220 |
extensionPoints.add("RasterSEPropertiesDialog", transpPanel.getID(), transpPanel);
|
221 |
extensionPoints.add("RasterSEPropertiesDialog", enhancedPanel.getID(), enhancedPanel);
|
222 |
extensionPoints.add("RasterSEPropertiesDialog", pansharpeningPanel.getID(), pansharpeningPanel);
|
223 |
// A?adimos la entrada del toc de la ventana de Histograma.
|
224 |
extensionPoints.add("View_TocActions", "HistogramPanel", new HistogramTocMenuEntry()); |
225 |
|
226 |
// A?adimos la entrada del toc de la ventana de Recorte.
|
227 |
extensionPoints.add("View_TocActions", "CuttingPanel", new CuttingTocMenuEntry()); |
228 |
|
229 |
// A?adimos la entrada del toc de la ventana de Filtros.
|
230 |
extensionPoints.add("View_TocActions", "FilterPanel", new FilterTocMenuEntry()); |
231 |
|
232 |
// A?adimos la entrada del toc del cuadro de Propiedades. Como se llama igual sustituye a la vieja.
|
233 |
extensionPoints.add("View_TocActions", "RasterSEProperties", new RasterPropertiesTocMenuEntry()); |
234 |
|
235 |
// A?adimos la entrada del toc de zoom a la resoluci?n del raster.
|
236 |
extensionPoints.add("View_TocActions", "ZoomPixelCursor", new ZoomPixelCursorTocMenuEntry()); |
237 |
|
238 |
// A?adimos la entrada del toc de zoom Salvar Como.
|
239 |
extensionPoints.add("View_TocActions", "SaveAs", new SaveAsTocMenuEntry()); |
240 |
|
241 |
// A?adimos la entrada del toc de la vista de analisis.
|
242 |
extensionPoints.add("View_TocActions", "ViewRasterAnalysis", new ViewRasterAnalysisTocMenuEntry()); |
243 |
|
244 |
// A?adimos la entrada del toc de la vista de analisis.
|
245 |
extensionPoints.add("View_TocActions", "ViewColorTable", new ColorTableTocMenuEntry()); |
246 |
|
247 |
// A?adimos el panel al winzard de cargar capa. (Esto es temporal hasta que el actual sea totalmente extensible)
|
248 |
AddLayer.addWizard(FileOpenRasterDialog.class); |
249 |
} |
250 |
|
251 |
/*
|
252 |
* (non-Javadoc)
|
253 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
254 |
*/
|
255 |
public boolean isEnabled() { |
256 |
return true; |
257 |
} |
258 |
|
259 |
/**
|
260 |
* Mostramos el control si hay alguna capa cargada.
|
261 |
*/
|
262 |
public boolean isVisible() { |
263 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
264 |
if (f == null) |
265 |
return false; |
266 |
|
267 |
if (f instanceof View) { |
268 |
View vista = (View) f; |
269 |
IProjectView model = vista.getModel(); |
270 |
MapContext mapa = model.getMapContext(); |
271 |
if (mapa.getLayers().getLayersCount() > 0) |
272 |
return true; |
273 |
} |
274 |
|
275 |
return false; |
276 |
} |
277 |
} |