]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/AudioListener.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / gui / AudioListener.java
1 package tim.prune.gui;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5
6 import javax.swing.JProgressBar;
7
8 import tim.prune.FunctionLibrary;
9 import tim.prune.function.PlayAudioFunction;
10
11 /**
12  * Class to update the supplied progress bar on the basis of
13  * the currently playing audio clip (if any)
14  */
15 public class AudioListener implements Runnable, ActionListener
16 {
17         /** progress bar */
18         private JProgressBar _progressBar = null;
19
20         /**
21          * Constructor
22          * @param inBar progress bar object to update
23          */
24         public AudioListener(JProgressBar inBar) {
25                 _progressBar = inBar;
26         }
27
28         /**
29          * React to button press
30          */
31         public void actionPerformed(ActionEvent inEvent) {
32                 new Thread(this).start();
33         }
34
35         /**
36          * Loop and update progress bar
37          */
38         public void run()
39         {
40                 int progress = 0;
41                 while (progress >= 0)
42                 {
43                         try {
44                                 Thread.sleep(400);
45                         }
46                         catch (InterruptedException e) {}
47                         progress = ((PlayAudioFunction) FunctionLibrary.FUNCTION_PLAY_AUDIO).getPercentage();
48                         _progressBar.setVisible(progress >= 0);
49                         _progressBar.setValue(progress);
50                 }
51         }
52 }