Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / histogram / HistogramProcess.java @ 11423

History | View | Annotate | Download (4.48 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.histogram;
20

    
21
import org.gvsig.gui.beans.incrementabletask.IIncrementable;
22
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
23
import org.gvsig.gui.beans.incrementabletask.IncrementableListener;
24
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
25
import org.gvsig.raster.util.Histogram;
26
import org.gvsig.raster.util.HistogramException;
27
import org.gvsig.raster.util.IHistogramable;
28

    
29
import com.iver.andami.PluginServices;
30
/**
31
 * Clase para calcular histogramas. Esta clase implementa IIncrementable para
32
 * poder ser usado con una ventana de incremento <code>IncrementableTask</code>
33
 * 
34
 * @version 23/04/2007
35
 * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
36
 */
37
public class HistogramProcess implements Runnable, IIncrementable, IncrementableListener {
38
        IHistogramable iHistogramable = null;
39
        HistogramPanelListener hpl = null;
40

    
41
        IncrementableTask incrementableTask = null;
42
        private volatile Thread blinker;
43

    
44
        /**
45
         * Constructor del Proceso de calculo de histogramas.
46
         * @param iHistogramable
47
         * @param hpl
48
         */
49
        public HistogramProcess(IHistogramable iHistogramable, HistogramPanelListener hpl) {
50
                this.iHistogramable = iHistogramable;
51
                this.hpl = hpl;
52
        }
53

    
54
        /**
55
         * Lanzar el Thread del proceso de calculo de histograma.
56
         */
57
        public void start() {
58
                blinker = new Thread(this);
59
                blinker.start();
60
        }
61

    
62
        /*
63
         * (non-Javadoc)
64
         * @see java.lang.Runnable#run()
65
         */
66
        public void run() {
67
                try {
68
                        // Definimos que no esta cancelado para que no termine antes de empezar.
69
                        iHistogramable.setCanceled(false, IHistogramable.CANCEL_HISTOGRAM);
70
                        // Proceso duro de obtener un histograma. Puede durar bastante tiempo.
71
                        Histogram histogram = iHistogramable.getHistogram();
72
                        // Ya tenemos el histograma y lo representamos en la ventana
73
                        if (histogram != null) hpl.setNewHistogram(histogram);
74
                } catch (HistogramException e) {
75
                        e.printStackTrace();
76
                }
77
                
78
                // Cerramos la ventana de incremento de manera correcta.
79
                incrementableTask.processFinalize();
80
        }
81
        
82
        /**
83
         * Definir el IncrementableTask 
84
         * @param value
85
         */
86
        public void setIncrementableTask(IncrementableTask value) {
87
                incrementableTask = value;
88
                incrementableTask.addIncrementableListener(this);
89
        }
90

    
91
        /*
92
         * (non-Javadoc)
93
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLabel()
94
         */
95
        public String getLabel() {
96
                return PluginServices.getText(this, "generando_histograma") + "...";
97
        }
98

    
99
        /*
100
         * (non-Javadoc)
101
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLog()
102
         */
103
        public String getLog() {
104
                return PluginServices.getText(this, "calculando_histograma") + "...";
105
        }
106

    
107
        /*
108
         * (non-Javadoc)
109
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getPercent()
110
         */
111
        public int getPercent() {
112
                return iHistogramable.getPercent();
113
        }
114

    
115
        /*
116
         * (non-Javadoc)
117
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getTitle()
118
         */
119
        public String getTitle() {
120
                return PluginServices.getText(this, "calculando_histograma");
121
        }
122

    
123
        /*
124
         * (non-Javadoc)
125
         * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionCanceled(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
126
         */
127
        public void actionCanceled(IncrementableEvent e) {
128
                iHistogramable.setCanceled(true, IHistogramable.CANCEL_HISTOGRAM);
129
        }
130

    
131
        /*
132
         * (non-Javadoc)
133
         * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionResumed(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
134
         */
135
        public void actionResumed(IncrementableEvent e) {
136
        }
137

    
138
        /*
139
         * (non-Javadoc)
140
         * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionSuspended(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
141
         */
142
        public void actionSuspended(IncrementableEvent e) {
143
        }
144
}