1 /* 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.sound.sampled; 27 28 /** 29 * A <code>BooleanControl</code> provides the ability to switch between 30 * two possible settings that affect a line's audio. The settings are boolean 31 * values (<code>true</code> and <code>false</code>). A graphical user interface 32 * might represent the control by a two-state button, an on/off switch, two 33 * mutually exclusive buttons, or a checkbox (among other possibilities). 34 * For example, depressing a button might activate a 35 * <code>{@link BooleanControl.Type#MUTE MUTE}</code> control to silence 36 * the line's audio. 37 * <p> 38 * As with other <code>{@link Control}</code> subclasses, a method is 39 * provided that returns string labels for the values, suitable for 40 * display in the user interface. 41 * 42 * @author Kara Kytle 43 * @since 1.3 44 */ 45 public abstract class BooleanControl extends Control { 46 47 48 // INSTANCE VARIABLES 49 50 /** 51 * The <code>true</code> state label, such as "true" or "on." 52 */ 53 private final String trueStateLabel; 54 55 /** 56 * The <code>false</code> state label, such as "false" or "off." 57 */ 58 private final String falseStateLabel; 59 60 /** 61 * The current value. 62 */ 63 private boolean value; 64 65 66 // CONSTRUCTORS 67 68 69 /** 70 * Constructs a new boolean control object with the given parameters. 71 * 72 * @param type the type of control represented this float control object 73 * @param initialValue the initial control value 74 * @param trueStateLabel the label for the state represented by <code>true</code>, 75 * such as "true" or "on." 76 * @param falseStateLabel the label for the state represented by <code>false</code>, 77 * such as "false" or "off." 78 */ 79 protected BooleanControl(Type type, boolean initialValue, String trueStateLabel, String falseStateLabel) { 80 81 super(type); 82 this.value = initialValue; 83 this.trueStateLabel = trueStateLabel; 84 this.falseStateLabel = falseStateLabel; 85 } 86 87 88 /** 89 * Constructs a new boolean control object with the given parameters. 90 * The labels for the <code>true</code> and <code>false</code> states 91 * default to "true" and "false." 92 * 93 * @param type the type of control represented by this float control object 94 * @param initialValue the initial control value 95 */ 96 protected BooleanControl(Type type, boolean initialValue) { 97 this(type, initialValue, "true", "false"); 98 } 99 100 101 // METHODS 102 103 104 /** 105 * Sets the current value for the control. The default 106 * implementation simply sets the value as indicated. 107 * Some controls require that their line be open before they can be affected 108 * by setting a value. 109 * @param value desired new value. 110 */ 111 public void setValue(boolean value) { 112 this.value = value; 113 } 114 115 116 117 /** 118 * Obtains this control's current value. 119 * @return current value. 120 */ 121 public boolean getValue() { 122 return value; 123 } 124 125 126 /** 127 * Obtains the label for the specified state. 128 * @param state the state whose label will be returned 129 * @return the label for the specified state, such as "true" or "on" 130 * for <code>true</code>, or "false" or "off" for <code>false</code>. 131 */ 132 public String getStateLabel(boolean state) { 133 return ((state == true) ? trueStateLabel : falseStateLabel); 134 } 135 136 137 138 // ABSTRACT METHOD IMPLEMENTATIONS: CONTROL 139 140 141 /** 142 * Provides a string representation of the control 143 * @return a string description 144 */ 145 public String toString() { 146 return new String(super.toString() + " with current value: " + getStateLabel(getValue())); 147 } 148 149 150 // INNER CLASSES 151 152 153 /** 154 * An instance of the <code>BooleanControl.Type</code> class identifies one kind of 155 * boolean control. Static instances are provided for the 156 * common types. 157 * 158 * @author Kara Kytle 159 * @since 1.3 160 */ 161 public static class Type extends Control.Type { 162 163 164 // TYPE DEFINES 165 166 167 /** 168 * Represents a control for the mute status of a line. 169 * Note that mute status does not affect gain. 170 */ 171 public static final Type MUTE = new Type("Mute"); 172 173 /** 174 * Represents a control for whether reverberation is applied 175 * to a line. Note that the status of this control not affect 176 * the reverberation settings for a line, but does affect whether 177 * these settings are used. 178 */ 179 public static final Type APPLY_REVERB = new Type("Apply Reverb"); 180 181 182 // CONSTRUCTOR 183 184 185 /** 186 * Constructs a new boolean control type. 187 * @param name the name of the new boolean control type 188 */ 189 protected Type(String name) { 190 super(name); 191 } 192 } // class Type 193 }