X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2FAudioListener.java;fp=src%2Ftim%2Fprune%2Fgui%2FAudioListener.java;h=6bf3ffe56f4bfde148bf1b4a37e269f5f8cd6286;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/gui/AudioListener.java b/src/tim/prune/gui/AudioListener.java new file mode 100644 index 0000000..6bf3ffe --- /dev/null +++ b/src/tim/prune/gui/AudioListener.java @@ -0,0 +1,52 @@ +package tim.prune.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JProgressBar; + +import tim.prune.FunctionLibrary; +import tim.prune.function.PlayAudioFunction; + +/** + * Class to update the supplied progress bar on the basis of + * the currently playing audio clip (if any) + */ +public class AudioListener implements Runnable, ActionListener +{ + /** progress bar */ + private JProgressBar _progressBar = null; + + /** + * Constructor + * @param inBar progress bar object to update + */ + public AudioListener(JProgressBar inBar) { + _progressBar = inBar; + } + + /** + * React to button press + */ + public void actionPerformed(ActionEvent inEvent) { + new Thread(this).start(); + } + + /** + * Loop and update progress bar + */ + public void run() + { + int progress = 0; + while (progress >= 0) + { + try { + Thread.sleep(400); + } + catch (InterruptedException e) {} + progress = ((PlayAudioFunction) FunctionLibrary.FUNCTION_PLAY_AUDIO).getPercentage(); + _progressBar.setVisible(progress >= 0); + _progressBar.setValue(progress); + } + } +}