Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/sampled/BooleanControl.java
38918 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.sampled;2627/**28* A <code>BooleanControl</code> provides the ability to switch between29* two possible settings that affect a line's audio. The settings are boolean30* values (<code>true</code> and <code>false</code>). A graphical user interface31* might represent the control by a two-state button, an on/off switch, two32* mutually exclusive buttons, or a checkbox (among other possibilities).33* For example, depressing a button might activate a34* <code>{@link BooleanControl.Type#MUTE MUTE}</code> control to silence35* the line's audio.36* <p>37* As with other <code>{@link Control}</code> subclasses, a method is38* provided that returns string labels for the values, suitable for39* display in the user interface.40*41* @author Kara Kytle42* @since 1.343*/44public abstract class BooleanControl extends Control {454647// INSTANCE VARIABLES4849/**50* The <code>true</code> state label, such as "true" or "on."51*/52private final String trueStateLabel;5354/**55* The <code>false</code> state label, such as "false" or "off."56*/57private final String falseStateLabel;5859/**60* The current value.61*/62private boolean value;636465// CONSTRUCTORS666768/**69* Constructs a new boolean control object with the given parameters.70*71* @param type the type of control represented this float control object72* @param initialValue the initial control value73* @param trueStateLabel the label for the state represented by <code>true</code>,74* such as "true" or "on."75* @param falseStateLabel the label for the state represented by <code>false</code>,76* such as "false" or "off."77*/78protected BooleanControl(Type type, boolean initialValue, String trueStateLabel, String falseStateLabel) {7980super(type);81this.value = initialValue;82this.trueStateLabel = trueStateLabel;83this.falseStateLabel = falseStateLabel;84}858687/**88* Constructs a new boolean control object with the given parameters.89* The labels for the <code>true</code> and <code>false</code> states90* default to "true" and "false."91*92* @param type the type of control represented by this float control object93* @param initialValue the initial control value94*/95protected BooleanControl(Type type, boolean initialValue) {96this(type, initialValue, "true", "false");97}9899100// METHODS101102103/**104* Sets the current value for the control. The default105* implementation simply sets the value as indicated.106* Some controls require that their line be open before they can be affected107* by setting a value.108* @param value desired new value.109*/110public void setValue(boolean value) {111this.value = value;112}113114115116/**117* Obtains this control's current value.118* @return current value.119*/120public boolean getValue() {121return value;122}123124125/**126* Obtains the label for the specified state.127* @param state the state whose label will be returned128* @return the label for the specified state, such as "true" or "on"129* for <code>true</code>, or "false" or "off" for <code>false</code>.130*/131public String getStateLabel(boolean state) {132return ((state == true) ? trueStateLabel : falseStateLabel);133}134135136137// ABSTRACT METHOD IMPLEMENTATIONS: CONTROL138139140/**141* Provides a string representation of the control142* @return a string description143*/144public String toString() {145return new String(super.toString() + " with current value: " + getStateLabel(getValue()));146}147148149// INNER CLASSES150151152/**153* An instance of the <code>BooleanControl.Type</code> class identifies one kind of154* boolean control. Static instances are provided for the155* common types.156*157* @author Kara Kytle158* @since 1.3159*/160public static class Type extends Control.Type {161162163// TYPE DEFINES164165166/**167* Represents a control for the mute status of a line.168* Note that mute status does not affect gain.169*/170public static final Type MUTE = new Type("Mute");171172/**173* Represents a control for whether reverberation is applied174* to a line. Note that the status of this control not affect175* the reverberation settings for a line, but does affect whether176* these settings are used.177*/178public static final Type APPLY_REVERB = new Type("Apply Reverb");179180181// CONSTRUCTOR182183184/**185* Constructs a new boolean control type.186* @param name the name of the new boolean control type187*/188protected Type(String name) {189super(name);190}191} // class Type192}193194195