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
Revision: 1.4
Committed: Fri Mar 16 17:52:00 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Changes since 1.3: +16 -8 lines
Log Message:
Moved and labelled the packet timer

File Contents

# User Rev Content
1 ajm 1.2 //---PACKAGE DECLARATION---
2 ajm 1.3 package uk.org.iscream.conient;
3 ajm 1.1
4 ajm 1.2 //---IMPORTS---
5 ajm 1.1 import javax.swing.JProgressBar;
6 ajm 1.4 import javax.swing.JPanel;
7     import javax.swing.JLabel;
8     import javax.swing.BoxLayout;
9 ajm 1.1 import javax.swing.SwingUtilities;
10    
11 ajm 1.2 /**
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 ajm 1.3 * @author $Author: ajm4 $
23 ajm 1.4 * @version $Id: PacketTimer.java,v 1.3 2001/03/15 01:05:46 ajm4 Exp $
24 ajm 1.2 */
25 ajm 1.4 public class PacketTimer extends JPanel implements Runnable {
26 ajm 1.1
27 ajm 1.2 //---FINAL ATTRIBUTES---
28    
29     /**
30     * The current CVS revision of this class
31     */
32 ajm 1.4 public static final String REVISION = "$Revision: 1.3 $";
33 ajm 1.2
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 ajm 1.4 public PacketTimer(String name, int timeBetweenPackets) {
44 ajm 1.1 _timeBetweenPackets = timeBetweenPackets * 10;
45 ajm 1.4 _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 ajm 1.1 }
51 ajm 1.2
52     //---PUBLIC METHODS---
53 ajm 1.1
54 ajm 1.2 /**
55     * Updates the progress bar every 10th of a second.
56     */
57 ajm 1.1 public void run() {
58 ajm 1.2 while(_running) {
59 ajm 1.1 try {
60     Thread.sleep(100);
61     } catch (InterruptedException e) {
62     }
63    
64     SwingUtilities.invokeLater(new Runnable() {
65     public void run() {
66 ajm 1.4 _progressBar.setValue(_progressBar.getValue() - 1);
67 ajm 1.1 }
68     });
69     }
70     }
71    
72 ajm 1.2 /**
73     * Resets the progress bar.
74     */
75 ajm 1.1 public void reset() {
76     SwingUtilities.invokeLater(new Runnable() {
77     public void run() {
78 ajm 1.4 _progressBar.setValue(_timeBetweenPackets);
79 ajm 1.1 }
80     });
81     }
82    
83 ajm 1.2 //---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 ajm 1.1 private int _timeBetweenPackets;
93 ajm 1.2
94     /**
95     * Used to indicate the state of the thread
96     */
97     private boolean _running = true;
98 ajm 1.4
99     private JProgressBar _progressBar;
100 ajm 1.2
101     //---STATIC ATTRIBUTES---
102    
103 ajm 1.1 }