svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / GenericToolBarModule.java @ 28995
History | View | Annotate | Download (8.79 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.fmap.mapcontext.MapContext; |
28 |
import org.gvsig.raster.util.RasterToolsUtil; |
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 |
import org.gvsig.tools.ToolsLocator; |
47 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
48 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
49 |
|
50 |
import com.iver.andami.PluginServices; |
51 |
import com.iver.andami.plugins.Extension; |
52 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
53 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
54 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
55 |
/**
|
56 |
* Extension para la barra de herramientas generica
|
57 |
*
|
58 |
* @version 13/02/2008
|
59 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
60 |
*/
|
61 |
public class GenericToolBarModule extends Extension { |
62 |
private GenericToolBarPanel toolBar = null; |
63 |
|
64 |
/**
|
65 |
* Crea y devuelve la barra de herramientas
|
66 |
* @return
|
67 |
*/
|
68 |
private GenericToolBarPanel getGenericToolBarPanel() {
|
69 |
if (toolBar == null) { |
70 |
MDIFrame f = (MDIFrame) PluginServices.getMainFrame(); |
71 |
if (f == null) |
72 |
return null; |
73 |
for (int i = 0; i < f.getContentPane().getComponentCount(); i++) { |
74 |
if (f.getContentPane().getComponent(i) instanceof JPanel) { |
75 |
JPanel panel = (JPanel) f.getContentPane().getComponent(i); |
76 |
for (int j = 0; j < panel.getComponentCount(); j++) { |
77 |
if (panel.getComponent(j) instanceof JToolBar) { |
78 |
toolBar = new GenericToolBarPanel();
|
79 |
panel.add(toolBar, BorderLayout.PAGE_START);
|
80 |
return toolBar;
|
81 |
} |
82 |
} |
83 |
} |
84 |
} |
85 |
} else {
|
86 |
toolBar.setPreferredSize(new Dimension(300, getToolbarHeight())); |
87 |
} |
88 |
|
89 |
return toolBar;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Obtenemos el alto de cualquier toolbar que este visible en gvSIG y no sea
|
94 |
* nuestro para poder asignarselo al GenericToolBar como PreferredSize. En
|
95 |
* caso de no encontrar ninguno que cumpla las condiciones, se devolver? 24
|
96 |
* @return
|
97 |
*/
|
98 |
private int getToolbarHeight() { |
99 |
if ((PluginServices.getMainFrame() == null) || |
100 |
(PluginServices.getMainFrame().getToolbars() == null) ||
|
101 |
(PluginServices.getMainFrame().getToolbars().length <= 0))
|
102 |
return 24; |
103 |
|
104 |
for (int i = 0; i < PluginServices.getMainFrame().getToolbars().length; i++) { |
105 |
if ((PluginServices.getMainFrame().getToolbars()[i].getHeight() > 16) && |
106 |
((Object) PluginServices.getMainFrame().getToolbars()[i] != (Object) toolBar)) |
107 |
return PluginServices.getMainFrame().getToolbars()[i].getHeight();
|
108 |
} |
109 |
return 24; |
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
115 |
*/
|
116 |
public void initialize() { |
117 |
registerIcons(); |
118 |
|
119 |
// Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
|
120 |
ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager(); |
121 |
ExtensionPoint point=extensionPoints.add("GenericToolBarGroup");
|
122 |
point.setDescription("Punto de extension para los grupos de menus del GenericToolBarPanel");
|
123 |
|
124 |
point.append("RasterLayer", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "capa_raster"), PluginServices.getIconTheme().get("layer-icon"))); |
125 |
point.append("RasterProcess", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "process_raster"), PluginServices.getIconTheme().get("process-icon"))); |
126 |
point.append("GeoRaster", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "transformaciones_geograficas"), PluginServices.getIconTheme().get("transgeo-icon"))); |
127 |
point.append("RasterExport", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "raster_export"), PluginServices.getIconTheme().get("raster-export"))); |
128 |
|
129 |
point = extensionPoints.add("GenericToolBarMenu");
|
130 |
point.setDescription("Punto de extension para los submenus del GenericToolBarPanel");
|
131 |
point.append("RasterProperties", "", RasterPropertiesTocMenuEntry.getSingleton()); |
132 |
point.append("SelectLayer", "", SelectLayerTocMenuEntry.getSingleton()); |
133 |
point.append("HistogramPanel", "", HistogramTocMenuEntry.getSingleton()); |
134 |
point.append("ViewColorTable", "",ColorTableTocMenuEntry.getSingleton()); |
135 |
point.append("Overviews", "", OverviewsTocMenuEntry.getSingleton()); |
136 |
point.append("RoisManager", "", ROIManagerTocMenuEntry.getSingleton()); |
137 |
point.append("ViewRasterAnalysis", "", ViewRasterAnalysisTocMenuEntry.getSingleton()); |
138 |
|
139 |
point.append("SaveAs", "", SaveAsTocMenuEntry.getSingleton()); |
140 |
point.append("ClippingPanel", "", ClippingTocMenuEntry.getSingleton()); |
141 |
point.append("SaveRaster", "", SaveRasterTocMenuEntry.getSingleton()); |
142 |
|
143 |
point.append("FilterPanel", "", FilterTocMenuEntry.getSingleton()); |
144 |
point.append("EnhancedPanel", "", EnhancedTocMenuEntry.getSingleton()); |
145 |
point.append("GeoLocation", "", GeoLocationTocMenuEntry.getSingleton()); |
146 |
point.append("Vectorization", "", VectorizationTocMenuEntry.getSingleton()); |
147 |
ReprojectTocMenuEntry menuEntry = ReprojectTocMenuEntry.getSingleton(); |
148 |
point.append(menuEntry.getText(), "", menuEntry);
|
149 |
|
150 |
if (getGenericToolBarPanel() != null) |
151 |
getGenericToolBarPanel().reloadMenuGroup(); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* Registra los iconos a utilizar en la botonera.
|
156 |
*/
|
157 |
private void registerIcons() { |
158 |
PluginServices.getIconTheme().register( |
159 |
"layer-icon",
|
160 |
this.getClass().getClassLoader().getResource("images/rasterlayer.png") |
161 |
); |
162 |
PluginServices.getIconTheme().register( |
163 |
"process-icon",
|
164 |
this.getClass().getClassLoader().getResource("images/icon_process.gif") |
165 |
); |
166 |
PluginServices.getIconTheme().register( |
167 |
"transgeo-icon",
|
168 |
this.getClass().getClassLoader().getResource("images/rastertransgeo.gif") |
169 |
); |
170 |
PluginServices.getIconTheme().registerDefault( |
171 |
"raster-export",
|
172 |
this.getClass().getClassLoader().getResource("images/raster-export.png") |
173 |
); |
174 |
} |
175 |
|
176 |
/*
|
177 |
* (non-Javadoc)
|
178 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
179 |
*/
|
180 |
public boolean isEnabled() { |
181 |
return false; |
182 |
} |
183 |
|
184 |
/**
|
185 |
* Establece si la barra de herramientas esta visible
|
186 |
* @param enabled
|
187 |
*/
|
188 |
private void setToolBarVisible(boolean enabled) { |
189 |
if (getGenericToolBarPanel() == null) |
190 |
return;
|
191 |
|
192 |
toolBar.setVisible(enabled); |
193 |
} |
194 |
|
195 |
/*
|
196 |
* (non-Javadoc)
|
197 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
198 |
*/
|
199 |
public boolean isVisible() { |
200 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
201 |
if (f == null) { |
202 |
setToolBarVisible(false);
|
203 |
return false; |
204 |
} |
205 |
|
206 |
if (f instanceof BaseView) { |
207 |
BaseView vista = (BaseView) f; |
208 |
IProjectView model = vista.getModel(); |
209 |
MapContext mapa = model.getMapContext(); |
210 |
if (mapa.getLayers().getLayersCount() > 0) { |
211 |
setToolBarVisible(true);
|
212 |
if (getGenericToolBarPanel() != null) { |
213 |
getGenericToolBarPanel().setLayers(mapa.getLayers()); |
214 |
} |
215 |
return true; |
216 |
} |
217 |
} |
218 |
|
219 |
setToolBarVisible(false);
|
220 |
return false; |
221 |
} |
222 |
|
223 |
public void execute(String actionCommand) {} |
224 |
} |