KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > sampled > BooleanControl


1 /*
2  * @(#)BooleanControl.java 1.15 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sound.sampled;
9
10 /**
11  * A <code>BooleanControl</code> provides the ability to switch between
12  * two possible settings that affect a line's audio. The settings are boolean
13  * values (<code>true</code> and <code>false</code>). A graphical user interface
14  * might represent the control by a two-state button, an on/off switch, two
15  * mutually exclusive buttons, or a checkbox (among other possibilities).
16  * For example, depressing a button might activate a
17  * <code>{@link BooleanControl.Type#MUTE MUTE}</code> control to silence
18  * the line's audio.
19  * <p>
20  * As with other <code>{@link Control}</code> subclasses, a method is
21  * provided that returns string labels for the values, suitable for
22  * display in the user interface.
23  *
24  * @author Kara Kytle
25  * @version 1.15, 03/12/19
26  * @since 1.3
27  */

28 public abstract class BooleanControl extends Control JavaDoc {
29     
30     
31     // INSTANCE VARIABLES
32

33     /**
34      * The <code>true</code> state label, such as "true" or "on."
35      */

36     private final String JavaDoc trueStateLabel;
37     
38     /**
39      * The <code>false</code> state label, such as "false" or "off."
40      */

41     private final String JavaDoc falseStateLabel;
42     
43     /**
44      * The current value.
45      */

46     private boolean value;
47     
48     
49     // CONSTRUCTORS
50

51     
52     /**
53      * Constructs a new boolean control object with the given parameters.
54      *
55      * @param type the type of control represented this float control object
56      * @param initialValue the initial control value
57      * @param trueStateLabel the label for the state represented by <code>true</code>,
58      * such as "true" or "on."
59      * @param falseStateLabel the label for the state represented by <code>false</code>,
60      * such as "false" or "off."
61      */

62     protected BooleanControl(Type type, boolean initialValue, String JavaDoc trueStateLabel, String JavaDoc falseStateLabel) {
63     
64     super(type);
65     this.value = initialValue;
66     this.trueStateLabel = trueStateLabel;
67     this.falseStateLabel = falseStateLabel;
68     }
69     
70     
71     /**
72      * Constructs a new boolean control object with the given parameters.
73      * The labels for the <code>true</code> and <code>false</code> states
74      * default to "true" and "false."
75      *
76      * @param type the type of control represented by this float control object
77      * @param initialValue the initial control value
78      */

79     protected BooleanControl(Type type, boolean initialValue) {
80     this(type, initialValue, "true", "false");
81     }
82     
83     
84     // METHODS
85

86     
87     /**
88      * Sets the current value for the control. The default
89      * implementation simply sets the value as indicated.
90      * Some controls require that their line be open before they can be affected
91      * by setting a value.
92      * @param value desired new value.
93      */

94     public void setValue(boolean value) {
95     this.value = value;
96     }
97     
98     
99     
100     /**
101      * Obtains this control's current value.
102      * @return current value.
103      */

104     public boolean getValue() {
105     return value;
106     }
107     
108     
109     /**
110      * Obtains the label for the specified state.
111      * @return the label for the specified state, such as "true" or "on"
112      * for <code>true</code>, or "false" or "off" for <code>false</code>.
113      */

114     public String JavaDoc getStateLabel(boolean state) {
115     return ((state == true) ? trueStateLabel : falseStateLabel);
116     }
117     
118     
119     
120     // ABSTRACT METHOD IMPLEMENTATIONS: CONTROL
121

122     
123     /**
124      * Provides a string representation of the control
125      * @return a string description
126      */

127     public String JavaDoc toString() {
128     return new String JavaDoc(super.toString() + " with current value: " + getStateLabel(getValue()));
129     }
130     
131     
132     // INNER CLASSES
133

134     
135     /**
136      * An instance of the <code>BooleanControl.Type</code> class identifies one kind of
137      * boolean control. Static instances are provided for the
138      * common types.
139      *
140      * @author Kara Kytle
141      * @version 1.15, 03/12/19
142      * @since 1.3
143      */

144     public static class Type extends Control.Type JavaDoc {
145     
146     
147     // TYPE DEFINES
148

149     
150     /**
151      * Represents a control for the mute status of a line.
152      * Note that mute status does not affect gain.
153      */

154     public static final Type MUTE = new Type("Mute");
155     
156     /**
157      * Represents a control for whether reverberation is applied
158      * to a line. Note that the status of this control not affect
159      * the reverberation settings for a line, but does affect whether
160      * these settings are used.
161      */

162     public static final Type APPLY_REVERB = new Type("Apply Reverb");
163     
164     
165     // CONSTRUCTOR
166

167     
168     /**
169      * Constructs a new boolean control type.
170      * @param name the name of the new boolean control type
171      */

172     protected Type(String JavaDoc name) {
173         super(name);
174     }
175     } // class Type
176
}
177
Popular Tags