Revision 3556
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/buildNumber.properties | ||
---|---|---|
1 |
#Thu Jul 02 02:58:30 CEST 2015 |
|
2 |
buildNumber=60 |
|
0 | 3 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
|
|
26 |
<dependencySets> |
|
27 |
<dependencySet> |
|
28 |
<useProjectArtifact>false</useProjectArtifact> |
|
29 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
30 |
<outputDirectory>lib</outputDirectory> |
|
31 |
<includes> |
|
32 |
<include>org.gvsig:org.gvsig.raster.tools.app.basic:jar</include> |
|
33 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.layerdatatype:jar</include> |
|
34 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.saveraster:jar</include> |
|
35 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.api:jar</include> |
|
36 |
<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.impl:jar</include> |
|
37 |
<include>org.gvsig:org.gvsig.raster.tools.toolbox.algorithm:jar</include> |
|
38 |
</includes> |
|
39 |
</dependencySet> |
|
40 |
</dependencySets> |
|
41 |
</assembly> |
|
0 | 42 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/RasterToolsUtil.java | ||
---|---|---|
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.tools.app.basic; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
import java.awt.Dimension; |
|
26 |
import java.awt.Point; |
|
27 |
import java.io.File; |
|
28 |
import java.util.ArrayList; |
|
29 |
|
|
30 |
import javax.swing.ImageIcon; |
|
31 |
import javax.swing.JOptionPane; |
|
32 |
|
|
33 |
import org.gvsig.andami.IconThemeHelper; |
|
34 |
import org.gvsig.andami.PluginServices; |
|
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
36 |
import org.gvsig.app.project.Project; |
|
37 |
import org.gvsig.app.project.ProjectManager; |
|
38 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
|
39 |
import org.gvsig.fmap.dal.DALLocator; |
|
40 |
import org.gvsig.fmap.dal.DataManager; |
|
41 |
import org.gvsig.fmap.dal.DataStore; |
|
42 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
43 |
import org.gvsig.fmap.dal.coverage.datastruct.Param; |
|
44 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
|
45 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
46 |
import org.gvsig.fmap.dal.coverage.util.ProviderServices; |
|
47 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
48 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
49 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
50 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
51 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
52 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
53 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
54 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
55 |
import org.gvsig.gui.beans.propertiespanel.PropertiesComponent; |
|
56 |
import org.gvsig.gui.beans.propertiespanel.PropertyStruct; |
|
57 |
import org.gvsig.i18n.Messages; |
|
58 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
|
59 |
import org.gvsig.raster.util.RasterNotLoadException; |
|
60 |
|
|
61 |
/** |
|
62 |
* Herramientas de uso general y que son dependientes de gvSIG, FMap o de |
|
63 |
* libUIComponents. En caso de no serlo existe una clase independiente de |
|
64 |
* cualquier proyecto dentro de libRaster para este tipo de funciones. |
|
65 |
* |
|
66 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
67 |
*/ |
|
68 |
public class RasterToolsUtil { |
|
69 |
|
|
70 |
/** |
|
71 |
* Obtiene la lista de capas del TOC y devuelve las raster. Si hay capas agrupadas lo tiene en cuenta y mira |
|
72 |
* dentro de la agrupaci?n. |
|
73 |
* @param srcLyrs FLayers de la vista |
|
74 |
* @param destLyrs Lista de capas |
|
75 |
* @return ArrayList con la lista de capas raster agrupadas o no. El orden en que aparecen |
|
76 |
* en la lista es de abajo a arriba las que aparecen en el TOC. |
|
77 |
*/ |
|
78 |
public static ArrayList<FLayer> getRasterLayerList(FLayers srcLyrs, ArrayList<FLayer> destLyrs) { |
|
79 |
if(destLyrs == null) |
|
80 |
destLyrs = new ArrayList<FLayer>(); |
|
81 |
for (int i = 0; i < srcLyrs.getLayersCount(); i++) { |
|
82 |
if(srcLyrs.getLayer(i) instanceof DefaultFLyrRaster) |
|
83 |
destLyrs.add(srcLyrs.getLayer(i)); |
|
84 |
if(srcLyrs.getLayer(i) instanceof FLayers) |
|
85 |
destLyrs = getLayerList((FLayers)srcLyrs.getLayer(i), destLyrs); |
|
86 |
} |
|
87 |
return destLyrs; |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Obtiene la lista de capas del TOC y devuelve las raster. Si hay capas agrupadas lo tiene en cuenta y mira |
|
92 |
* dentro de la agrupaci?n. |
|
93 |
* @param srcLyrs FLayers de la vista |
|
94 |
* @param destLyrs Lista de capas |
|
95 |
* @return ArrayList con la lista de capas raster agrupadas o no. El orden en que aparecen |
|
96 |
* en la lista es de abajo a arriba las que aparecen en el TOC. |
|
97 |
*/ |
|
98 |
public static ArrayList<FLayer> getLayerList(FLayers srcLyrs, ArrayList<FLayer> destLyrs) { |
|
99 |
if(srcLyrs == null) |
|
100 |
return null; |
|
101 |
if(destLyrs == null) |
|
102 |
destLyrs = new ArrayList<FLayer>(); |
|
103 |
for (int i = 0; i < srcLyrs.getLayersCount(); i++) { |
|
104 |
if(srcLyrs.getLayer(i) instanceof FLayers) |
|
105 |
destLyrs = getLayerList((FLayers)srcLyrs.getLayer(i), destLyrs); |
|
106 |
else |
|
107 |
destLyrs.add(srcLyrs.getLayer(i)); |
|
108 |
} |
|
109 |
return destLyrs; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Obtiene el nombre de la vista donde est? cargada la capa que se pasa por par?metro |
|
114 |
* @param layer Capa cargada en una vista |
|
115 |
* @return Nombre de la vista donde est? cargada la capa. |
|
116 |
*/ |
|
117 |
public static String getView(FLayer layer) { |
|
118 |
// Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject(); |
|
119 |
Project p = ProjectManager.getInstance().getCurrentProject(); |
|
120 |
return p.getViewName(layer); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Devuelve la traducci?n de un texto. En caso de no existir la traducci?n al idioma seleccionado |
|
125 |
* devolver? la cadena de entrada. |
|
126 |
* @param parent Ventana padre que contiene el objeto con la traducci?n |
|
127 |
* @param text Texto a traducir |
|
128 |
* @return Texto traducido o cadena de entrada en caso de no encontrar una traducci?n |
|
129 |
*/ |
|
130 |
public static String getText(Object parent, String text) { |
|
131 |
return PluginServices.getText(parent, text); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Obtiene un icono definido por la etiqueta que se especifica en el |
|
136 |
* par?metro |
|
137 |
* @param ico Etiqueta del icono |
|
138 |
* @return Icono |
|
139 |
*/ |
|
140 |
public static ImageIcon getIcon(String ico) { |
|
141 |
return IconThemeHelper.getImageIcon(ico); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* A?ade una ventana al gestor de ventanas |
|
146 |
* @param window |
|
147 |
*/ |
|
148 |
public static void addWindow(IWindow window) { |
|
149 |
PluginServices.getMDIManager().addWindow(window); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Elimina una ventana al gestor de ventanas |
|
154 |
* @param window |
|
155 |
*/ |
|
156 |
public static void closeWindow(IWindow window) { |
|
157 |
PluginServices.getMDIManager().closeWindow(window); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Selecciona los controles del panel de propiedades a partir de los par?mtros |
|
162 |
* obtenidos del driver. Este m?todo realiza una transformaci?n entre Params |
|
163 |
* obtenido del driver de escritura y los par?metros del panel de propiedades. |
|
164 |
* @param panel Panel de propiedades |
|
165 |
* @param params Par?metros del driver |
|
166 |
* @param notTakeIntoAccount Nombre de par?metros que no hay que tener en cuenta. Si es null se tienen en cuenta todos. |
|
167 |
*/ |
|
168 |
public static void loadPropertiesFromWriterParams(PropertiesComponent pComp, Params params, String[] notTakeIntoAccount) { |
|
169 |
for (int i = 0; i < params.getNumParams(); i++) { |
|
170 |
Param p = params.getParam(i); |
|
171 |
String name = getText(null, p.getId()); |
|
172 |
String key = p.getId(); |
|
173 |
|
|
174 |
//Miramos si el par?metro coincide con alguno en la lista de parametros que no hay que |
|
175 |
//tener en cuenta. Si es as? no lo a?adimos |
|
176 |
if(notTakeIntoAccount != null && notTakeIntoAccount.length > 0) { |
|
177 |
boolean jump = false; |
|
178 |
for (int j = 0; j < notTakeIntoAccount.length; j++) { |
|
179 |
if (key.equals(notTakeIntoAccount[j])) |
|
180 |
jump = true; |
|
181 |
} |
|
182 |
if(jump) |
|
183 |
continue; |
|
184 |
} |
|
185 |
|
|
186 |
Object[] types = null; |
|
187 |
int selectedValue = 0; |
|
188 |
|
|
189 |
switch (p.getType()) { |
|
190 |
case Params.CHECK: |
|
191 |
pComp.addValue(name, key, p.getDefaultValue(), types); |
|
192 |
break; |
|
193 |
case Params.CHOICE: |
|
194 |
ArrayList<String> list = new ArrayList<String>(); |
|
195 |
for (int j = 0; j < p.getList().length; j++) { |
|
196 |
list.add(p.getList()[j]); |
|
197 |
if (p.getDefaultValue() instanceof Integer) |
|
198 |
if (((Integer) p.getDefaultValue()).intValue() == j) |
|
199 |
selectedValue = j; |
|
200 |
} |
|
201 |
types = new Object[] { new Integer(PropertiesComponent.TYPE_COMBO), list }; |
|
202 |
pComp.addValue(name, key, new Integer(selectedValue), types); |
|
203 |
break; |
|
204 |
case Params.SLIDER: |
|
205 |
types = new Object[] { new Integer(PropertiesComponent.TYPE_SLIDER), new Integer(p.getList()[0]), new Integer(p.getList()[1]) }; |
|
206 |
pComp.addValue(name, key, p.getDefaultValue(), types); |
|
207 |
break; |
|
208 |
default: |
|
209 |
pComp.addValue(getText(null, ((Param)params.getParam(i)).getId()), params.getParam(i).getId(), params.getParam(i).getDefaultValue(), null); |
|
210 |
break; |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* Carga los par?metros del escritor WriterParams con los valores obtenidos |
|
217 |
* de la ventana de propiedades. |
|
218 |
*/ |
|
219 |
@SuppressWarnings("unchecked") |
|
220 |
public static void loadWriterParamsFromPropertiesPanel(PropertiesComponent pComp, Params params) { |
|
221 |
ArrayList<PropertyStruct> values = pComp.getValues(); |
|
222 |
for (int iParam = 0; iParam < params.getNumParams(); iParam++) { |
|
223 |
Param p = params.getParam(iParam); |
|
224 |
for (int iValue = 0; iValue < values.size(); iValue++) { |
|
225 |
PropertyStruct prop = values.get(iValue); |
|
226 |
if (p.getId().compareTo(prop.getKey()) == 0) { |
|
227 |
switch (p.getType()) { |
|
228 |
case Params.CHECK: |
|
229 |
p.setDefaultValue((Boolean) prop.getNewValue()); |
|
230 |
break; |
|
231 |
case Params.CHOICE: |
|
232 |
p.setDefaultValue(((Integer) prop.getNewValue()));//p.list[((Integer) prop.getNewValue()).intValue()]; |
|
233 |
break; |
|
234 |
case Params.SLIDER: |
|
235 |
try { |
|
236 |
p.setDefaultValue((Integer)prop.getNewValue()); |
|
237 |
} catch (NumberFormatException e) {} |
|
238 |
} |
|
239 |
break; |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* Funci?n que devuelve true si se tiene permiso de escritura en la ruta |
|
247 |
* indicada en el par?metro path y false si no los tiene. |
|
248 |
* @param path Ruta a comprobar los permisosv |
|
249 |
* @param pluginObject si es distinto de null se obtiene un mensaje de |
|
250 |
* advertencia y sirve como par?metro para getText de la traducci?n. |
|
251 |
* Si es null no se mostrar? ventana de advertencia |
|
252 |
* @return true si se tiene permiso de escritura en la ruta indicada en el |
|
253 |
* par?metro path y false si no los tiene. |
|
254 |
*/ |
|
255 |
public static boolean canWrite(String path) { |
|
256 |
File f = new File(path); |
|
257 |
if(f.exists() && f.canWrite()) |
|
258 |
return true; |
|
259 |
else { |
|
260 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
|
261 |
Messages.getText("error_writing_raster_file")); |
|
262 |
return false; |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* Carga una capa raster en una vista de gvSIG. |
|
268 |
* @param viewName Nombre de la vista donde ha de cargarse. Si vale null se cargar? en la |
|
269 |
* primera vista que encuentre que est? activa. Si no hay ninguna saltar? una excepci?n. |
|
270 |
* @param fileName Nombre del fichero a cargar. No debe ser nulo nunca. |
|
271 |
* @param layerName Nombre de la capa. Si es null se asignar? el nombre del |
|
272 |
* fichero sin extensi?n. |
|
273 |
* @throws RasterNotLoadException Excepci?n que se lanza cuando no se ha podido cargar la capa |
|
274 |
* por alg?n motivo. |
|
275 |
*/ |
|
276 |
@SuppressWarnings("deprecation") |
|
277 |
public static FLayer loadLayer(String viewName, String fileName, String layerName) throws RasterNotLoadException { |
|
278 |
if(fileName == null) |
|
279 |
return null; |
|
280 |
|
|
281 |
//Seleccionamos la vista de gvSIG |
|
282 |
AbstractViewPanel theView = null; |
|
283 |
try { |
|
284 |
IWindow[] allViews = PluginServices.getMDIManager().getAllWindows(); |
|
285 |
if(viewName != null) { |
|
286 |
for (int i = 0; i < allViews.length; i++) { |
|
287 |
if (allViews[i] instanceof AbstractViewPanel |
|
288 |
&& (((AbstractViewPanel) allViews[i]).getDocument().getName().equals(viewName) || |
|
289 |
PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) allViews[i]).getTitle().equals(viewName))) |
|
290 |
theView = (AbstractViewPanel) allViews[i]; |
|
291 |
} |
|
292 |
} else { |
|
293 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
|
294 |
for (int i = 0; i < allViews.length; i++) { |
|
295 |
if (allViews[i] instanceof AbstractViewPanel && ((AbstractViewPanel)allViews[i]) == activeWindow) //En la primera vista activa |
|
296 |
theView = (AbstractViewPanel) allViews[i]; |
|
297 |
} |
|
298 |
if(theView == null) { |
|
299 |
for (int i = 0; i < allViews.length; i++) { |
|
300 |
if (allViews[i] instanceof AbstractViewPanel) //En la primera vista |
|
301 |
theView = (AbstractViewPanel) allViews[i]; |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
|
|
306 |
if (theView == null) |
|
307 |
throw new RasterNotLoadException("Imposible cargar la capa."); |
|
308 |
} catch (ClassCastException ex) { |
|
309 |
throw new RasterNotLoadException("No se puede hacer un casting de esa IWindow a View."); |
|
310 |
} |
|
311 |
|
|
312 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
|
313 |
|
|
314 |
DefaultFLyrRaster lyr = null; |
|
315 |
try { |
|
316 |
ProviderServices provServ = RasterLocator.getManager().getProviderServices(); |
|
317 |
RasterDataParameters storeParameters = provServ.createNotTiledParameters(fileName); |
|
318 |
storeParameters.setSRS(theView.getProjection()); |
|
319 |
|
|
320 |
MapContextManager mcm = MapContextLocator.getMapContextManager(); |
|
321 |
DataManager dataManager = DALLocator.getDataManager(); |
|
322 |
DataStore dataStore = null; |
|
323 |
try { |
|
324 |
dataStore = dataManager.createStore(storeParameters); |
|
325 |
} catch (ValidateDataParametersException e) { |
|
326 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
327 |
} catch (InitializeException e) { |
|
328 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
329 |
} catch (ProviderNotRegisteredException e) { |
|
330 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
331 |
} |
|
332 |
|
|
333 |
lyr = new DefaultFLyrRaster(); |
|
334 |
|
|
335 |
if(layerName == null) { |
|
336 |
int endIndex = fileName.lastIndexOf("."); |
|
337 |
if (endIndex < 0) |
|
338 |
endIndex = fileName.length(); |
|
339 |
|
|
340 |
layerName = fileName.substring(fileName.lastIndexOf(File.separator) + 1, endIndex); |
|
341 |
} |
|
342 |
|
|
343 |
lyr = (DefaultFLyrRaster) mcm.createLayer(layerName, dataStore); |
|
344 |
|
|
345 |
} catch (LoadLayerException e) { |
|
346 |
throw new RasterNotLoadException("Error al cargar la capa."); |
|
347 |
} catch (InitializeException e) { |
|
348 |
throw new RasterNotLoadException("Error creating parameters."); |
|
349 |
} catch (ProviderNotRegisteredException e) { |
|
350 |
throw new RasterNotLoadException("Error creating parameters."); |
|
351 |
} |
|
352 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
|
353 |
theView.getMapControl().getMapContext().invalidate(); |
|
354 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
|
355 |
return lyr; |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* Carga una capa raster en una vista de gvSIG. |
|
360 |
* @param viewName Nombre de la vista donde ha de cargarse. Si vale null se cargar? en la |
|
361 |
* primera vista que encuentre que est? activa. Si no hay ninguna saltar? una excepci?n. |
|
362 |
* @param fileName Nombre del fichero a cargar. No debe ser nulo nunca. |
|
363 |
* @param layerName Nombre de la capa. Si es null se asignar? el nombre del |
|
364 |
* fichero sin extensi?n. |
|
365 |
* @throws RasterNotLoadException Excepci?n que se lanza cuando no se ha podido cargar la capa |
|
366 |
* por alg?n motivo. |
|
367 |
*/ |
|
368 |
public static FLayer loadLayer(String viewName, FLayer lyr) throws RasterNotLoadException { |
|
369 |
if(lyr == null) |
|
370 |
return null; |
|
371 |
|
|
372 |
//Seleccionamos la vista de gvSIG |
|
373 |
AbstractViewPanel theView = null; |
|
374 |
try { |
|
375 |
IWindow[] allViews = PluginServices.getMDIManager().getAllWindows(); |
|
376 |
if(viewName != null) { |
|
377 |
for (int i = 0; i < allViews.length; i++) { |
|
378 |
if (allViews[i] instanceof AbstractViewPanel |
|
379 |
&& PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) allViews[i]).getTitle().equals(viewName)) |
|
380 |
theView = (AbstractViewPanel) allViews[i]; |
|
381 |
} |
|
382 |
} else { |
|
383 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
|
384 |
for (int i = 0; i < allViews.length; i++) { |
|
385 |
if (allViews[i] instanceof AbstractViewPanel && ((AbstractViewPanel)allViews[i]) == activeWindow) //En la primera vista activa |
|
386 |
theView = (AbstractViewPanel) allViews[i]; |
|
387 |
} |
|
388 |
if(theView == null) { |
|
389 |
for (int i = 0; i < allViews.length; i++) { |
|
390 |
if (allViews[i] instanceof AbstractViewPanel) //En la primera vista |
|
391 |
theView = (AbstractViewPanel) allViews[i]; |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
|
|
396 |
if (theView == null) |
|
397 |
throw new RasterNotLoadException("Imposible cargar la capa."); |
|
398 |
} catch (ClassCastException ex) { |
|
399 |
throw new RasterNotLoadException("No se puede hacer un casting de esa IWindow a View."); |
|
400 |
} |
|
401 |
|
|
402 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
|
403 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
|
404 |
theView.getMapControl().getMapContext().invalidate(); |
|
405 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
|
406 |
return lyr; |
|
407 |
} |
|
408 |
|
|
409 |
/** |
|
410 |
* Calculo de las coordenadas de una ventana IWindow para que quede centrada sobre el |
|
411 |
* MainFrame. Estas coordenadas solo valen para un IWindow ya que andami mete las ventanas |
|
412 |
* con coordenadas relativas a su ventanta principal. |
|
413 |
* @param widthWindow Ancho de la ventana a a?adir |
|
414 |
* @param heightWindow Alto de la ventana a a?adir |
|
415 |
* @return Array con el ancho y el alto |
|
416 |
*/ |
|
417 |
public static Point iwindowPosition(int widthWindow, int heightWindow) { |
|
418 |
int posWindowX = 0; |
|
419 |
int posWindowY = 0; |
|
420 |
Dimension dim = null; |
|
421 |
Point pos = null; |
|
422 |
if(PluginServices.getMainFrame() instanceof Component) { |
|
423 |
dim = ((Component)PluginServices.getMainFrame()).getSize(); |
|
424 |
pos = ((Component)PluginServices.getMainFrame()).getLocation(); |
|
425 |
if(dim != null && pos != null) { |
|
426 |
posWindowX = ((dim.width >> 1) - (widthWindow >> 1)); |
|
427 |
posWindowY = ((dim.height >> 1) - (heightWindow >> 1) - 70); |
|
428 |
return new Point(posWindowX, posWindowY); |
|
429 |
} |
|
430 |
} |
|
431 |
return null; |
|
432 |
} |
|
433 |
} |
|
0 | 434 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/IProcessActions.java | ||
---|---|---|
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.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
/** |
|
25 |
* Acciones que puede ejecutar un proceso sobre un objeto externo. Un proceso |
|
26 |
* debe ser independiente de objetos que sean dependientes de su funcionalidad. Es |
|
27 |
* decir, cualquier extensi?n debe poder usar un proceso y este ejecutar metodos |
|
28 |
* de la funcionalidad. Esto se hace ha trav?s de este interfaz. |
|
29 |
* |
|
30 |
* @version 26/09/2007 |
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
32 |
* |
|
33 |
*/ |
|
34 |
public interface IProcessActions { |
|
35 |
|
|
36 |
/** |
|
37 |
* El proceso comunica que ha sido interrumpido |
|
38 |
* |
|
39 |
*/ |
|
40 |
public void interrupted(); |
|
41 |
|
|
42 |
/** |
|
43 |
* Acciones de finalizaci?n del proceso |
|
44 |
*/ |
|
45 |
public void end(Object param); |
|
46 |
} |
|
0 | 47 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/OverviewsProcess.java | ||
---|---|---|
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.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import org.gvsig.andami.PluginServices; |
|
25 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
26 |
import org.gvsig.fmap.dal.coverage.exception.OverviewException; |
|
27 |
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask; |
|
28 |
import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder; |
|
29 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
30 |
import org.gvsig.raster.mainplugin.config.Configuration; |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* Proceso para la generaci?n de overviews. |
|
35 |
* |
|
36 |
* 10/12/2007 |
|
37 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
38 |
*/ |
|
39 |
public class OverviewsProcess extends RasterProcess implements BaseIncrementableTask { |
|
40 |
private FLyrRaster rasterSE = null; |
|
41 |
private int value = 0; |
|
42 |
private int resamplingAlg = OverviewBuilder.AVERAGE; |
|
43 |
private int[] overviews = new int[] { 2, 4, 8, 16 }; |
|
44 |
private String builder = "GDAL"; |
|
45 |
|
|
46 |
/* |
|
47 |
* (non-Javadoc) |
|
48 |
* @see org.gvsig.rastertools.RasterProcess#init() |
|
49 |
*/ |
|
50 |
public void init() { |
|
51 |
rasterSE = getLayerParam("layer"); |
|
52 |
builder = getStringParam("builder") != null ? getStringParam("builder") : builder; |
|
53 |
|
|
54 |
int overviewsRate = 2; |
|
55 |
int nOverviews = 4; |
|
56 |
overviewsRate = Configuration.getValue("overviews_rate", new Integer(overviewsRate)).intValue(); |
|
57 |
nOverviews = Configuration.getValue("overviews_number", new Integer(nOverviews)).intValue(); |
|
58 |
resamplingAlg = Configuration.getValue("overviews_resampling_algorithm", new Integer(resamplingAlg)).intValue(); |
|
59 |
|
|
60 |
// Leemos de la configuraci?n los valores de algoritmo a usar, |
|
61 |
// n?mero de overviews a generar y proporci?n de la primera overview |
|
62 |
|
|
63 |
overviews = new int[nOverviews]; |
|
64 |
overviews[0] = overviewsRate; |
|
65 |
for (int i = 1; i < nOverviews; i++) |
|
66 |
overviews[i] = overviewsRate * overviews[i - 1]; |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* M?todo donde se ejecutar? el Thread, aqu? se generaran las |
|
71 |
* overviews |
|
72 |
* @throws ProcessException |
|
73 |
*/ |
|
74 |
public void process() throws ProcessException { |
|
75 |
insertLineLog(PluginServices.getText(this, "overviews_generating")); |
|
76 |
OverviewBuilder overviewBuilder = RasterLocator.getManager().getOverviewBuilder(builder); |
|
77 |
|
|
78 |
overviewBuilder.setIncrementListener(this); |
|
79 |
try { |
|
80 |
String[] uri = rasterSE.getDataStore().getURIByProvider(); |
|
81 |
|
|
82 |
for (int i = 0; i < uri.length; i++) { |
|
83 |
insertLineLog(" Dataset: " + i); |
|
84 |
overviewBuilder.buildOverviews(resamplingAlg, uri[i], overviews); |
|
85 |
} |
|
86 |
|
|
87 |
if (externalActions != null) |
|
88 |
externalActions.end(rasterSE); |
|
89 |
} catch (OverviewException e) { |
|
90 |
if (incrementableTask != null) |
|
91 |
incrementableTask.hideWindow(); |
|
92 |
throw new ProcessException("error_write_overviews", e); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
/* |
|
97 |
* (non-Javadoc) |
|
98 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
|
99 |
*/ |
|
100 |
public int getPercent() { |
|
101 |
return value; |
|
102 |
} |
|
103 |
|
|
104 |
/* |
|
105 |
* (non-Javadoc) |
|
106 |
* @see org.gvsig.addo.IOverviewIncrement#setPercent(int) |
|
107 |
*/ |
|
108 |
public void setPercent(int value) { |
|
109 |
this.value = value; |
|
110 |
} |
|
111 |
|
|
112 |
/* |
|
113 |
* (non-Javadoc) |
|
114 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
|
115 |
*/ |
|
116 |
public String getTitle() { |
|
117 |
return PluginServices.getText(this, "incremento_overview"); |
|
118 |
} |
|
119 |
|
|
120 |
/* |
|
121 |
* (non-Javadoc) |
|
122 |
* @see java.lang.Object#finalize() |
|
123 |
*/ |
|
124 |
protected void finalize() throws Throwable { |
|
125 |
rasterSE = null; |
|
126 |
overviews = null; |
|
127 |
super.finalize(); |
|
128 |
} |
|
129 |
} |
|
0 | 130 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/StatisticsProcess.java | ||
---|---|---|
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.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import javax.swing.SwingUtilities; |
|
25 |
|
|
26 |
import org.gvsig.andami.PluginServices; |
|
27 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
28 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
29 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
30 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
|
31 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* Proceso para la generaci?n de estad?sticas. |
|
36 |
* |
|
37 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
38 |
*/ |
|
39 |
public class StatisticsProcess extends RasterProcess { |
|
40 |
private FLyrRaster lyr = null; |
|
41 |
private Statistics stats = null; |
|
42 |
private boolean force = false; |
|
43 |
private double scale = 1; |
|
44 |
|
|
45 |
/** |
|
46 |
* Lanzador del procesos de estad?sticas |
|
47 |
* @param lyr Capa a calcular las estad?sticas |
|
48 |
* @param actions Clase que recoge eventos del proceso |
|
49 |
*/ |
|
50 |
public static void launcher(FLyrRaster lyr, IProcessActions actions) { |
|
51 |
RasterProcess process = new StatisticsProcess(); |
|
52 |
process.addParam("layer", lyr); |
|
53 |
process.addParam("force", new Boolean(false)); |
|
54 |
process.setActions(actions); |
|
55 |
process.start(); |
|
56 |
} |
|
57 |
|
|
58 |
public void init() { |
|
59 |
lyr = getLayerParam("layer"); |
|
60 |
force = getBooleanParam("force"); |
|
61 |
double s = getDoubleParam("scale"); |
|
62 |
if(s > 0 && s < 1) |
|
63 |
scale = s; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* M?todo donde se ejecutar? el Thread, aqu? se calcular?n las |
|
68 |
* estad?sticas. |
|
69 |
* @throws ProcessException |
|
70 |
*/ |
|
71 |
public void process() throws ProcessInterruptedException, ProcessException { |
|
72 |
insertLineLog(PluginServices.getText(this, "statistics_generation")); |
|
73 |
if(lyr == null || lyr.getDataStore() == null) |
|
74 |
return; |
|
75 |
stats = lyr.getDataStore().getStatistics(); |
|
76 |
lyr.setReadingData(Thread.currentThread().getId() + ""); |
|
77 |
if (force) |
|
78 |
stats.forceToRecalc(); |
|
79 |
try { |
|
80 |
stats.calculate(scale); |
|
81 |
SwingUtilities.invokeLater(new Runnable() { |
|
82 |
public void run() { |
|
83 |
if (externalActions != null) |
|
84 |
externalActions.end(lyr); |
|
85 |
} |
|
86 |
}); |
|
87 |
} catch (FileNotOpenException e) { |
|
88 |
throw new ProcessException("No se ha podido escribir en el fichero rmf", e); |
|
89 |
} catch (RasterDriverException e) { |
|
90 |
throw new ProcessException("Error leyendo bloques de datos para calcular estad?sticas", e); |
|
91 |
} finally { |
|
92 |
lyr.setReadingData(null); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
public int getPercent() { |
|
97 |
return (stats != null) ? stats.getPercent() : 0; |
|
98 |
} |
|
99 |
|
|
100 |
public String getTitle() { |
|
101 |
return PluginServices.getText(this, "increase_statistics"); |
|
102 |
} |
|
103 |
} |
|
0 | 104 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/UniqueProcessQueue.java | ||
---|---|---|
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.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import org.gvsig.raster.util.Queue; |
|
25 |
import org.slf4j.LoggerFactory; |
|
26 |
|
|
27 |
/** |
|
28 |
* Cola de procesos de ejecuci?n exclusiva. Los procesos de esta lista se ir?n ejecutando |
|
29 |
* por orden de llegada impidiendo que se ejecuten dos al mismo tiempo. |
|
30 |
* |
|
31 |
* 16/05/2008 |
|
32 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
33 |
*/ |
|
34 |
public class UniqueProcessQueue implements IProcessActions { |
|
35 |
private static final int LAPSE_TIME = 1000; |
|
36 |
|
|
37 |
private Queue queue = new Queue(); |
|
38 |
private RasterProcess executionProcess = null; |
|
39 |
static private UniqueProcessQueue singleton = new UniqueProcessQueue(); |
|
40 |
|
|
41 |
/** |
|
42 |
* Dejamos el constructor privado para que nadie pueda referenciarlo |
|
43 |
*/ |
|
44 |
private UniqueProcessQueue() {} |
|
45 |
|
|
46 |
/** |
|
47 |
* Devuelve una instancia al unico objeto de UniqueProcessQueue que puede existir. |
|
48 |
* @return |
|
49 |
*/ |
|
50 |
static public UniqueProcessQueue getSingleton() { |
|
51 |
return singleton; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* A?ade un proceso a la cola. |
|
56 |
* @param id Identificador del proceso |
|
57 |
* @param process Proceso |
|
58 |
*/ |
|
59 |
public synchronized void add(RasterProcess process) { |
|
60 |
queue.put(process); |
|
61 |
process.setUniqueProcessActions(this); |
|
62 |
|
|
63 |
//Decisi?n de arranque |
|
64 |
if(queue.size() >= 1 && executionProcess != null) |
|
65 |
start(); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Pone en marcha el primer proceso de la lista |
|
70 |
*/ |
|
71 |
public void start() { |
|
72 |
nextProcess(); |
|
73 |
} |
|
74 |
|
|
75 |
private void nextProcess() { |
|
76 |
executionProcess = ((RasterProcess) queue.get()); |
|
77 |
if (executionProcess != null) |
|
78 |
executionProcess.start(); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Evento de finalizaci?n de un proceso. Cuando un proceso acaba se |
|
83 |
* pone en marcha el siguiente de la lista si existe. Se asigna un tiempo de latencia para |
|
84 |
* la ejecuci?n del siguiente marcado por LAPSE_TIME. |
|
85 |
*/ |
|
86 |
public void end(Object param) { |
|
87 |
try { |
|
88 |
Thread.sleep(LAPSE_TIME); |
|
89 |
} catch (InterruptedException e) { |
|
90 |
LoggerFactory.getLogger(UniqueProcessQueue.class).debug("sleep Exception", e); |
|
91 |
} |
|
92 |
nextProcess(); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* How many elements are there in this queue? |
|
97 |
*/ |
|
98 |
public int size() { |
|
99 |
return queue.size(); |
|
100 |
} |
|
101 |
|
|
102 |
/* |
|
103 |
* (non-Javadoc) |
|
104 |
* @see org.gvsig.raster.IProcessActions#interrupted() |
|
105 |
*/ |
|
106 |
public void interrupted() {} |
|
107 |
} |
|
0 | 108 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/HistogramProcess.java | ||
---|---|---|
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.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import javax.swing.SwingUtilities; |
|
25 |
|
|
26 |
import org.gvsig.andami.PluginServices; |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram; |
|
28 |
import org.gvsig.fmap.dal.coverage.exception.HistogramException; |
|
29 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
30 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
|
31 |
|
|
32 |
/** |
|
33 |
* Process to calculate a Histogram using a Histogramable object. A Histogramable object |
|
34 |
* has its own method to build an histogram an this process will call to this function. |
|
35 |
* |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class HistogramProcess extends RasterProcess { |
|
39 |
private BufferHistogram lastHistogram = null; |
|
40 |
private HistogramComputer histogramable = null; |
|
41 |
|
|
42 |
/* |
|
43 |
* (non-Javadoc) |
|
44 |
* @see org.gvsig.rastertools.RasterProcess#init() |
|
45 |
*/ |
|
46 |
public void init() { |
|
47 |
histogramable = (HistogramComputer) getParam("histogramable"); |
|
48 |
} |
|
49 |
|
|
50 |
/* |
|
51 |
* (non-Javadoc) |
|
52 |
* @see org.gvsig.rastertools.RasterProcess#process() |
|
53 |
*/ |
|
54 |
public void process() throws ProcessInterruptedException, ProcessException { |
|
55 |
try { |
|
56 |
// Proceso duro de obtener un histograma. Puede durar bastante tiempo. |
|
57 |
lastHistogram = histogramable.getBufferHistogram(); |
|
58 |
// Ya tenemos el histograma y lo representamos en la ventana |
|
59 |
SwingUtilities.invokeLater(new Runnable() { |
|
60 |
public void run() { |
|
61 |
if ((externalActions != null) && (lastHistogram != null)) |
|
62 |
externalActions.end(lastHistogram); |
|
63 |
} |
|
64 |
}); |
|
65 |
|
|
66 |
} catch (HistogramException e) { |
|
67 |
throw new ProcessException("Error calculando el histograma", e); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
/* |
|
72 |
* (non-Javadoc) |
|
73 |
* @see org.gvsig.raster.RasterProcess#getResult() |
|
74 |
*/ |
|
75 |
public Object getResult() { |
|
76 |
return lastHistogram; |
|
77 |
} |
|
78 |
|
|
79 |
/* |
|
80 |
* (non-Javadoc) |
|
81 |
* @see org.gvsig.rastertools.RasterProcess#getLog() |
|
82 |
*/ |
|
83 |
public String getLog() { |
|
84 |
return PluginServices.getText(this, "calculando_histograma") + "...\n"; |
|
85 |
} |
|
86 |
|
|
87 |
/* |
|
88 |
* (non-Javadoc) |
|
89 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
|
90 |
*/ |
|
91 |
public int getPercent() { |
|
92 |
if (histogramable != null) |
|
93 |
return histogramable.getPercent(); |
|
94 |
return 0; |
|
95 |
} |
|
96 |
|
|
97 |
/* |
|
98 |
* (non-Javadoc) |
|
99 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
|
100 |
*/ |
|
101 |
public String getTitle() { |
|
102 |
return PluginServices.getText(this, "calculando_histograma"); |
|
103 |
} |
|
104 |
|
|
105 |
/* |
|
106 |
* (non-Javadoc) |
|
107 |
* @see java.lang.Object#finalize() |
|
108 |
*/ |
|
109 |
protected void finalize() throws Throwable { |
|
110 |
lastHistogram = null; |
|
111 |
histogramable = null; |
|
112 |
super.finalize(); |
|
113 |
} |
|
114 |
} |
|
0 | 115 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/ProcessException.java | ||
---|---|---|
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.tools.app.basic.raster.process; |
|
23 |
/** |
|
24 |
* This exception is thrown when a problem inside a raster process |
|
25 |
* is detected. |
|
26 |
* |
|
27 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
28 |
*/ |
|
29 |
public class ProcessException extends Exception { |
|
30 |
private static final long serialVersionUID = 666908550965442025L; |
|
31 |
|
|
32 |
public ProcessException(String msg, Throwable e) { |
|
33 |
super(msg, e); |
|
34 |
} |
|
35 |
|
|
36 |
public ProcessException(String msg){ |
|
37 |
super(msg); |
|
38 |
} |
|
39 |
} |
|
0 | 40 |
org.gvsig.raster.tools/tags/org.gvsig.raster.tools-2.2.9/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/raster/process/RasterProcess.java | ||
---|---|---|
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.tools.app.basic.raster.process; |
|
23 |
|
|
24 |
import java.util.Hashtable; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
28 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
29 |
import org.gvsig.fmap.dal.coverage.process.CancelEvent; |
|
30 |
import org.gvsig.fmap.dal.coverage.process.TaskEventManager; |
|
31 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
|
32 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
|
33 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
|
34 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
|
35 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
|
36 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
37 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
38 |
import org.gvsig.tools.dispose.Disposable; |
|
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
/** |
|
42 |
* Clase base de todos los procesos raster. En ella se genstionan todas las |
|
43 |
* funciones comunes como incremento de la tarea, gesti?n de eventos a la tarea, |
|
44 |
* par?metros de la tarea, etc ... |
|
45 |
* |
|
46 |
* 18/12/2007 |
|
47 |
* @author Nacho Brodin nachobrodin@gmail.com |
|
48 |
* @deprecated Use DataProcess in org.gvsig.raster.algorithm |
|
49 |
*/ |
|
50 |
public abstract class RasterProcess implements IIncrementable, IncrementableListener, Runnable, Disposable { |
|
51 |
protected IncrementableTask incrementableTask = null; |
|
52 |
protected volatile Thread blinker = null; |
|
53 |
protected TaskEventManager taskEventManager = null; |
|
54 |
protected IProcessActions externalActions = null; |
|
55 |
protected Hashtable<String, Object> |
|
56 |
taskParams = new Hashtable<String, Object>(); |
|
57 |
|
|
58 |
private String log = ""; |
|
59 |
private String lastLine = ""; |
|
60 |
private long time = 0; |
|
61 |
private boolean progressActive = true; |
|
62 |
private IProcessActions queueActions = null; |
|
63 |
private Logger logger = LoggerFactory.getLogger(RasterProcess.class.toString()); |
|
64 |
|
|
65 |
|
|
66 |
/** |
|
67 |
* Crea la ventana de IncrementableTask |
|
68 |
*/ |
|
69 |
public IncrementableTask getIncrementableTask() { |
|
70 |
if (incrementableTask == null) { |
|
71 |
incrementableTask = new IncrementableTask(this); |
|
72 |
incrementableTask.addIncrementableListener(this); |
|
73 |
} |
|
74 |
return incrementableTask; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Define si se puede cancelar el proceso. Por defecto es true. |
|
79 |
* @param enabled |
|
80 |
*/ |
|
81 |
public void setCancelable(boolean enabled) { |
|
82 |
getIncrementableTask().getButtonsPanel().setEnabled(ButtonsPanel.BUTTON_CANCEL, enabled); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Muestra la ventana de IncrementableTask |
|
87 |
*/ |
|
88 |
public void showIncrementableWindow() { |
|
89 |
if (progressActive) { |
|
90 |
getIncrementableTask().showWindow(); |
|
91 |
getIncrementableTask().start(); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Arranca el proceso de recorte de un layer |
|
97 |
*/ |
|
98 |
public void start() { |
|
99 |
showIncrementableWindow(); |
|
100 |
if(blinker == null) |
|
101 |
blinker = new Thread(this); |
|
102 |
blinker.start(); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Proceso de carga de par?metros. Puede no hacerse una carga de par?metros |
|
107 |
* explicita y obtenerlos directamente de la tabla Hash cuando vayan a usarse. |
|
108 |
* Esto queda a elecci?n del programador. En caso de hacerse una carga de par?metros |
|
109 |
* explicita esta llamada deber?a hacerse justo despues del constructor de la clase |
|
110 |
* que contendr? el proceso. |
|
111 |
*/ |
|
112 |
public abstract void init(); |
|
113 |
|
|
114 |
/** |
|
115 |
* Proceso |
|
116 |
* @throws InterruptedException |
|
117 |
*/ |
|
118 |
public abstract void process() throws ProcessInterruptedException, ProcessException; |
|
119 |
|
|
120 |
/** |
|
121 |
* Obtenci?n de un objeto de resultado. Este objeto deber? ser el mismo que el que se |
|
122 |
* pasa por par?metro en el "end" de IProcessActions. Este m?todo es util cuando la tarea no se |
|
123 |
* lanza en un Thread (ejecutamos process directamente) y queremos recoger el resultado |
|
124 |
* sin registrarnos al evento de finalizaci?n de tarea. |
|
125 |
* @return objeto resultado de la tarea |
|
126 |
*/ |
|
127 |
public Object getResult() { |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Proceso |
|
133 |
* @throws ProcessException |
|
134 |
*/ |
|
135 |
public void execute() throws ProcessInterruptedException, ProcessException { |
|
136 |
init(); |
|
137 |
process(); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* M?todo donde se ejecutar? el Thread. Este har? las acciones globales para |
|
142 |
* cualquier tarea y llamar? al m?todo execute especifico de una tarea. |
|
143 |
*/ |
|
144 |
public void run() { |
|
145 |
long t1 = new java.util.Date().getTime(); |
|
146 |
|
|
147 |
try { |
|
148 |
taskEventManager = RasterLocator.getManager().createRasterTask(this); |
|
149 |
execute(); |
|
150 |
} catch (ProcessInterruptedException e) { |
|
151 |
if (externalActions != null) |
|
152 |
externalActions.interrupted(); |
|
153 |
Thread.currentThread().interrupt(); |
|
154 |
} catch (ProcessException e) { |
|
155 |
if (progressActive) { |
|
156 |
if (incrementableTask != null) { |
|
157 |
getIncrementableTask().processFinalize(); |
|
158 |
incrementableTask = null; |
|
159 |
} |
|
160 |
} |
|
161 |
logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e)); |
|
162 |
if(e.getMessage() != null && e.getMessage().compareTo("") != 0) |
|
163 |
RasterSwingLibrary.messageBoxError(e.getMessage(), this); |
|
164 |
else |
|
165 |
RasterSwingLibrary.messageBoxError("error_processing", this); |
|
166 |
queueActions = null; |
|
167 |
|
|
168 |
} catch (Exception e) { |
|
169 |
if (progressActive) { |
|
170 |
if (incrementableTask != null) { |
|
171 |
getIncrementableTask().processFinalize(); |
|
172 |
incrementableTask = null; |
|
173 |
} |
|
174 |
} |
|
175 |
logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e)); |
|
176 |
if(e.getMessage() != null && e.getMessage().compareTo("") != 0) |
|
177 |
RasterSwingLibrary.messageBoxError(e.getMessage(), this); |
|
178 |
else |
|
179 |
RasterSwingLibrary.messageBoxError("error_processing", this); |
|
180 |
queueActions = null; |
|
181 |
} finally { |
|
182 |
taskEventManager.removeTask(); |
|
183 |
if (progressActive) { |
|
184 |
if (incrementableTask != null) |
|
185 |
getIncrementableTask().processFinalize(); |
|
186 |
} |
|
187 |
if (queueActions != null) |
|
188 |
queueActions.end(this); |
|
189 |
time = new java.util.Date().getTime() - t1; |
|
190 |
blinker = null; |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Activa o desactiva el interfaz de progreso en el lanzamiento de la tarea como un thread. |
|
196 |
* @param active true para activarlo o false para desactivarlo |
|
197 |
*/ |
|
198 |
public void setProgressActive(boolean active){ |
|
199 |
this.progressActive = active; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Obtiene el tiempo que tard? en ejecutarse la tarea |
|
204 |
* la ?ltima vez que se proces? |
|
205 |
*/ |
|
206 |
public long getTime() { |
|
207 |
return time; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* Obtiene el objeto para ejecutar acciones externar. |
|
212 |
* @param IProcessActions |
|
213 |
*/ |
|
214 |
public IProcessActions getActions() { |
|
215 |
return externalActions; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Asigna el objeto para ejecutar acciones externar. |
|
220 |
* @param IProcessActions |
|
221 |
*/ |
|
222 |
public void setActions(IProcessActions actions) { |
|
223 |
this.externalActions = actions; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* Obtiene el objeto para ejecutar acciones de la cola de procesos de ejecuci?n exclusiva. |
|
228 |
* @param IProcessActions |
|
229 |
*/ |
|
230 |
public IProcessActions getUniqueProcessActions() { |
|
231 |
return queueActions; |
|
232 |
} |
|
233 |
|
|
234 |
/** |
|
235 |
* Asigna el objeto para ejecutar acciones externar. |
|
236 |
* @param IProcessActions |
|
237 |
*/ |
|
238 |
public void setUniqueProcessActions(IProcessActions actions) { |
|
239 |
this.queueActions = actions; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Inserta una nueva l?nea en el log del cuadro de incremento de tarea |
|
244 |
* @param line |
|
245 |
*/ |
|
246 |
protected void insertLineLog(String line) { |
|
247 |
lastLine = line; |
|
248 |
log = log + line + "\n"; |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* Obtiene la ?ltima l?nea introducida en el log del cuadro de incremento. |
|
253 |
*/ |
|
254 |
public String getLabel() { |
|
255 |
return lastLine; |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Obtiene el texto de log del cuadro de incremento completo. |
|
260 |
*/ |
|
261 |
public String getLog() { |
|
262 |
return log; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Un evento de cancelado es enviado a la tarea cuando actionCanceled es activado. Para |
|
267 |
* ello se crear? un objeto CancelEvent y se asignar? a la tarea en ejecuci?n. Esta lo |
|
268 |
* procesar? cuando pueda e interrumpir? el proceso. |
|
269 |
*/ |
|
270 |
public void actionCanceled(IncrementableEvent e) { |
|
271 |
taskEventManager.setEvent(new CancelEvent(this)); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* A?ade un par?metro a la tarea |
|
276 |
* @param name Clave del par?metro |
|
277 |
* @param param Objeto pasado como par?metro |
|
278 |
*/ |
|
279 |
public void addParam(String name, Object param) { |
|
280 |
if (param != null) |
|
281 |
taskParams.put(name, param); |
|
282 |
else |
|
283 |
taskParams.remove(name); |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* Elimina un par?metro de la tarea |
|
288 |
* @param name Clave del par?metro a eliminar |
|
289 |
*/ |
|
290 |
public void removeParam(String name) { |
|
291 |
taskParams.remove(name); |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* Obtiene un par?metro a partir de la clave |
|
296 |
* @param name Par?metro |
|
297 |
* @return Par?metro |
|
298 |
*/ |
|
299 |
public Object getParam(String name) { |
|
300 |
return taskParams.get(name); |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Obtiene un par?metro String a partir de la clave |
|
305 |
* @param name Par?metro |
|
306 |
* @return Par?metro |
|
307 |
*/ |
|
308 |
public String getStringParam(String name) { |
|
309 |
Object value = taskParams.get(name); |
|
310 |
return (value != null && value instanceof String) ? (String)value : null; |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* Obtiene un par?metro byte a partir de la clave |
|
315 |
* @param name Par?metro |
|
316 |
* @return Par?metro |
|
317 |
*/ |
|
318 |
public byte getByteParam(String name) { |
|
319 |
Object value = taskParams.get(name); |
|
320 |
return (value != null && value instanceof Byte) ? ((Byte)value).byteValue() : 0; |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* Obtiene un par?metro float a partir de la clave |
|
325 |
* @param name Par?metro |
|
326 |
* @return Par?metro |
|
327 |
*/ |
|
328 |
public float getFloatParam(String name) { |
|
329 |
Object value = taskParams.get(name); |
|
330 |
return (value != null && value instanceof Float) ? ((Float)value).floatValue() : 0F; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Obtiene un par?metro double a partir de la clave |
|
335 |
* @param name Par?metro |
|
336 |
* @return Par?metro |
|
337 |
*/ |
|
338 |
public double getDoubleParam(String name) { |
|
339 |
Object value = taskParams.get(name); |
|
340 |
return (value != null && value instanceof Double) ? ((Double)value).doubleValue() : 0D; |
|
341 |
} |
|
342 |
|
|
343 |
/** |
|
344 |
* Obtiene un par?metro entero a partir de la clave |
|
345 |
* @param name Par?metro |
|
346 |
* @return Par?metro |
|
347 |
*/ |
|
348 |
public int getIntParam(String name) { |
|
349 |
Object value = taskParams.get(name); |
|
350 |
return (value != null && value instanceof Integer) ? ((Integer)value).intValue() : 0; |
|
351 |
} |
|
352 |
|
|
353 |
/** |
|
354 |
* Obtiene un par?metro boolean a partir de la clave |
|
355 |
* @param name Par?metro |
|
356 |
* @return Par?metro |
|
357 |
*/ |
|
358 |
public boolean getBooleanParam(String name) { |
|
359 |
Object value = taskParams.get(name); |
|
360 |
return (value != null && value instanceof Boolean) ? ((Boolean)value).booleanValue() : false; |
|
361 |
} |
|
362 |
|
|
363 |
/** |
|
364 |
* Obtiene un par?metro int[] a partir de la clave |
|
365 |
* @param name Par?metro |
|
366 |
* @return Par?metro |
|
367 |
*/ |
|
368 |
public int[] getIntArrayParam(String name) { |
Also available in: Unified diff