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 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 |
|
* |
19 |
– |
* It currently is adjusted by the addition of 1 second |
20 |
– |
* to account for the possibility of network delay. |
21 |
– |
* |
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 |