Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / HistogramIncrement.java @ 8026

History | View | Annotate | Download (2.92 KB)

1
/*
2
 * Created on 22-jul-2006
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 */
23
package org.cresques.ui.raster;
24

    
25
import java.awt.Dimension;
26
import java.awt.FlowLayout;
27
import java.awt.Toolkit;
28

    
29
import javax.swing.JFrame;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32

    
33
import org.cresques.io.datastruct.Histogram;
34
import org.gvsig.i18n.Messages;
35

    
36
/**
37
 * Ventana de incremento para la construcci?n del histograma
38
 * 
39
 * @author Nacho Brodin (brodin_ign@gva.es)
40
 *
41
 */
42

    
43
public class HistogramIncrement extends Thread {
44

    
45
        private JPanel panel = null;
46
        private JLabel label = null;
47
        private HistogramPanel hp = null;
48
        private JFrame window = new JFrame();
49
        
50
        public HistogramIncrement(HistogramPanel hp){
51
                this.hp = hp;
52
        }
53
        
54
        /**
55
         * Muestra la ventana de incremento con el porcentaje de la construcci?n del
56
         * histograma.
57
         */
58
        public void showWindow(){
59
                if(label != null)
60
                        label.setText(Messages.getText("calculando... ") + 0  + "%");
61
                window.getContentPane().add(getJPanel());
62
                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
63
                window.setLocation(        ((int)d.getWidth()) >> 1, 
64
                                                    ((int)d.getHeight()) >> 1);
65
                window.setSize(200, 60);
66
                window.show();
67
                if(this.isAlive())
68
                        this.resume();
69
                else
70
                        this.start();
71
        }
72
        
73
        /**
74
         * Obtiene el panel del interior de la ventana de incremento
75
         * @return JPanel
76
         */
77
        private JPanel getJPanel(){
78
                if(panel == null){
79
                        FlowLayout f = new FlowLayout();
80
                        panel = new JPanel();
81
                        panel.setLayout(f);
82
                        label = new JLabel();
83
                        label.setText(Messages.getText("calculando... ") + 0  + "%");
84
                        panel.add(label, null);
85
                }
86
                return panel;
87
        }
88
        
89
        /**
90
         * Este thread va leyendo el porcentaje hasta que se completa el histograma.
91
         */
92
        public synchronized void run(){
93
                while(true){
94
                        Histogram hist = hp.getHistogram();
95
                        while(hist.getPercent() < 100){
96
                                label.setText(Messages.getText("calculando ...") +  hist.getPercent() +"%");
97
                                try {
98
                                        sleep(100);
99
                                } catch (InterruptedException e) {
100
                                        e.printStackTrace();
101
                                }
102
                        }
103
                        //Cerramos la ventana
104
                        window.hide();
105
                        window = null;
106
                        
107
                        //Mostramos el resultado
108
                        hp.readFullHistogramFromThread();
109
                        
110
                        this.suspend();
111

    
112
                }
113
        }
114
}