root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / incrementabletask / IncrementableTask.java @ 10948
History | View | Annotate | Download (2.12 KB)
1 |
package org.gvsig.gui.beans.incrementabletask; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.awt.event.WindowAdapter; |
6 |
import java.awt.event.WindowEvent; |
7 |
|
8 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
9 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
10 |
|
11 |
public class IncrementableTask extends Thread implements ActionListener { |
12 |
IIncrementable iIncrementable; |
13 |
ProgressPanel progressPanel = null;
|
14 |
|
15 |
public IncrementableTask(IIncrementable incrementable) {
|
16 |
iIncrementable = incrementable; |
17 |
} |
18 |
|
19 |
/**
|
20 |
* Este thread va leyendo el porcentaje hasta que se completa el histograma.
|
21 |
*/
|
22 |
public synchronized void run(){ |
23 |
while(true){ |
24 |
showWindow(); |
25 |
while (iIncrementable.getPercent() < 100){ |
26 |
getProgressPanel().setLabel(iIncrementable.getLabel()); |
27 |
getProgressPanel().setPercent(iIncrementable.getPercent()); |
28 |
getProgressPanel().setTitle(iIncrementable.getTitle()); |
29 |
getProgressPanel().setLog(iIncrementable.getLog()); |
30 |
try {
|
31 |
sleep(100);
|
32 |
} catch (InterruptedException e) { |
33 |
e.printStackTrace(); |
34 |
} |
35 |
} |
36 |
//Cerramos la ventana
|
37 |
|
38 |
handleClose(); |
39 |
|
40 |
this.suspend();
|
41 |
} |
42 |
} |
43 |
|
44 |
private void handleClose() { |
45 |
getProgressPanel().setVisible(false);
|
46 |
getProgressPanel().hide(); |
47 |
progressPanel = null;
|
48 |
System.out.println("Cerrado"); |
49 |
} |
50 |
/**
|
51 |
* Muestra la ventana de incremento con el porcentaje de la construcci?n del
|
52 |
* histograma.
|
53 |
*/
|
54 |
public void showWindow(){ |
55 |
getProgressPanel().setTitle(iIncrementable.getTitle()); |
56 |
getProgressPanel().showLog(false);
|
57 |
getProgressPanel().show(); |
58 |
|
59 |
if(this.isAlive()) |
60 |
this.resume();
|
61 |
else
|
62 |
this.start();
|
63 |
} |
64 |
|
65 |
private ProgressPanel getProgressPanel() {
|
66 |
if (progressPanel == null) { |
67 |
progressPanel = new ProgressPanel();
|
68 |
progressPanel.getButtonsPanel().addActionListener(this);
|
69 |
progressPanel.addWindowListener( new WindowAdapter() { |
70 |
public void windowClosing(WindowEvent e) |
71 |
{ |
72 |
handleClose(); |
73 |
} |
74 |
}); |
75 |
} |
76 |
return progressPanel;
|
77 |
} |
78 |
|
79 |
public void actionPerformed(ActionEvent e) { |
80 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "") == 0) { |
81 |
handleClose(); |
82 |
} |
83 |
} |
84 |
} |