Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/sampled/EnumControl.java
38918 views
/*1* Copyright (c) 1999, 2003, 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>EnumControl</code> provides control over a set of29* discrete possible values, each represented by an object. In a30* graphical user interface, such a control might be represented31* by a set of buttons, each of which chooses one value or setting. For32* example, a reverb control might provide several preset reverberation33* settings, instead of providing continuously adjustable parameters34* of the sort that would be represented by <code>{@link FloatControl}</code>35* objects.36* <p>37* Controls that provide a choice between only two settings can often be implemented38* instead as a <code>{@link BooleanControl}</code>, and controls that provide39* a set of values along some quantifiable dimension might be implemented40* instead as a <code>FloatControl</code> with a coarse resolution.41* However, a key feature of <code>EnumControl</code> is that the returned values42* are arbitrary objects, rather than numerical or boolean values. This means that each43* returned object can provide further information. As an example, the settings44* of a <code>{@link EnumControl.Type#REVERB REVERB}</code> control are instances of45* <code>{@link ReverbType}</code> that can be queried for the parameter values46* used for each setting.47*48* @author Kara Kytle49* @since 1.350*/51public abstract class EnumControl extends Control {525354// TYPE DEFINES555657// INSTANCE VARIABLES585960/**61* The set of possible values.62*/63private Object[] values;646566/**67* The current value.68*/69private Object value;70717273// CONSTRUCTORS747576/**77* Constructs a new enumerated control object with the given parameters.78*79* @param type the type of control represented this enumerated control object80* @param values the set of possible values for the control81* @param value the initial control value82*/83protected EnumControl(Type type, Object[] values, Object value) {8485super(type);8687this.values = values;88this.value = value;89}90919293// METHODS949596/**97* Sets the current value for the control. The default implementation98* simply sets the value as indicated. If the value indicated is not99* supported, an IllegalArgumentException is thrown.100* Some controls require that their line be open before they can be affected101* by setting a value.102* @param value the desired new value103* @throws IllegalArgumentException if the value indicated does not fall104* within the allowable range105*/106public void setValue(Object value) {107if (!isValueSupported(value)) {108throw new IllegalArgumentException("Requested value " + value + " is not supported.");109}110111this.value = value;112}113114115/**116* Obtains this control's current value.117* @return the current value118*/119public Object getValue() {120return value;121}122123124/**125* Returns the set of possible values for this control.126* @return the set of possible values127*/128public Object[] getValues() {129130Object[] localArray = new Object[values.length];131132for (int i = 0; i < values.length; i++) {133localArray[i] = values[i];134}135136return localArray;137}138139140/**141* Indicates whether the value specified is supported.142* @param value the value for which support is queried143* @return <code>true</code> if the value is supported,144* otherwise <code>false</code>145*/146private boolean isValueSupported(Object value) {147148for (int i = 0; i < values.length; i++) {149//$$fb 2001-07-20: Fix for bug 4400392: setValue() in ReverbControl always throws Exception150//if (values.equals(values[i])) {151if (value.equals(values[i])) {152return true;153}154}155156return false;157}158159160161// ABSTRACT METHOD IMPLEMENTATIONS: CONTROL162163164/**165* Provides a string representation of the control.166* @return a string description167*/168public String toString() {169return new String(getType() + " with current value: " + getValue());170}171172173// INNER CLASSES174175176/**177* An instance of the <code>EnumControl.Type</code> inner class identifies one kind of178* enumerated control. Static instances are provided for the179* common types.180*181* @see EnumControl182*183* @author Kara Kytle184* @since 1.3185*/186public static class Type extends Control.Type {187188189// TYPE DEFINES190191/**192* Represents a control over a set of possible reverberation settings.193* Each reverberation setting is described by an instance of the194* {@link ReverbType} class. (To access these settings,195* invoke <code>{@link EnumControl#getValues}</code> on an196* enumerated control of type <code>REVERB</code>.)197*/198public static final Type REVERB = new Type("Reverb");199200201// CONSTRUCTOR202203204/**205* Constructs a new enumerated control type.206* @param name the name of the new enumerated control type207*/208protected Type(String name) {209super(name);210}211} // class Type212213} // class EnumControl214215216