1 |
< |
package uk.ac.ukc.iscream.conient; |
1 |
> |
/* |
2 |
> |
* i-scream central monitoring system |
3 |
> |
* http://www.i-scream.org.uk |
4 |
> |
* Copyright (C) 2000-2002 i-scream |
5 |
> |
* |
6 |
> |
* This program is free software; you can redistribute it and/or |
7 |
> |
* modify it under the terms of the GNU General Public License |
8 |
> |
* as published by the Free Software Foundation; either version 2 |
9 |
> |
* of the License, or (at your option) any later version. |
10 |
> |
* |
11 |
> |
* This program is distributed in the hope that it will be useful, |
12 |
> |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
> |
* GNU General Public License for more details. |
15 |
> |
* |
16 |
> |
* You should have received a copy of the GNU General Public License |
17 |
> |
* along with this program; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
> |
*/ |
20 |
|
|
21 |
+ |
//---PACKAGE DECLARATION--- |
22 |
+ |
package uk.org.iscream.cms.conient; |
23 |
+ |
|
24 |
+ |
//---IMPORTS--- |
25 |
|
import javax.swing.JProgressBar; |
26 |
+ |
import javax.swing.JPanel; |
27 |
+ |
import javax.swing.JLabel; |
28 |
+ |
import javax.swing.BoxLayout; |
29 |
|
import javax.swing.SwingUtilities; |
30 |
|
|
31 |
< |
public class PacketTimer extends JProgressBar implements Runnable { |
31 |
> |
/** |
32 |
> |
* Shows a countdown timer for packet arrival times. |
33 |
> |
* When constructed it takes an integer value relating |
34 |
> |
* to the time in seconds between recieving packets. |
35 |
> |
* |
36 |
> |
* This then displays a JProgress bar which updates at |
37 |
> |
* 10th of a second intervals. |
38 |
> |
* |
39 |
> |
* It currently is adjusted by the addition of 1 second |
40 |
> |
* to account for the possibility of network delay. |
41 |
> |
* |
42 |
> |
* @author $Author$ |
43 |
> |
* @version $Id$ |
44 |
> |
*/ |
45 |
> |
public class PacketTimer extends JPanel implements Runnable { |
46 |
|
|
47 |
< |
public PacketTimer(int timeBetweenPackets) { |
48 |
< |
super(JProgressBar.VERTICAL, 0, timeBetweenPackets * 10); |
47 |
> |
//---FINAL ATTRIBUTES--- |
48 |
> |
|
49 |
> |
/** |
50 |
> |
* The current CVS revision of this class |
51 |
> |
*/ |
52 |
> |
public static final String REVISION = "$Revision$"; |
53 |
> |
|
54 |
> |
//---STATIC METHODS--- |
55 |
> |
|
56 |
> |
//---CONSTRUCTORS--- |
57 |
> |
|
58 |
> |
/** |
59 |
> |
* Constructs a new PacketTimer |
60 |
> |
* |
61 |
> |
* @param timeBetweenPackets the time in seconds between packet arrival |
62 |
> |
*/ |
63 |
> |
public PacketTimer(String name, int timeBetweenPackets) { |
64 |
|
_timeBetweenPackets = timeBetweenPackets * 10; |
65 |
< |
setMaximum(_timeBetweenPackets); |
65 |
> |
_progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, _timeBetweenPackets); |
66 |
> |
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
67 |
> |
JLabel label = new JLabel(name); |
68 |
> |
this.add(_progressBar); |
69 |
> |
this.add(label); |
70 |
|
} |
71 |
+ |
|
72 |
+ |
//---PUBLIC METHODS--- |
73 |
|
|
74 |
+ |
/** |
75 |
+ |
* Updates the progress bar every 10th of a second. |
76 |
+ |
*/ |
77 |
|
public void run() { |
78 |
< |
while(running) { |
78 |
> |
while(_running) { |
79 |
|
try { |
80 |
|
Thread.sleep(100); |
81 |
|
} catch (InterruptedException e) { |
83 |
|
|
84 |
|
SwingUtilities.invokeLater(new Runnable() { |
85 |
|
public void run() { |
86 |
< |
PacketTimer.this.setValue(PacketTimer.this.getValue() - 1); |
86 |
> |
_progressBar.setValue(_progressBar.getValue() - 1); |
87 |
|
} |
88 |
|
}); |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
+ |
/** |
93 |
+ |
* Resets the progress bar. |
94 |
+ |
*/ |
95 |
|
public void reset() { |
96 |
|
SwingUtilities.invokeLater(new Runnable() { |
97 |
|
public void run() { |
98 |
< |
PacketTimer.this.setValue(_timeBetweenPackets); |
98 |
> |
_progressBar.setValue(_timeBetweenPackets); |
99 |
|
} |
100 |
|
}); |
101 |
|
} |
102 |
|
|
103 |
+ |
//---PRIVATE METHODS--- |
104 |
+ |
|
105 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
106 |
+ |
|
107 |
+ |
//---ATTRIBUTES--- |
108 |
+ |
|
109 |
+ |
/** |
110 |
+ |
* Holds the time between packets as used internally by this class |
111 |
+ |
*/ |
112 |
|
private int _timeBetweenPackets; |
113 |
< |
private boolean running = true; |
113 |
> |
|
114 |
> |
/** |
115 |
> |
* Used to indicate the state of the thread |
116 |
> |
*/ |
117 |
> |
private boolean _running = true; |
118 |
> |
|
119 |
> |
private JProgressBar _progressBar; |
120 |
> |
|
121 |
> |
//---STATIC ATTRIBUTES--- |
122 |
> |
|
123 |
|
} |