001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: AudioClipViewer.java,v $ 023 Revision 1.4 2004/05/12 19:13:43 markl 024 comment block updates 025 026 Revision 1.3 2003/01/19 09:50:52 markl 027 Javadoc & comment header updates. 028 029 Revision 1.2 2001/03/12 09:27:52 markl 030 Source code and Javadoc cleanup. 031 032 Revision 1.1 1999/06/03 06:50:40 markl 033 Initial revision 034 ---------------------------------------------------------------------------- 035*/ 036 037package kiwi.ui; 038 039import java.awt.*; 040import java.awt.event.*; 041import javax.swing.*; 042 043import kiwi.util.*; 044 045/** An implementation of <code>UIElementViewer</code> for previewing 046 * audio clips. The viewer consists of <i>Play</i> and <i>Stop</i> buttons, 047 * for playing and stopping the audio clip, respectively. 048 * 049 * @author Mark Lindner 050 */ 051 052public class AudioClipViewer extends KPanel implements UIElementViewer, 053 ActionListener 054 { 055 private KButton b_play, b_stop; 056 private AudioClip clip = null; 057 058 /** Construct a new <code>AudioClipViewer</code>. 059 */ 060 061 public AudioClipViewer() 062 { 063 setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); 064 065 ResourceManager rm = KiwiUtils.getResourceManager(); 066 067 b_play = new KButton(rm.getIcon("play.gif")); 068 b_play.addActionListener(this); 069 add(b_play); 070 071 b_stop = new KButton(rm.getIcon("stop.gif")); 072 b_stop.addActionListener(this); 073 add(b_stop); 074 } 075 076 /** Get a reference to the viewer component. 077 * 078 * @return The viewer component. 079 */ 080 081 public JComponent getViewerComponent() 082 { 083 return(this); 084 } 085 086 /** Show the specified element. 087 * 088 * @param element An object, assumed to be an instance of 089 * <code>AudioClip</code>, to display. 090 */ 091 092 public void showElement(UIElement element) 093 { 094 Object obj = element.getObject(); 095 096 if(obj instanceof AudioClip) 097 { 098 if(clip != null) 099 clip.stop(); 100 101 clip = (AudioClip)obj; 102 } 103 } 104 105 /** This method is public as an implementation side-effect. 106 */ 107 108 public void actionPerformed(ActionEvent evt) 109 { 110 if(clip == null) 111 return; 112 113 Object o = evt.getSource(); 114 115 if(o == b_play) 116 clip.play(); 117 118 else if(o == b_stop) 119 clip.stop(); 120 } 121 122 } 123 124/* end of source file */