Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / histogram / HistogramProcess.java @ 11065

History | View | Annotate | Download (3.03 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
public class HistogramProcess implements Runnable, IIncrementable, IncrementableListener {
30
        IHistogramable iHistogramable = null;
31
        HistogramPanelListener hpl = null;
32

    
33
        IncrementableTask incrementableTask = null;
34
        private volatile Thread blinker;
35

    
36
        public HistogramProcess(IHistogramable iHistogramable, HistogramPanelListener hpl) {
37
                this.iHistogramable = iHistogramable;
38
                this.hpl = hpl;
39
        }
40
        
41
        public void start() {
42
                blinker = new Thread(this);
43
                blinker.start();
44
        }
45
        
46
        public synchronized void stop() {
47
                blinker = null;
48
                notify();
49
        }
50

    
51
        public void run() {
52
                try {
53
                        Histogram histogram = iHistogramable.getHistogram();
54
                        hpl.setNewHistogram(histogram);
55
                } catch (HistogramException e) {
56
                        e.printStackTrace();
57
                }
58
                while (incrementableTask.isAlive());
59
                incrementableTask.Hide();
60
                incrementableTask = null;
61
        }
62
        
63
        public void setIncrementableTask(IncrementableTask value) {
64
                incrementableTask = value;
65
        }
66

    
67
        /*
68
         * (non-Javadoc)
69
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLabel()
70
         */
71
        public String getLabel() {
72
                return "Generando histograma, por favor, espere...";
73
        }
74

    
75
        /*
76
         * (non-Javadoc)
77
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLog()
78
         */
79
        public String getLog() {
80
                return "Calculando histograma...";
81
        }
82

    
83
        /*
84
         * (non-Javadoc)
85
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getPercent()
86
         */
87
        public int getPercent() {
88
                return iHistogramable.getPercent();
89
        }
90

    
91
        /*
92
         * (non-Javadoc)
93
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getTitle()
94
         */
95
        public String getTitle() {
96
                return "Calculando histograma";
97
        }
98

    
99
        public void actionCanceled(IncrementableEvent e) {
100
                // TODO Implementar la forma de cancelar el proceso
101
        }
102

    
103
        public void actionResumed(IncrementableEvent e) {
104
        }
105

    
106
        public void actionSuspended(IncrementableEvent e) {
107
        }
108
}