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