--- projects/cms/source/conient/uk/org/iscream/cms/conient/PacketTimer.java 2002/05/21 16:47:10 1.7 +++ projects/cms/source/conient/uk/org/iscream/cms/conient/PacketTimer.java 2003/03/06 12:15:52 1.8 @@ -22,6 +22,7 @@ package uk.org.iscream.cms.conient; //---IMPORTS--- +import java.awt.Color; import javax.swing.JProgressBar; import javax.swing.JPanel; import javax.swing.JLabel; @@ -36,11 +37,8 @@ import javax.swing.SwingUtilities; * This then displays a JProgress bar which updates at * 10th of a second intervals. * - * It currently is adjusted by the addition of 1 second - * to account for the possibility of network delay. - * * @author $Author: tdb $ - * @version $Id: PacketTimer.java,v 1.7 2002/05/21 16:47:10 tdb Exp $ + * @version $Id: PacketTimer.java,v 1.8 2003/03/06 12:15:52 tdb Exp $ */ public class PacketTimer extends JPanel implements Runnable { @@ -49,7 +47,7 @@ public class PacketTimer extends JPanel implements Run /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.7 $"; + public static final String REVISION = "$Revision: 1.8 $"; //---STATIC METHODS--- @@ -61,8 +59,9 @@ public class PacketTimer extends JPanel implements Run * @param timeBetweenPackets the time in seconds between packet arrival */ public PacketTimer(String name, int timeBetweenPackets) { - _timeBetweenPackets = timeBetweenPackets * 10; + _timeBetweenPackets = timeBetweenPackets * 1000; _progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, _timeBetweenPackets); + _barColour = _progressBar.getForeground(); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JLabel label = new JLabel(name); this.add(_progressBar); @@ -83,7 +82,14 @@ public class PacketTimer extends JPanel implements Run SwingUtilities.invokeLater(new Runnable() { public void run() { - _progressBar.setValue(_progressBar.getValue() - 1); + long t = _nextTime - System.currentTimeMillis(); + if(t >= 0) { + _progressBar.setValue((int) t); + } + else { + _progressBar.setValue((int) (t*-1)); + _progressBar.setForeground(Color.red); + } } }); } @@ -93,9 +99,11 @@ public class PacketTimer extends JPanel implements Run * Resets the progress bar. */ public void reset() { + _nextTime = System.currentTimeMillis() + _timeBetweenPackets; SwingUtilities.invokeLater(new Runnable() { public void run() { _progressBar.setValue(_timeBetweenPackets); + _progressBar.setForeground(_barColour); } }); } @@ -110,6 +118,8 @@ public class PacketTimer extends JPanel implements Run * Holds the time between packets as used internally by this class */ private int _timeBetweenPackets; + private long _nextTime; + private Color _barColour; /** * Used to indicate the state of the thread