gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.mainplugin / src / main / java / org / gvsig / raster / mainplugin / GenericToolBarModule.java @ 2118
History | View | Annotate | Download (7.01 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.mainplugin; |
23 |
|
24 |
import java.awt.Dimension; |
25 |
|
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.andami.ui.mdiFrame.MDIFrame; |
30 |
import org.gvsig.app.project.documents.view.ViewDocument; |
31 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
32 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
33 |
import org.gvsig.fmap.mapcontext.MapContext; |
34 |
import org.gvsig.i18n.Messages; |
35 |
import org.gvsig.raster.mainplugin.toolbar.GenericToolBarMenuItem; |
36 |
import org.gvsig.raster.mainplugin.toolbar.GenericToolBarPanel; |
37 |
import org.gvsig.tools.ToolsLocator; |
38 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
39 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
40 |
|
41 |
/**
|
42 |
* Extension para la barra de herramientas generica
|
43 |
*
|
44 |
* @version 13/02/2008
|
45 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
46 |
*/
|
47 |
public class GenericToolBarModule extends Extension { |
48 |
private GenericToolBarPanel toolBar = null; |
49 |
|
50 |
/**
|
51 |
* Crea y devuelve la barra de herramientas
|
52 |
* @return
|
53 |
*/
|
54 |
private GenericToolBarPanel getGenericToolBarPanel() {
|
55 |
if (toolBar == null) { |
56 |
MDIFrame f = (MDIFrame) PluginServices.getMainFrame(); |
57 |
if (f == null) |
58 |
return null; |
59 |
toolBar = new GenericToolBarPanel();
|
60 |
toolBar.setVisible(false);
|
61 |
f.addToolBarControl(getClass(), toolBar, "RasterToolBar");
|
62 |
} else {
|
63 |
toolBar.setPreferredSize(new Dimension(300, getToolbarHeight())); |
64 |
} |
65 |
|
66 |
return toolBar;
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* Obtenemos el alto de cualquier toolbar que este visible en gvSIG y no sea
|
71 |
* nuestro para poder asignarselo al GenericToolBar como PreferredSize. En
|
72 |
* caso de no encontrar ninguno que cumpla las condiciones, se devolver? 24
|
73 |
* @return
|
74 |
*/
|
75 |
private int getToolbarHeight() { |
76 |
if ((PluginServices.getMainFrame() == null) || |
77 |
(PluginServices.getMainFrame().getToolbars() == null) ||
|
78 |
(PluginServices.getMainFrame().getToolbars().length <= 0))
|
79 |
return 24; |
80 |
|
81 |
for (int i = 0; i < PluginServices.getMainFrame().getToolbars().length; i++) { |
82 |
if ((PluginServices.getMainFrame().getToolbars()[i].getHeight() > 16) && |
83 |
((Object) PluginServices.getMainFrame().getToolbars()[i] != (Object) toolBar)) |
84 |
return PluginServices.getMainFrame().getToolbars()[i].getHeight();
|
85 |
} |
86 |
return 24; |
87 |
} |
88 |
|
89 |
/*
|
90 |
* (non-Javadoc)
|
91 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
92 |
*/
|
93 |
public void initialize() { |
94 |
registerIcons(); |
95 |
|
96 |
// Creaci?n del punto de extensi?n para registrar paneles en el cuadro de propiedades.
|
97 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
98 |
ExtensionPoint point = extensionPoints.add("GenericToolBarGroup");
|
99 |
point.setDescription("Punto de extension para los grupos de menus del GenericToolBarPanel");
|
100 |
|
101 |
point.append("RasterLayer", "", new GenericToolBarMenuItem(Messages.getText("capa_raster"), IconThemeHelper.getImageIcon("menu-layer-icon"))); |
102 |
point.append("RasterProcess", "", new GenericToolBarMenuItem(Messages.getText("process_raster"), IconThemeHelper.getImageIcon("menu-process-icon"))); |
103 |
point.append("Multispectral", "", new GenericToolBarMenuItem(Messages.getText("multispectral"), IconThemeHelper.getImageIcon("menu-multispectral-icon"))); |
104 |
point.append("Enhanced", "", new GenericToolBarMenuItem(Messages.getText("enhanced"), IconThemeHelper.getImageIcon("menu-enhanced-icon"))); |
105 |
point.append("GeoRaster", "", new GenericToolBarMenuItem(Messages.getText("transformaciones_geograficas"), IconThemeHelper.getImageIcon("menu-transgeo-icon"))); |
106 |
point.append("RasterExport", "", new GenericToolBarMenuItem(Messages.getText("raster_export"), IconThemeHelper.getImageIcon("menu-raster-export"))); |
107 |
|
108 |
point = extensionPoints.add("GenericToolBarMenu");
|
109 |
point.setDescription("Punto de extension para los submenus del GenericToolBarPanel");
|
110 |
} |
111 |
|
112 |
private void registerIcons() { |
113 |
//Actions
|
114 |
IconThemeHelper.registerIcon("action", "menu-layer-icon", this); |
115 |
IconThemeHelper.registerIcon("action", "menu-process-icon", this); |
116 |
IconThemeHelper.registerIcon("action", "menu-transgeo-icon", this); |
117 |
IconThemeHelper.registerIcon("action", "menu-raster-export", this); |
118 |
IconThemeHelper.registerIcon("action", "menu-multispectral-icon", this); |
119 |
IconThemeHelper.registerIcon("action", "menu-enhanced-icon", this); |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public void postInitialize() { |
124 |
super.postInitialize();
|
125 |
if (getGenericToolBarPanel() != null) |
126 |
getGenericToolBarPanel().reloadMenuGroup(); |
127 |
} |
128 |
|
129 |
/*
|
130 |
* (non-Javadoc)
|
131 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
132 |
*/
|
133 |
public boolean isEnabled() { |
134 |
return false; |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Establece si la barra de herramientas esta visible
|
139 |
* @param enabled
|
140 |
*/
|
141 |
private void setToolBarVisible(boolean enabled) { |
142 |
if (getGenericToolBarPanel() == null) |
143 |
return;
|
144 |
|
145 |
toolBar.setVisible(enabled); |
146 |
} |
147 |
|
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
151 |
*/
|
152 |
@SuppressWarnings("deprecation") |
153 |
public boolean isVisible() { |
154 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
155 |
if (f == null || !(f instanceof AbstractViewPanel)) { |
156 |
setToolBarVisible(false);
|
157 |
return false; |
158 |
} |
159 |
|
160 |
if (getGenericToolBarPanel() != null) |
161 |
getGenericToolBarPanel().setLayers(null);
|
162 |
AbstractViewPanel vista = (AbstractViewPanel) f; |
163 |
ViewDocument model = vista.getModel(); |
164 |
MapContext mapa = model.getMapContext(); |
165 |
if (mapa.getLayers().getLayersCount() > 0) { |
166 |
if (getGenericToolBarPanel() != null) { |
167 |
getGenericToolBarPanel().setLayers(mapa.getLayers()); |
168 |
} |
169 |
} |
170 |
|
171 |
setToolBarVisible(true);
|
172 |
return true; |
173 |
|
174 |
/*if (f instanceof AbstractViewPanel) {
|
175 |
AbstractViewPanel vista = (AbstractViewPanel) f;
|
176 |
ViewDocument model = vista.getModel();
|
177 |
MapContext mapa = model.getMapContext();
|
178 |
if (mapa.getLayers().getLayersCount() > 0) {
|
179 |
setToolBarVisible(true);
|
180 |
if (getGenericToolBarPanel() != null) {
|
181 |
getGenericToolBarPanel().setLayers(mapa.getLayers());
|
182 |
}
|
183 |
return true;
|
184 |
}
|
185 |
}
|
186 |
|
187 |
setToolBarVisible(false);
|
188 |
return false;*/
|
189 |
} |
190 |
|
191 |
public void execute(String actionCommand) {} |
192 |
} |