jdk/src/java.desktop/share/classes/javax/sound/sampled/EnumControl.java
author serb
Mon, 15 Aug 2016 20:08:55 +0300
changeset 40444 afabcfc2f3ef
parent 38986 5b96e2b155eb
permissions -rw-r--r--
8163949: Cleanup of classes which are related to JavaSound Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.sampled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
38986
5b96e2b155eb 8157322: Several typos in javadoc
dmarkov
parents: 25859
diff changeset
    29
 * An {@code EnumControl} provides control over a set of discrete possible
5b96e2b155eb 8157322: Several typos in javadoc
dmarkov
parents: 25859
diff changeset
    30
 * values, each represented by an object. In a graphical user interface, such a
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    31
 * control might be represented by a set of buttons, each of which chooses one
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    32
 * value or setting. For example, a reverb control might provide several preset
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    33
 * reverberation settings, instead of providing continuously adjustable
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    34
 * parameters of the sort that would be represented by {@link FloatControl}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    37
 * Controls that provide a choice between only two settings can often be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    38
 * implemented instead as a {@link BooleanControl}, and controls that provide a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    39
 * set of values along some quantifiable dimension might be implemented instead
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    40
 * as a {@code FloatControl} with a coarse resolution. However, a key feature of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    41
 * {@code EnumControl} is that the returned values are arbitrary objects, rather
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    42
 * than numerical or boolean values. This means that each returned object can
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    43
 * provide further information. As an example, the settings of a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    44
 * {@link EnumControl.Type#REVERB REVERB} control are instances of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    45
 * {@link ReverbType} that can be queried for the parameter values used for each
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    46
 * setting.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public abstract class EnumControl extends Control {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * The set of possible values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
40444
afabcfc2f3ef 8163949: Cleanup of classes which are related to JavaSound
serb
parents: 38986
diff changeset
    56
    private final Object[] values;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * The current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Constructs a new enumerated control object with the given parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    66
     * @param  type the type of control represented this enumerated control
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    67
     *         object
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    68
     * @param  values the set of possible values for the control
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    69
     * @param  value the initial control value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected EnumControl(Type type, Object[] values, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.values = values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    78
     * Sets the current value for the control. The default implementation simply
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    79
     * sets the value as indicated. If the value indicated is not supported, an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    80
     * {@code IllegalArgumentException} is thrown. Some controls require that
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    81
     * their line be open before they can be affected by setting a value.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    82
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    83
     * @param  value the desired new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @throws IllegalArgumentException if the value indicated does not fall
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    85
     *         within the allowable range
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (!isValueSupported(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new IllegalArgumentException("Requested value " + value + " is not supported.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Obtains this control's current value.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
    97
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Returns the set of possible values for this control.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   106
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return the set of possible values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public Object[] getValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        Object[] localArray = new Object[values.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        for (int i = 0; i < values.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            localArray[i] = values[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return localArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Indicates whether the value specified is supported.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   122
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   123
     * @param  value the value for which support is queried
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   124
     * @return {@code true} if the value is supported, otherwise {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private boolean isValueSupported(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        for (int i = 0; i < values.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            //$$fb 2001-07-20: Fix for bug 4400392: setValue() in ReverbControl always throws Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            //if (values.equals(values[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if (value.equals(values[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Provides a string representation of the control.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   141
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return a string description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   144
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return new String(getType() + " with current value: " + getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   150
     * An instance of the {@code EnumControl.Type} inner class identifies one
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   151
     * kind of enumerated control. Static instances are provided for the common
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   152
     * types.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @author Kara Kytle
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   155
     * @see EnumControl
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static class Type extends Control.Type {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * Represents a control over a set of possible reverberation settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * Each reverberation setting is described by an instance of the
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   163
         * {@link ReverbType} class. (To access these settings, invoke
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   164
         * {@link EnumControl#getValues} on an enumerated control of type
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   165
         * {@code REVERB}.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        public static final Type REVERB         = new Type("Reverb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         * Constructs a new enumerated control type.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   171
         *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   172
         * @param  name the name of the new enumerated control type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   174
        protected Type(final String name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   177
    }
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 5506
diff changeset
   178
}