svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / RasterModule.java @ 11893
History | View | Annotate | Download (8.07 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 |
|
20 |
package org.gvsig.rastertools; |
21 |
|
22 |
import java.util.prefs.Preferences; |
23 |
|
24 |
import org.gvsig.rastertools.cutting.CuttingTocMenuEntry; |
25 |
import org.gvsig.rastertools.filter.FilterTocMenuEntry; |
26 |
import org.gvsig.rastertools.histogram.HistogramTocMenuEntry; |
27 |
import org.gvsig.rastertools.pixelincrease.PixelncreaseDialog; |
28 |
import org.gvsig.rastertools.properties.dialog.RasterPropertiesTocMenuEntry; |
29 |
import org.gvsig.rastertools.properties.panels.BandSetupPanel; |
30 |
import org.gvsig.rastertools.properties.panels.EnhancedPanel; |
31 |
import org.gvsig.rastertools.properties.panels.InfoPanel; |
32 |
import org.gvsig.rastertools.properties.panels.TransparencyPanel; |
33 |
import org.gvsig.rastertools.rasterresolution.ZoomPixelCursorTocMenuEntry; |
34 |
import org.gvsig.rastertools.saveraster.map.SaveRasterListener; |
35 |
import org.gvsig.rastertools.selectrasterlayer.SelectImageListener; |
36 |
import org.gvsig.rastertools.wizards.FileOpenRasterDialog; |
37 |
|
38 |
import com.iver.andami.PluginServices; |
39 |
import com.iver.andami.plugins.Extension; |
40 |
import com.iver.andami.ui.mdiManager.IWindow; |
41 |
import com.iver.cit.gvsig.AddLayer; |
42 |
import com.iver.cit.gvsig.fmap.MapContext; |
43 |
import com.iver.cit.gvsig.fmap.MapControl; |
44 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
45 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
46 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
47 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
48 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
49 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
50 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
51 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
52 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
53 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
54 |
|
55 |
/**
|
56 |
* Extensi?n que adapta a FMap y gvSIG la nueva implementaci?n de raster. Para
|
57 |
* el cuadro de Propiedades de visualizaci?n de raster contiene el contenedor
|
58 |
* base se registran la entrada del men? del TOC y los paneles en el cuadro.
|
59 |
* Para la parte de FMap contiene una nueva capa raster y los drivers
|
60 |
* necesarios.
|
61 |
*
|
62 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
63 |
*/
|
64 |
public class RasterModule extends Extension{ |
65 |
|
66 |
public static void setPath(String value) { |
67 |
Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
68 |
prefs.put("DataFolder", value);
|
69 |
} |
70 |
|
71 |
public static String getPath() { |
72 |
Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
73 |
return prefs.get("DataFolder", null); |
74 |
} |
75 |
|
76 |
public void execute(String actionCommand) { |
77 |
View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
78 |
MapControl mapCtrl = theView.getMapControl(); |
79 |
|
80 |
//Listener de eventos de movimiento que pone las coordenadas del rat?n en la barra de estado
|
81 |
StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
82 |
|
83 |
if(actionCommand.equals("SAVERASTER")) { |
84 |
loadSaveRasterListener(mapCtrl, sbl); |
85 |
mapCtrl.setTool("saveRaster");
|
86 |
} |
87 |
|
88 |
if(actionCommand.equals("PIXELINCREASE")) { |
89 |
IWindow[] win = PluginServices.getMDIManager().getAllWindows();
|
90 |
for (int i = 0; i < win.length; i++) { |
91 |
if(win[i] instanceof PixelncreaseDialog) { |
92 |
PluginServices.getMDIManager().closeWindow(win[i]); |
93 |
return;
|
94 |
} |
95 |
} |
96 |
PixelncreaseDialog pIncrease = new PixelncreaseDialog();
|
97 |
PluginServices.getMDIManager().addWindow(pIncrease); |
98 |
} |
99 |
|
100 |
if (actionCommand.equals("SELECTIMAGE")) { |
101 |
loadSelectRasterListener(mapCtrl, sbl); |
102 |
mapCtrl.setTool("selectRasterLayer");
|
103 |
} |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Carga el listener de salvar a raster en el MapControl.
|
108 |
*/
|
109 |
private void loadSaveRasterListener(MapControl m_MapControl, StatusBarListener sbl) { |
110 |
//Si no se ha cargado el listener a?n lo cargamos.
|
111 |
if(m_MapControl.getNamesMapTools().get("saveRaster") == null) { |
112 |
//Salvar a Raster
|
113 |
SaveRasterListener srl = new SaveRasterListener(m_MapControl);
|
114 |
m_MapControl.addMapTool("saveRaster", new Behavior[]{ |
115 |
new RectangleBehavior(srl), new MouseMovementBehavior(sbl)}); |
116 |
} |
117 |
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Carga el listener de selecci?n de raster en el MapControl.
|
122 |
*/
|
123 |
private void loadSelectRasterListener(MapControl mapCtrl, StatusBarListener sbl) { |
124 |
if(mapCtrl.getNamesMapTools().get("selectRasterLayer") == null) { |
125 |
SelectImageListener sil = new SelectImageListener(mapCtrl);
|
126 |
mapCtrl.addMapTool("selectRasterLayer", new Behavior[]{ |
127 |
new PointBehavior(sil), new MouseMovementBehavior(sbl)}); |
128 |
mapCtrl.setTool("selectRasterLayer");
|
129 |
} |
130 |
} |
131 |
|
132 |
/*
|
133 |
* (non-Javadoc)
|
134 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
135 |
*/
|
136 |
public void initialize() { |
137 |
// DiagSignalHandler.install("ALRM");
|
138 |
|
139 |
InfoPanel info = new InfoPanel();
|
140 |
BandSetupPanel bandSetup = new BandSetupPanel();
|
141 |
TransparencyPanel transpPanel = new TransparencyPanel();
|
142 |
EnhancedPanel enhancedPanel = new EnhancedPanel();
|
143 |
|
144 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
145 |
|
146 |
//Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
|
147 |
if (!extensionPoints.containsKey("RasterSEProperties")) { |
148 |
extensionPoints.put( |
149 |
new ExtensionPoint(
|
150 |
"RasterSEPropertiesDialog",
|
151 |
"Raster Properties registrable panels (register instances of javax.swing.JPanel)")
|
152 |
); |
153 |
} |
154 |
//A?adimos paneles al cuadro de propiedades.
|
155 |
extensionPoints.add("RasterSEPropertiesDialog", info.getID(), info);
|
156 |
extensionPoints.add("RasterSEPropertiesDialog", bandSetup.getID(), bandSetup);
|
157 |
extensionPoints.add("RasterSEPropertiesDialog", transpPanel.getID(), transpPanel);
|
158 |
extensionPoints.add("RasterSEPropertiesDialog", enhancedPanel.getID(), enhancedPanel);
|
159 |
|
160 |
//A?adimos la entrada del toc de la ventana de Histograma.
|
161 |
extensionPoints.add("View_TocActions","HistogramPanel",new HistogramTocMenuEntry()); |
162 |
|
163 |
//A?adimos la entrada del toc de la ventana de Recorte.
|
164 |
extensionPoints.add("View_TocActions","CuttingPanel",new CuttingTocMenuEntry()); |
165 |
|
166 |
//A?adimos la entrada del toc de la ventana de Filtros.
|
167 |
extensionPoints.add("View_TocActions","FilterPanel",new FilterTocMenuEntry()); |
168 |
|
169 |
//A?adimos la entrada del toc del cuadro de Propiedades. Como se llama igual sustituye a la vieja.
|
170 |
extensionPoints.add("View_TocActions","RasterSEProperties",new RasterPropertiesTocMenuEntry()); |
171 |
|
172 |
//A?adimos la entrada del toc de zoom a la resoluci?n del raster.
|
173 |
extensionPoints.add("View_TocActions","ZoomPixelCursor",new ZoomPixelCursorTocMenuEntry()); |
174 |
|
175 |
//A?adimos el panel al winzard de cargar capa. (Esto es temporal hasta que el actual sea totalmente extensible)
|
176 |
AddLayer.addWizard(FileOpenRasterDialog.class); |
177 |
} |
178 |
|
179 |
/*
|
180 |
* (non-Javadoc)
|
181 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
182 |
*/
|
183 |
public boolean isEnabled() { |
184 |
return true; |
185 |
} |
186 |
|
187 |
/**
|
188 |
* Mostramos el control si hay alguna capa cargada.
|
189 |
*/
|
190 |
public boolean isVisible() { |
191 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
192 |
if (f == null) |
193 |
return false; |
194 |
|
195 |
if (f instanceof View) { |
196 |
View vista = (View) f; |
197 |
IProjectView model = vista.getModel(); |
198 |
MapContext mapa = model.getMapContext(); |
199 |
if (mapa.getLayers().getLayersCount() > 0) |
200 |
return true; |
201 |
} |
202 |
|
203 |
return false; |
204 |
} |
205 |
|
206 |
} |