Statistics
| Revision:

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

History | View | Annotate | Download (3.72 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
        /*
52
         * (non-Javadoc)
53
         * @see java.lang.Runnable#run()
54
         */
55
        public void run() {
56
                try {
57
                        iHistogramable.setCanceled(false);
58
                        Histogram histogram = iHistogramable.getHistogram();
59
                        if (histogram != null) hpl.setNewHistogram(histogram);
60
                } catch (HistogramException e) {
61
                        e.printStackTrace();
62
                }
63
                while (incrementableTask.isAlive());
64
                incrementableTask.Hide();
65
                incrementableTask = null;
66
        }
67
        
68
        /*
69
         * Definir el IncrementableTask 
70
         */
71
        public void setIncrementableTask(IncrementableTask value) {
72
                incrementableTask = value;
73
                incrementableTask.addIncrementableListener(this);
74
        }
75

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

    
84
        /*
85
         * (non-Javadoc)
86
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLog()
87
         */
88
        public String getLog() {
89
                return "Calculando histograma...";
90
        }
91

    
92
        /*
93
         * (non-Javadoc)
94
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getPercent()
95
         */
96
        public int getPercent() {
97
                return iHistogramable.getPercent();
98
        }
99

    
100
        /*
101
         * (non-Javadoc)
102
         * @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getTitle()
103
         */
104
        public String getTitle() {
105
                return "Calculando histograma";
106
        }
107

    
108
        /*
109
         * (non-Javadoc)
110
         * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionCanceled(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
111
         */
112
        public void actionCanceled(IncrementableEvent e) {
113
                iHistogramable.setCanceled(true);
114
        }
115

    
116
        /*
117
         * (non-Javadoc)
118
         * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionResumed(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
119
         */
120
        public void actionResumed(IncrementableEvent e) {
121
        }
122

    
123
        /*
124
         * (non-Javadoc)
125
         * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionSuspended(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
126
         */
127
        public void actionSuspended(IncrementableEvent e) {
128
        }
129
}