svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / statistics / StatisticsProcess.java @ 30008
History | View | Annotate | Download (3.47 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. 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 |
package org.gvsig.rastertools.statistics; |
20 |
|
21 |
import javax.swing.SwingUtilities; |
22 |
|
23 |
import org.gvsig.andami.PluginServices; |
24 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
25 |
import org.gvsig.raster.IProcessActions; |
26 |
import org.gvsig.raster.RasterProcess; |
27 |
import org.gvsig.raster.dataset.FileNotOpenException; |
28 |
import org.gvsig.raster.dataset.RasterDriverException; |
29 |
import org.gvsig.raster.dataset.properties.DatasetListStatistics; |
30 |
import org.gvsig.raster.util.RasterToolsUtil; |
31 |
|
32 |
|
33 |
/**
|
34 |
* Proceso para la generaci?n de estad?sticas.
|
35 |
*
|
36 |
* 10/12/2007
|
37 |
* @author Nacho Brodin nachobrodin@gmail.com
|
38 |
*/
|
39 |
public class StatisticsProcess extends RasterProcess { |
40 |
private FLyrRasterSE lyr = null; |
41 |
private DatasetListStatistics stats = null; |
42 |
private boolean force = false; |
43 |
|
44 |
/**
|
45 |
* Lanzador del procesos de estad?sticas
|
46 |
* @param lyr Capa a calcular las estad?sticas
|
47 |
* @param actions Clase que recoge eventos del proceso
|
48 |
*/
|
49 |
public static void launcher(FLyrRasterSE lyr, IProcessActions actions) { |
50 |
RasterProcess process = new StatisticsProcess();
|
51 |
process.addParam("layer", lyr);
|
52 |
process.addParam("force", new Boolean(false)); |
53 |
process.setActions(actions); |
54 |
process.start(); |
55 |
} |
56 |
|
57 |
/*
|
58 |
* (non-Javadoc)
|
59 |
* @see org.gvsig.rastertools.RasterProcess#init()
|
60 |
*/
|
61 |
public void init() { |
62 |
lyr = getLayerParam("layer");
|
63 |
force = getBooleanParam("force");
|
64 |
stats = lyr.getDataSource().getStatistics(); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* M?todo donde se ejecutar? el Thread, aqu? se calcular?n las
|
69 |
* estad?sticas.
|
70 |
*/
|
71 |
public void process() throws InterruptedException { |
72 |
insertLineLog(PluginServices.getText(this, "statistics_generation")); |
73 |
lyr.setReadingData(Thread.currentThread().toString());
|
74 |
if (force)
|
75 |
stats.forceToRecalc(); |
76 |
try {
|
77 |
stats.calcFullStatistics(); |
78 |
SwingUtilities.invokeLater(new Runnable() { |
79 |
public void run() { |
80 |
if (externalActions != null) |
81 |
externalActions.end(lyr); |
82 |
} |
83 |
}); |
84 |
} catch (FileNotOpenException e) {
|
85 |
RasterToolsUtil.debug("No se ha podido escribir en el fichero rmf", this, e); |
86 |
} catch (RasterDriverException e) {
|
87 |
RasterToolsUtil.debug("Error leyendo bloques de datos para calcular estad?sticas", this, e); |
88 |
} finally {
|
89 |
lyr.setReadingData(null);
|
90 |
} |
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
|
96 |
*/
|
97 |
public int getPercent() { |
98 |
return (stats != null) ? stats.getPercent() : 0; |
99 |
} |
100 |
|
101 |
/*
|
102 |
* (non-Javadoc)
|
103 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
|
104 |
*/
|
105 |
public String getTitle() { |
106 |
return PluginServices.getText(this, "increase_statistics"); |
107 |
} |
108 |
} |