001 /*
002 * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.sound.sampled;
027
028 /**
029 * A <code>BooleanControl</code> provides the ability to switch between
030 * two possible settings that affect a line's audio. The settings are boolean
031 * values (<code>true</code> and <code>false</code>). A graphical user interface
032 * might represent the control by a two-state button, an on/off switch, two
033 * mutually exclusive buttons, or a checkbox (among other possibilities).
034 * For example, depressing a button might activate a
035 * <code>{@link BooleanControl.Type#MUTE MUTE}</code> control to silence
036 * the line's audio.
037 * <p>
038 * As with other <code>{@link Control}</code> subclasses, a method is
039 * provided that returns string labels for the values, suitable for
040 * display in the user interface.
041 *
042 * @author Kara Kytle
043 * @version 1.22, 07/05/05
044 * @since 1.3
045 */
046 public abstract class BooleanControl extends Control {
047
048 // INSTANCE VARIABLES
049
050 /**
051 * The <code>true</code> state label, such as "true" or "on."
052 */
053 private final String trueStateLabel;
054
055 /**
056 * The <code>false</code> state label, such as "false" or "off."
057 */
058 private final String falseStateLabel;
059
060 /**
061 * The current value.
062 */
063 private boolean value;
064
065 // CONSTRUCTORS
066
067 /**
068 * Constructs a new boolean control object with the given parameters.
069 *
070 * @param type the type of control represented this float control object
071 * @param initialValue the initial control value
072 * @param trueStateLabel the label for the state represented by <code>true</code>,
073 * such as "true" or "on."
074 * @param falseStateLabel the label for the state represented by <code>false</code>,
075 * such as "false" or "off."
076 */
077 protected BooleanControl(Type type, boolean initialValue,
078 String trueStateLabel, String falseStateLabel) {
079
080 super (type);
081 this .value = initialValue;
082 this .trueStateLabel = trueStateLabel;
083 this .falseStateLabel = falseStateLabel;
084 }
085
086 /**
087 * Constructs a new boolean control object with the given parameters.
088 * The labels for the <code>true</code> and <code>false</code> states
089 * default to "true" and "false."
090 *
091 * @param type the type of control represented by this float control object
092 * @param initialValue the initial control value
093 */
094 protected BooleanControl(Type type, boolean initialValue) {
095 this (type, initialValue, "true", "false");
096 }
097
098 // METHODS
099
100 /**
101 * Sets the current value for the control. The default
102 * implementation simply sets the value as indicated.
103 * Some controls require that their line be open before they can be affected
104 * by setting a value.
105 * @param value desired new value.
106 */
107 public void setValue(boolean value) {
108 this .value = value;
109 }
110
111 /**
112 * Obtains this control's current value.
113 * @return current value.
114 */
115 public boolean getValue() {
116 return value;
117 }
118
119 /**
120 * Obtains the label for the specified state.
121 * @return the label for the specified state, such as "true" or "on"
122 * for <code>true</code>, or "false" or "off" for <code>false</code>.
123 */
124 public String getStateLabel(boolean state) {
125 return ((state == true) ? trueStateLabel : falseStateLabel);
126 }
127
128 // ABSTRACT METHOD IMPLEMENTATIONS: CONTROL
129
130 /**
131 * Provides a string representation of the control
132 * @return a string description
133 */
134 public String toString() {
135 return new String(super .toString() + " with current value: "
136 + getStateLabel(getValue()));
137 }
138
139 // INNER CLASSES
140
141 /**
142 * An instance of the <code>BooleanControl.Type</code> class identifies one kind of
143 * boolean control. Static instances are provided for the
144 * common types.
145 *
146 * @author Kara Kytle
147 * @version 1.22, 07/05/05
148 * @since 1.3
149 */
150 public static class Type extends Control.Type {
151
152 // TYPE DEFINES
153
154 /**
155 * Represents a control for the mute status of a line.
156 * Note that mute status does not affect gain.
157 */
158 public static final Type MUTE = new Type("Mute");
159
160 /**
161 * Represents a control for whether reverberation is applied
162 * to a line. Note that the status of this control not affect
163 * the reverberation settings for a line, but does affect whether
164 * these settings are used.
165 */
166 public static final Type APPLY_REVERB = new Type("Apply Reverb");
167
168 // CONSTRUCTOR
169
170 /**
171 * Constructs a new boolean control type.
172 * @param name the name of the new boolean control type
173 */
174 protected Type(String name) {
175 super (name);
176 }
177 } // class Type
178 }
|