Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / statistics / StatisticsProcess.java @ 22827

History | View | Annotate | Download (3.37 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.fmap.raster.layers.FLyrRasterSE;
24
import org.gvsig.raster.IProcessActions;
25
import org.gvsig.raster.RasterProcess;
26
import org.gvsig.raster.dataset.FileNotOpenException;
27
import org.gvsig.raster.dataset.io.RasterDriverException;
28
import org.gvsig.raster.dataset.properties.DatasetListStatistics;
29
import org.gvsig.raster.util.RasterToolsUtil;
30

    
31
import com.iver.andami.PluginServices;
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
                if (force)
74
                        stats.forceToRecalc();
75
                try {
76
                        stats.calcFullStatistics();
77
                        SwingUtilities.invokeLater(new Runnable() {
78
                                public void run() {
79
                                        if (externalActions != null)
80
                                                externalActions.end(lyr);
81
                                }
82
                        });
83
                } catch (FileNotOpenException e) {
84
                        RasterToolsUtil.debug("No se ha podido escribir en el fichero rmf", this, e);
85
                } catch (RasterDriverException e) {
86
                        RasterToolsUtil.debug("Error leyendo bloques de datos para calcular estad?sticas", this, e);
87
                }
88
        }
89

    
90
        /*
91
         * (non-Javadoc)
92
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
93
         */
94
        public int getPercent() {
95
                return (stats != null) ? stats.getPercent() : 0;
96
        }
97

    
98
        /*
99
         * (non-Javadoc)
100
         * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
101
         */
102
        public String getTitle() {
103
                return PluginServices.getText(this, "increase_statistics");
104
        }
105
}