Statistics
| Revision:

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

History | View | Annotate | Download (3.07 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.getStarted());
59
                while (incrementableTask.isAlive());
60
                incrementableTask.Hide();
61
                incrementableTask = null;
62
        }
63
        
64
        public void setIncrementableTask(IncrementableTask value) {
65
                incrementableTask = value;
66
        }
67

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

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

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

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

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

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

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