22 |
|
package uk.org.iscream.cms.conient; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
+ |
import java.awt.Color; |
26 |
|
import javax.swing.JProgressBar; |
27 |
|
import javax.swing.JPanel; |
28 |
|
import javax.swing.JLabel; |
37 |
|
* This then displays a JProgress bar which updates at |
38 |
|
* 10th of a second intervals. |
39 |
|
* |
39 |
– |
* It currently is adjusted by the addition of 1 second |
40 |
– |
* to account for the possibility of network delay. |
41 |
– |
* |
40 |
|
* @author $Author$ |
41 |
|
* @version $Id$ |
42 |
|
*/ |
59 |
|
* @param timeBetweenPackets the time in seconds between packet arrival |
60 |
|
*/ |
61 |
|
public PacketTimer(String name, int timeBetweenPackets) { |
62 |
< |
_timeBetweenPackets = timeBetweenPackets * 10; |
62 |
> |
_timeBetweenPackets = timeBetweenPackets * 1000; |
63 |
|
_progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, _timeBetweenPackets); |
64 |
+ |
_barColour = _progressBar.getForeground(); |
65 |
|
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
66 |
|
JLabel label = new JLabel(name); |
67 |
|
this.add(_progressBar); |
82 |
|
|
83 |
|
SwingUtilities.invokeLater(new Runnable() { |
84 |
|
public void run() { |
85 |
< |
_progressBar.setValue(_progressBar.getValue() - 1); |
85 |
> |
long t = _nextTime - System.currentTimeMillis(); |
86 |
> |
if(t >= 0) { |
87 |
> |
_progressBar.setValue((int) t); |
88 |
> |
} |
89 |
> |
else { |
90 |
> |
_progressBar.setValue((int) (t*-1)); |
91 |
> |
_progressBar.setForeground(Color.red); |
92 |
> |
} |
93 |
|
} |
94 |
|
}); |
95 |
|
} |
99 |
|
* Resets the progress bar. |
100 |
|
*/ |
101 |
|
public void reset() { |
102 |
+ |
_nextTime = System.currentTimeMillis() + _timeBetweenPackets; |
103 |
|
SwingUtilities.invokeLater(new Runnable() { |
104 |
|
public void run() { |
105 |
|
_progressBar.setValue(_timeBetweenPackets); |
106 |
+ |
_progressBar.setForeground(_barColour); |
107 |
|
} |
108 |
|
}); |
109 |
|
} |
118 |
|
* Holds the time between packets as used internally by this class |
119 |
|
*/ |
120 |
|
private int _timeBetweenPackets; |
121 |
+ |
private long _nextTime; |
122 |
+ |
private Color _barColour; |
123 |
|
|
124 |
|
/** |
125 |
|
* Used to indicate the state of the thread |