jdk/src/share/classes/javax/sound/sampled/BooleanControl.java
author darcy
Thu, 05 Jun 2014 23:17:05 -0700
changeset 25131 49006bd0e69d
parent 25128 2dfdfa369071
permissions -rw-r--r--
8044553: Fix raw and unchecked lint warnings in javax.sound.* 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: 19207
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
/**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    29
 * A {@code BooleanControl} provides the ability to switch between two possible
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    30
 * settings that affect a line's audio. The settings are boolean values
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    31
 * ({@code true} and {@code false}). A graphical user interface might represent
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    32
 * the control by a two-state button, an on/off switch, two mutually exclusive
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    33
 * buttons, or a checkbox (among other possibilities). For example, depressing a
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    34
 * button might activate a {@link BooleanControl.Type#MUTE MUTE} control to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    35
 * silence the line's audio.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    37
 * As with other {@code Control} subclasses, a method is provided that returns
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    38
 * string labels for the values, suitable for display in the user interface.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public abstract class BooleanControl extends Control {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    46
     * The {@code true} state label, such as "true" or "on".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private final String trueStateLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    51
     * The {@code false} state label, such as "false" or "off".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final String falseStateLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private boolean value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Constructs a new boolean control object with the given parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    63
     * @param  type the type of control represented this float control object
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    64
     * @param  initialValue the initial control value
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    65
     * @param  trueStateLabel the label for the state represented by
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    66
     *         {@code true}, such as "true" or "on"
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    67
     * @param  falseStateLabel the label for the state represented by
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    68
     *         {@code false}, such as "false" or "off"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected BooleanControl(Type type, boolean initialValue, String trueStateLabel, String falseStateLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.value = initialValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.trueStateLabel = trueStateLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.falseStateLabel = falseStateLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    79
     * Constructs a new boolean control object with the given parameters. The
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    80
     * labels for the {@code true} and {@code false} states default to "true"
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    81
     * and "false".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    83
     * @param  type the type of control represented by this float control object
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    84
     * @param  initialValue the initial control value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected BooleanControl(Type type, boolean initialValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this(type, initialValue, "true", "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    91
     * Sets the current value for the control. The default implementation simply
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    92
     * sets the value as indicated. Some controls require that their line be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    93
     * open before they can be affected by setting a value.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    94
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
    95
     * @param  value desired new value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public void setValue(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Obtains this control's current value.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   103
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   104
     * @return current value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public boolean getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Obtains the label for the specified state.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   112
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   113
     * @param  state the state whose label will be returned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   114
     * @return the label for the specified state, such as "true" or "on" for
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   115
     *         {@code true}, or "false" or "off" for {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public String getStateLabel(boolean state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return ((state == true) ? trueStateLabel : falseStateLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   122
     * Provides a string representation of the control.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   123
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return a string description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   126
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return new String(super.toString() + " with current value: " + getStateLabel(getValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   132
     * An instance of the {@code BooleanControl.Type} class identifies one kind
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   133
     * of boolean control. Static instances are provided for the common types.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public static class Type extends Control.Type {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   141
         * Represents a control for the mute status of a line. Note that mute
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   142
         * status does not affect gain.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        public static final Type MUTE                           = new Type("Mute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   147
         * Represents a control for whether reverberation is applied to a line.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   148
         * Note that the status of this control not affect the reverberation
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   149
         * settings for a line, but does affect whether these settings are used.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        public static final Type APPLY_REVERB           = new Type("Apply Reverb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * Constructs a new boolean control type.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   155
         *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   156
         * @param name the name of the new boolean control type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   158
        protected Type(final String name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 19207
diff changeset
   161
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}