gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / GenericToolBarModule.java @ 1151
History | View | Annotate | Download (9.73 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.tool; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Dimension; |
26 |
|
27 |
import javax.swing.JPanel; |
28 |
import javax.swing.JToolBar; |
29 |
|
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.plugins.Extension; |
32 |
import org.gvsig.andami.ui.mdiFrame.MDIFrame; |
33 |
import org.gvsig.app.project.documents.view.ViewDocument; |
34 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
35 |
import org.gvsig.fmap.mapcontext.MapContext; |
36 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
37 |
import org.gvsig.raster.tools.app.basic.tool.analysisview.ViewRasterAnalysisTocMenuEntry; |
38 |
import org.gvsig.raster.tools.app.basic.tool.clip.ClippingTocMenuEntry; |
39 |
import org.gvsig.raster.tools.app.basic.tool.colortable.ColorTableTocMenuEntry; |
40 |
import org.gvsig.raster.tools.app.basic.tool.enhanced.EnhancedTocMenuEntry; |
41 |
import org.gvsig.raster.tools.app.basic.tool.filter.FilterTocMenuEntry; |
42 |
import org.gvsig.raster.tools.app.basic.tool.generictoolbar.GenericToolBarMenuItem; |
43 |
import org.gvsig.raster.tools.app.basic.tool.generictoolbar.GenericToolBarPanel; |
44 |
import org.gvsig.raster.tools.app.basic.tool.geolocation.GeoLocationTocMenuEntry; |
45 |
import org.gvsig.raster.tools.app.basic.tool.histogram.HistogramTocMenuEntry; |
46 |
import org.gvsig.raster.tools.app.basic.tool.infobypoint.InfoByRasterPointTocMenuEntry; |
47 |
import org.gvsig.raster.tools.app.basic.tool.overview.OverviewsTocMenuEntry; |
48 |
import org.gvsig.raster.tools.app.basic.tool.properties.RasterPropertiesTocMenuEntry; |
49 |
import org.gvsig.raster.tools.app.basic.tool.reproject.ReprojectTocMenuEntry; |
50 |
import org.gvsig.raster.tools.app.basic.tool.roi.ROIManagerTocMenuEntry; |
51 |
import org.gvsig.raster.tools.app.basic.tool.saveas.SaveAsTocMenuEntry; |
52 |
import org.gvsig.raster.tools.app.basic.tool.saveraster.SaveRasterTocMenuEntry; |
53 |
import org.gvsig.raster.tools.app.basic.tool.selectrasterlayer.SelectLayerTocMenuEntry; |
54 |
import org.gvsig.tools.ToolsLocator; |
55 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
56 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
57 |
|
58 |
/**
|
59 |
* Extension para la barra de herramientas generica
|
60 |
*
|
61 |
* @version 13/02/2008
|
62 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
63 |
*/
|
64 |
public class GenericToolBarModule extends Extension { |
65 |
private GenericToolBarPanel toolBar = null; |
66 |
|
67 |
/**
|
68 |
* Crea y devuelve la barra de herramientas
|
69 |
* @return
|
70 |
*/
|
71 |
private GenericToolBarPanel getGenericToolBarPanel() {
|
72 |
if (toolBar == null) { |
73 |
MDIFrame f = (MDIFrame) PluginServices.getMainFrame(); |
74 |
if (f == null) |
75 |
return null; |
76 |
for (int i = 0; i < f.getContentPane().getComponentCount(); i++) { |
77 |
if (f.getContentPane().getComponent(i) instanceof JPanel) { |
78 |
JPanel panel = (JPanel) f.getContentPane().getComponent(i); |
79 |
for (int j = 0; j < panel.getComponentCount(); j++) { |
80 |
if (panel.getComponent(j) instanceof JToolBar) { |
81 |
toolBar = new GenericToolBarPanel();
|
82 |
panel.add(toolBar, BorderLayout.PAGE_START);
|
83 |
return toolBar;
|
84 |
} |
85 |
} |
86 |
} |
87 |
} |
88 |
} else {
|
89 |
toolBar.setPreferredSize(new Dimension(300, getToolbarHeight())); |
90 |
} |
91 |
|
92 |
return toolBar;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Obtenemos el alto de cualquier toolbar que este visible en gvSIG y no sea
|
97 |
* nuestro para poder asignarselo al GenericToolBar como PreferredSize. En
|
98 |
* caso de no encontrar ninguno que cumpla las condiciones, se devolver? 24
|
99 |
* @return
|
100 |
*/
|
101 |
private int getToolbarHeight() { |
102 |
if ((PluginServices.getMainFrame() == null) || |
103 |
(PluginServices.getMainFrame().getToolbars() == null) ||
|
104 |
(PluginServices.getMainFrame().getToolbars().length <= 0))
|
105 |
return 24; |
106 |
|
107 |
for (int i = 0; i < PluginServices.getMainFrame().getToolbars().length; i++) { |
108 |
if ((PluginServices.getMainFrame().getToolbars()[i].getHeight() > 16) && |
109 |
((Object) PluginServices.getMainFrame().getToolbars()[i] != (Object) toolBar)) |
110 |
return PluginServices.getMainFrame().getToolbars()[i].getHeight();
|
111 |
} |
112 |
return 24; |
113 |
} |
114 |
|
115 |
/*
|
116 |
* (non-Javadoc)
|
117 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
118 |
*/
|
119 |
public void initialize() { |
120 |
registerIcons(); |
121 |
|
122 |
// Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
|
123 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
124 |
ExtensionPoint point = extensionPoints.add("GenericToolBarGroup");
|
125 |
point.setDescription("Punto de extension para los grupos de menus del GenericToolBarPanel");
|
126 |
|
127 |
point.append("RasterLayer", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "capa_raster"), PluginServices.getIconTheme().get("layer-icon"))); |
128 |
point.append("RasterProcess", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "process_raster"), PluginServices.getIconTheme().get("process-icon"))); |
129 |
point.append("GeoRaster", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "transformaciones_geograficas"), PluginServices.getIconTheme().get("transgeo-icon"))); |
130 |
point.append("RasterExport", "", new GenericToolBarMenuItem(RasterToolsUtil.getText(this, "raster_export"), PluginServices.getIconTheme().get("raster-export"))); |
131 |
|
132 |
point = extensionPoints.add("GenericToolBarMenu");
|
133 |
point.setDescription("Punto de extension para los submenus del GenericToolBarPanel");
|
134 |
point.append("RasterProperties", "", RasterPropertiesTocMenuEntry.getSingleton()); |
135 |
point.append("SelectLayer", "", SelectLayerTocMenuEntry.getSingleton()); |
136 |
point.append("HistogramPanel", "", HistogramTocMenuEntry.getSingleton()); |
137 |
point.append("ViewColorTable", "",ColorTableTocMenuEntry.getSingleton()); |
138 |
point.append("Overviews", "", OverviewsTocMenuEntry.getSingleton()); |
139 |
point.append("RoisManager", "", ROIManagerTocMenuEntry.getSingleton()); |
140 |
point.append("ViewRasterAnalysis", "", ViewRasterAnalysisTocMenuEntry.getSingleton()); |
141 |
|
142 |
point.append("SaveAs", "", SaveAsTocMenuEntry.getSingleton()); |
143 |
point.append("ClippingPanel", "", ClippingTocMenuEntry.getSingleton()); |
144 |
point.append("SaveRaster", "", SaveRasterTocMenuEntry.getSingleton()); |
145 |
|
146 |
point.append("FilterPanel", "", FilterTocMenuEntry.getSingleton()); |
147 |
point.append("EnhancedPanel", "", EnhancedTocMenuEntry.getSingleton()); |
148 |
point.append("GeoLocation", "", GeoLocationTocMenuEntry.getSingleton()); |
149 |
point.append("InfoByPoint", "", InfoByRasterPointTocMenuEntry.getSingleton()); |
150 |
//point.append("Vectorization", "", VectorizationTocMenuEntry.getSingleton());
|
151 |
ReprojectTocMenuEntry menuEntry = ReprojectTocMenuEntry.getSingleton(); |
152 |
point.append(menuEntry.getText(), "", menuEntry);
|
153 |
|
154 |
if (getGenericToolBarPanel() != null) |
155 |
getGenericToolBarPanel().reloadMenuGroup(); |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Registra los iconos a utilizar en la botonera.
|
160 |
*/
|
161 |
private void registerIcons() { |
162 |
PluginServices.getIconTheme().register( |
163 |
"layer-icon",
|
164 |
this.getClass().getClassLoader().getResource("images/rasterlayer.png") |
165 |
); |
166 |
PluginServices.getIconTheme().register( |
167 |
"process-icon",
|
168 |
this.getClass().getClassLoader().getResource("images/icon_process.gif") |
169 |
); |
170 |
PluginServices.getIconTheme().register( |
171 |
"transgeo-icon",
|
172 |
this.getClass().getClassLoader().getResource("images/rastertransgeo.gif") |
173 |
); |
174 |
PluginServices.getIconTheme().registerDefault( |
175 |
"raster-export",
|
176 |
this.getClass().getClassLoader().getResource("images/raster-export.png") |
177 |
); |
178 |
} |
179 |
|
180 |
/*
|
181 |
* (non-Javadoc)
|
182 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
183 |
*/
|
184 |
public boolean isEnabled() { |
185 |
return false; |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Establece si la barra de herramientas esta visible
|
190 |
* @param enabled
|
191 |
*/
|
192 |
private void setToolBarVisible(boolean enabled) { |
193 |
if (getGenericToolBarPanel() == null) |
194 |
return;
|
195 |
|
196 |
toolBar.setVisible(enabled); |
197 |
} |
198 |
|
199 |
/*
|
200 |
* (non-Javadoc)
|
201 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
202 |
*/
|
203 |
@SuppressWarnings("deprecation") |
204 |
public boolean isVisible() { |
205 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
206 |
if (f == null || !(f instanceof AbstractViewPanel)) { |
207 |
setToolBarVisible(false);
|
208 |
return false; |
209 |
} |
210 |
|
211 |
if (getGenericToolBarPanel() != null) |
212 |
getGenericToolBarPanel().setLayers(null);
|
213 |
AbstractViewPanel vista = (AbstractViewPanel) f; |
214 |
ViewDocument model = vista.getModel(); |
215 |
MapContext mapa = model.getMapContext(); |
216 |
if (mapa.getLayers().getLayersCount() > 0) { |
217 |
if (getGenericToolBarPanel() != null) { |
218 |
getGenericToolBarPanel().setLayers(mapa.getLayers()); |
219 |
} |
220 |
} |
221 |
|
222 |
setToolBarVisible(true);
|
223 |
return true; |
224 |
|
225 |
/*if (f instanceof AbstractViewPanel) {
|
226 |
AbstractViewPanel vista = (AbstractViewPanel) f;
|
227 |
ViewDocument model = vista.getModel();
|
228 |
MapContext mapa = model.getMapContext();
|
229 |
if (mapa.getLayers().getLayersCount() > 0) {
|
230 |
setToolBarVisible(true);
|
231 |
if (getGenericToolBarPanel() != null) {
|
232 |
getGenericToolBarPanel().setLayers(mapa.getLayers());
|
233 |
}
|
234 |
return true;
|
235 |
}
|
236 |
}
|
237 |
|
238 |
setToolBarVisible(false);
|
239 |
return false;*/
|
240 |
} |
241 |
|
242 |
public void execute(String actionCommand) {} |
243 |
} |