root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / histogram / ui / HistogramIncrement.java @ 10799
History | View | Annotate | Download (3.59 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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.ui; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.FlowLayout; |
23 |
import java.awt.Toolkit; |
24 |
|
25 |
import javax.swing.JFrame; |
26 |
import javax.swing.JLabel; |
27 |
import javax.swing.JPanel; |
28 |
|
29 |
import org.cresques.i18n.Messages; |
30 |
import org.gvsig.rastertools.histogram.Histogram; |
31 |
/**
|
32 |
* <code>HistogramIncrement</code>. Ventana de incremento para la construcci?n
|
33 |
* del histograma
|
34 |
*
|
35 |
* @version 20/03/2007
|
36 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
37 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
|
38 |
*/
|
39 |
public class HistogramIncrement extends Thread { |
40 |
private HistogramPanelListener histogramPanelListener = null; |
41 |
|
42 |
private JPanel panel = null; |
43 |
private JLabel label = null; |
44 |
private JFrame window = new JFrame(); |
45 |
|
46 |
/**
|
47 |
* Constructor del <code>HistogramIncrement</code>.
|
48 |
* @param hpl Se le pasa el objecto de {@link HistogramPanelListener}
|
49 |
*/
|
50 |
public HistogramIncrement(HistogramPanelListener hpl){
|
51 |
this.setHistogramPanelListener(hpl);
|
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 |
window.getContentPane().add(getJPanel()); |
60 |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); |
61 |
window.setLocation( ((int)d.getWidth()) >> 1, |
62 |
((int)d.getHeight()) >> 1); |
63 |
window.setSize(200, 60); |
64 |
window.show(); |
65 |
if(this.isAlive()) |
66 |
this.resume();
|
67 |
else
|
68 |
this.start();
|
69 |
} |
70 |
|
71 |
/**
|
72 |
* Obtiene el panel del interior de la ventana de incremento
|
73 |
* @return JPanel
|
74 |
*/
|
75 |
private JPanel getJPanel(){ |
76 |
if (panel == null){ |
77 |
FlowLayout f = new FlowLayout(); |
78 |
panel = new JPanel(); |
79 |
panel.setLayout(f); |
80 |
label = new JLabel(); |
81 |
label.setText(Messages.getText("calculando... ") + 0 + "%"); |
82 |
panel.add(label, null);
|
83 |
} |
84 |
return panel;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Este thread va leyendo el porcentaje hasta que se completa el histograma.
|
89 |
*/
|
90 |
public synchronized void run(){ |
91 |
while(true){ |
92 |
Histogram hist = this.getHistogramPanelListener().getHistogram();
|
93 |
while (hist.getPercent() < 100){ |
94 |
label.setText(Messages.getText("calculando ...") + hist.getPercent() +"%"); |
95 |
try {
|
96 |
sleep(100);
|
97 |
} catch (InterruptedException e) { |
98 |
e.printStackTrace(); |
99 |
} |
100 |
} |
101 |
//Cerramos la ventana
|
102 |
window.hide(); |
103 |
window = null;
|
104 |
|
105 |
//Mostramos el resultado
|
106 |
this.getHistogramPanelListener().readFullHistogramFromThread();
|
107 |
|
108 |
this.suspend();
|
109 |
} |
110 |
} |
111 |
|
112 |
/**
|
113 |
* M?todo para obtener el {@link HistogramPanelListener}
|
114 |
* @return <code>HistogramPanelListener</code>
|
115 |
*/
|
116 |
public HistogramPanelListener getHistogramPanelListener() {
|
117 |
return histogramPanelListener;
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Definir el {@link HistogramPanelListener}
|
122 |
* @param hpl {@link HistogramPanelListener}
|
123 |
*/
|
124 |
public void setHistogramPanelListener(HistogramPanelListener hpl) { |
125 |
histogramPanelListener = hpl; |
126 |
} |
127 |
} |