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