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