]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/gui/StatusBar.java
Version 20, March 2020
[GpsPrune.git] / src / tim / prune / gui / StatusBar.java
1 package tim.prune.gui;
2
3 import java.awt.FlowLayout;
4
5 import javax.swing.BorderFactory;
6 import javax.swing.JLabel;
7 import javax.swing.JPanel;
8 import tim.prune.DataSubscriber;
9
10 /**
11  * Class to act as a status bar for the application
12  */
13 public class StatusBar extends JPanel implements Runnable, DataSubscriber
14 {
15         /** Label for displaying the text */
16         private JLabel _label = null;
17         /** timer for clearing the status */
18         private long _timer = 0L;
19         /** thread for clearing the status */
20         private Thread _thread = null;
21
22         /** Number of milliseconds until status text cleared */
23         private static final long DEFAULT_CLEAR_INTERVAL = 1000L * 4;
24
25
26         /**
27          * Constructor
28          */
29         public StatusBar()
30         {
31                 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
32                 setBorder(BorderFactory.createLoweredBevelBorder());
33                 _label = new JLabel(" ");
34                 _label.setFont(_label.getFont().deriveFont(8));
35                 add(_label);
36         }
37
38         /**
39          * Run method, to check if text should be deleted
40          * @see java.lang.Runnable#run()
41          */
42         public void run()
43         {
44                 while (System.currentTimeMillis() < _timer) {
45                         try {
46                                 Thread.sleep(500);
47                         }
48                         catch (InterruptedException ie) {} // ignore
49                 }
50                 _label.setText(" ");
51         }
52
53         /**
54          * Accept notification that an action has been completed
55          * @param inMessage message to display
56          */
57         public void actionCompleted(String inMessage)
58         {
59                 _label.setText(" " + inMessage);
60                 _timer = System.currentTimeMillis() + DEFAULT_CLEAR_INTERVAL;
61                 // If necessary, start a new checker thread
62                 if (_thread == null || !_thread.isAlive())
63                 {
64                         _thread = new Thread(this);
65                         _thread.start();
66                 }
67         }
68
69         /**
70          * Ignore signals about updated data
71          * @param inUpdateType update type
72          */
73         public void dataUpdated(byte inUpdateType)
74         {
75         }
76 }