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