001: package com.xoetrope.swing;
002:
003: import com.xoetrope.carousel.build.BuildProperties;
004: import java.applet.Applet;
005: import java.applet.AudioClip;
006: import java.io.IOException;
007:
008: import javax.swing.JComponent;
009: import net.xoetrope.debug.DebugLogger;
010: import net.xoetrope.xui.XAttributedComponent;
011: import net.xoetrope.xui.XProject;
012: import net.xoetrope.xui.XProjectManager;
013:
014: /**
015: * A component capable of playing audio clips
016: *
017: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
018: * the GNU Public License (GPL), please see license.txt for more details. If
019: * you make commercial use of this software you must purchase a commercial
020: * license from Xoetrope.</p>
021: * <p> $Revision: 1.10 $</p>
022: */
023: public class XAudio extends JComponent implements XAttributedComponent {
024: /**
025: * The owner project and the context in which this object operates.
026: */
027: protected XProject currentProject = XProjectManager
028: .getCurrentProject();
029:
030: /**
031: * Create a new audio component
032: */
033: public XAudio() {
034: setOpaque(false);
035: }
036:
037: /**
038: * Performs any post creation initialisation of the control.
039: * @throws java.io.IOException problems were encountered while trying to initailize the component. This component's init method actually does nothing
040: */
041: public void init() throws IOException {
042: }
043:
044: /**
045: * Set one or more attributes of the component.
046: * @param attribName the name of the attribute
047: * <ul>
048: *<li>content - the file name of the audio clip</li>
049: *</ul>
050: * @param attribValue the value of the attribute
051: * @return 0 for success, non zero otherwise
052: */
053: public int setAttribute(String attribName, Object attribValue) {
054: String attribNameLwr = attribName.toLowerCase();
055: if (attribNameLwr.equals("content")
056: || attribNameLwr.equals("value"))
057: setValue((String) attribValue);
058:
059: return 0;
060: }
061:
062: /**
063: * Sets the image at the specified index.
064: * The index is forced to be in the range of valid images and
065: * if no images exist then no action is taken.
066: * @param _fileName the name of the new image.
067: */
068: public void setValue(String _fileName) {
069: if (_fileName != null) {
070: fileName = _fileName;
071: try {
072: ac = Applet.newAudioClip(currentProject
073: .findResource(fileName));
074: } catch (Exception e) {
075: if (BuildProperties.DEBUG)
076: DebugLogger
077: .logError("Unable to load the audio clip: "
078: + _fileName);
079:
080: ac = null;
081: }
082: }
083: }
084:
085: /**
086: * Gets the image at the specified index.
087: * The index is forced to be in the range of valid images and
088: * if no images exist then no action is taken.
089: * @return the file name
090: */
091: public String getValue() {
092: return fileName;
093: }
094:
095: /**
096: * Starts the sound playback
097: */
098: public void start() {
099: if (ac != null)
100: ac.play();
101: }
102:
103: /**
104: * Starts the continuous sound playback
105: */
106: public void loop() {
107: if (ac != null)
108: ac.loop();
109: }
110:
111: /**
112: * Stops the playback.
113: */
114: public void stop() {
115: if (ac != null)
116: ac.stop();
117: }
118:
119: private int zOrder = 3;
120:
121: private String fileName = " ";
122: private AudioClip ac;
123:
124: // Original coordinates.
125: private int oX, oY, oW, oH;
126: static final long serialVersionUID = -3675838130865645852L;
127: }
|