ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/PacketTimer.java
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/PacketTimer.java (file contents):
Revision 1.7 by tdb, Tue May 21 16:47:10 2002 UTC vs.
Revision 1.8 by tdb, Thu Mar 6 12:15:52 2003 UTC

# Line 22 | Line 22
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;
# Line 36 | Line 37 | import javax.swing.SwingUtilities;
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   */
# Line 61 | Line 59 | public class PacketTimer extends JPanel implements Run
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);
# Line 83 | Line 82 | public class PacketTimer extends JPanel implements Run
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          }
# Line 93 | Line 99 | public class PacketTimer extends JPanel implements Run
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      }
# Line 110 | Line 118 | public class PacketTimer extends JPanel implements Run
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines