svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / GridCalculatorExtension.java @ 26348
History | View | Annotate | Download (6.1 KB)
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ibez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
package org.gvsig.remotesensing; |
41 |
|
42 |
import javax.swing.Icon; |
43 |
|
44 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
45 |
import org.gvsig.fmap.raster.layers.ILayerState; |
46 |
import org.gvsig.raster.gui.IGenericToolBarMenuItem; |
47 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
48 |
import org.gvsig.remotesensing.gridmath.gui.GridMathDialog; |
49 |
|
50 |
import com.iver.andami.PluginServices; |
51 |
import com.iver.andami.plugins.Extension; |
52 |
import com.iver.cit.gvsig.fmap.MapContext; |
53 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
55 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
56 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
57 |
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
58 |
/**
|
59 |
* Extensi?n para el C?lculo de Raster (Band Math)
|
60 |
*
|
61 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
62 |
*/
|
63 |
public class GridCalculatorExtension extends Extension implements IGenericToolBarMenuItem { |
64 |
|
65 |
/*
|
66 |
* (non-Javadoc)
|
67 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
68 |
*/
|
69 |
public void initialize() { |
70 |
ExtensionPoint extensionPoint = ExtensionPoint.getExtensionPoint("GenericToolBarMenu");
|
71 |
extensionPoint.register("GridCalculator", this); |
72 |
|
73 |
PluginServices.getIconTheme().register( |
74 |
"calculator-icon",
|
75 |
this.getClass().getClassLoader().getResource("images/calculator.png") |
76 |
); |
77 |
} |
78 |
|
79 |
/*
|
80 |
* (non-Javadoc)
|
81 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
82 |
*/
|
83 |
public void execute(String actionCommand) { |
84 |
if (actionCommand.equals("band_math")) { |
85 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
86 |
|
87 |
// si la ventana activa es de tipo Vista
|
88 |
if (activeWindow instanceof View) { |
89 |
GridMathDialog calculatorDialog = new GridMathDialog((View) activeWindow); |
90 |
// Mostrar la calculadora.
|
91 |
PluginServices.getMDIManager().addWindow(calculatorDialog); |
92 |
} |
93 |
} |
94 |
} |
95 |
|
96 |
/*
|
97 |
* (non-Javadoc)
|
98 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
99 |
*/
|
100 |
public boolean isEnabled() { |
101 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
102 |
if (f == null) { |
103 |
return false; |
104 |
} |
105 |
if (f.getClass() == View.class) { |
106 |
View vista = (View) f; |
107 |
IProjectView model = vista.getModel(); |
108 |
MapContext mapa = model.getMapContext(); |
109 |
FLayers layers = mapa.getLayers(); |
110 |
for (int i = 0; i < layers.getLayersCount(); i++) |
111 |
if (layers.getLayer(i) instanceof FLyrRasterSE) |
112 |
return true; |
113 |
} |
114 |
return false; |
115 |
} |
116 |
|
117 |
/*
|
118 |
* (non-Javadoc)
|
119 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
120 |
*/
|
121 |
public boolean isVisible() { |
122 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
123 |
if (f == null) { |
124 |
return false; |
125 |
} |
126 |
if (f instanceof View) { |
127 |
View vista = (View) f; |
128 |
IProjectView model = vista.getModel(); |
129 |
MapContext mapa = model.getMapContext(); |
130 |
return mapa.getLayers().getLayersCount() > 0; |
131 |
} else {
|
132 |
return false; |
133 |
} |
134 |
} |
135 |
|
136 |
/*
|
137 |
* (non-Javadoc)
|
138 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
139 |
*/
|
140 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
141 |
this.execute("band_math"); |
142 |
} |
143 |
|
144 |
/*
|
145 |
* (non-Javadoc)
|
146 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getGroup()
|
147 |
*/
|
148 |
public String getGroup() { |
149 |
return "RasterProcess"; |
150 |
} |
151 |
|
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getIcon()
|
155 |
*/
|
156 |
public Icon getIcon() { |
157 |
return PluginServices.getIconTheme().get("calculator-icon"); |
158 |
} |
159 |
|
160 |
/*
|
161 |
* (non-Javadoc)
|
162 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getOrder()
|
163 |
*/
|
164 |
public int getOrder() { |
165 |
return 0; |
166 |
} |
167 |
|
168 |
/*
|
169 |
* (non-Javadoc)
|
170 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getText()
|
171 |
*/
|
172 |
public String getText() { |
173 |
return PluginServices.getText(this, "band_math_tooltip"); |
174 |
} |
175 |
|
176 |
/*
|
177 |
* (non-Javadoc)
|
178 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
179 |
*/
|
180 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
181 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
182 |
return false; |
183 |
|
184 |
if (!(selectedItems[0] instanceof ILayerState)) |
185 |
return false; |
186 |
|
187 |
if (!((ILayerState) selectedItems[0]).isOpen()) |
188 |
return false; |
189 |
|
190 |
return true; |
191 |
} |
192 |
|
193 |
/*
|
194 |
* (non-Javadoc)
|
195 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
196 |
*/
|
197 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
198 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
199 |
return false; |
200 |
|
201 |
if (!(selectedItems[0] instanceof FLyrRasterSE)) |
202 |
return false; |
203 |
|
204 |
return true; |
205 |
} |
206 |
|
207 |
/*
|
208 |
* (non-Javadoc)
|
209 |
* @see org.gvsig.raster.gui.IGenericToolBarMenuItem#getGroupOrder()
|
210 |
*/
|
211 |
public int getGroupOrder() { |
212 |
return 0; |
213 |
} |
214 |
} |