1 |
< |
package uk.ac.ukc.iscream.conient; |
1 |
> |
//---PACKAGE DECLARATION--- |
2 |
> |
package uk.org.iscream.cms.conient; |
3 |
|
|
4 |
+ |
//---IMPORTS--- |
5 |
|
import javax.swing.JProgressBar; |
6 |
+ |
import javax.swing.JPanel; |
7 |
+ |
import javax.swing.JLabel; |
8 |
+ |
import javax.swing.BoxLayout; |
9 |
|
import javax.swing.SwingUtilities; |
10 |
|
|
11 |
< |
public class PacketTimer extends JProgressBar implements Runnable { |
11 |
> |
/** |
12 |
> |
* Shows a countdown timer for packet arrival times. |
13 |
> |
* When constructed it takes an integer value relating |
14 |
> |
* to the time in seconds between recieving packets. |
15 |
> |
* |
16 |
> |
* This then displays a JProgress bar which updates at |
17 |
> |
* 10th of a second intervals. |
18 |
> |
* |
19 |
> |
* It currently is adjusted by the addition of 1 second |
20 |
> |
* to account for the possibility of network delay. |
21 |
> |
* |
22 |
> |
* @author $Author$ |
23 |
> |
* @version $Id$ |
24 |
> |
*/ |
25 |
> |
public class PacketTimer extends JPanel implements Runnable { |
26 |
|
|
27 |
< |
public PacketTimer(int timeBetweenPackets) { |
28 |
< |
super(JProgressBar.VERTICAL, 0, timeBetweenPackets * 10); |
27 |
> |
//---FINAL ATTRIBUTES--- |
28 |
> |
|
29 |
> |
/** |
30 |
> |
* The current CVS revision of this class |
31 |
> |
*/ |
32 |
> |
public static final String REVISION = "$Revision$"; |
33 |
> |
|
34 |
> |
//---STATIC METHODS--- |
35 |
> |
|
36 |
> |
//---CONSTRUCTORS--- |
37 |
> |
|
38 |
> |
/** |
39 |
> |
* Constructs a new PacketTimer |
40 |
> |
* |
41 |
> |
* @param timeBetweenPackets the time in seconds between packet arrival |
42 |
> |
*/ |
43 |
> |
public PacketTimer(String name, int timeBetweenPackets) { |
44 |
|
_timeBetweenPackets = timeBetweenPackets * 10; |
45 |
< |
setMaximum(_timeBetweenPackets); |
45 |
> |
_progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, _timeBetweenPackets); |
46 |
> |
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
47 |
> |
JLabel label = new JLabel(name); |
48 |
> |
this.add(_progressBar); |
49 |
> |
this.add(label); |
50 |
|
} |
51 |
+ |
|
52 |
+ |
//---PUBLIC METHODS--- |
53 |
|
|
54 |
+ |
/** |
55 |
+ |
* Updates the progress bar every 10th of a second. |
56 |
+ |
*/ |
57 |
|
public void run() { |
58 |
< |
while(running) { |
58 |
> |
while(_running) { |
59 |
|
try { |
60 |
|
Thread.sleep(100); |
61 |
|
} catch (InterruptedException e) { |
63 |
|
|
64 |
|
SwingUtilities.invokeLater(new Runnable() { |
65 |
|
public void run() { |
66 |
< |
PacketTimer.this.setValue(PacketTimer.this.getValue() - 1); |
66 |
> |
_progressBar.setValue(_progressBar.getValue() - 1); |
67 |
|
} |
68 |
|
}); |
69 |
|
} |
70 |
|
} |
71 |
|
|
72 |
+ |
/** |
73 |
+ |
* Resets the progress bar. |
74 |
+ |
*/ |
75 |
|
public void reset() { |
76 |
|
SwingUtilities.invokeLater(new Runnable() { |
77 |
|
public void run() { |
78 |
< |
PacketTimer.this.setValue(_timeBetweenPackets); |
78 |
> |
_progressBar.setValue(_timeBetweenPackets); |
79 |
|
} |
80 |
|
}); |
81 |
|
} |
82 |
|
|
83 |
+ |
//---PRIVATE METHODS--- |
84 |
+ |
|
85 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
86 |
+ |
|
87 |
+ |
//---ATTRIBUTES--- |
88 |
+ |
|
89 |
+ |
/** |
90 |
+ |
* Holds the time between packets as used internally by this class |
91 |
+ |
*/ |
92 |
|
private int _timeBetweenPackets; |
93 |
< |
private boolean running = true; |
93 |
> |
|
94 |
> |
/** |
95 |
> |
* Used to indicate the state of the thread |
96 |
> |
*/ |
97 |
> |
private boolean _running = true; |
98 |
> |
|
99 |
> |
private JProgressBar _progressBar; |
100 |
> |
|
101 |
> |
//---STATIC ATTRIBUTES--- |
102 |
> |
|
103 |
|
} |