1 /*
   2  * Copyright (c) 1999, 2014, 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  * {@link Line Lines} often have a set of controls, such as gain and pan, that
  30  * affect the audio signal passing through the line. Java Sound's {@code Line}
  31  * objects let you obtain a particular control object by passing its class as
  32  * the argument to a {@link Line#getControl(Control.Type) getControl} method.
  33  * <p>
  34  * Because the various types of controls have different purposes and features,
  35  * all of their functionality is accessed from the subclasses that define each
  36  * kind of control.
  37  *
  38  * @author Kara Kytle
  39  * @see Line#getControls
  40  * @see Line#isControlSupported
  41  * @since 1.3
  42  */
  43 public abstract class Control {
  44 
  45     /**
  46      * The control type.
  47      */
  48     private final Type type;
  49 
  50     /**
  51      * Constructs a Control with the specified type.
  52      *
  53      * @param  type the kind of control desired
  54      */
  55     protected Control(Type type) {
  56         this.type = type;
  57     }
  58 
  59     /**
  60      * Obtains the control's type.
  61      *
  62      * @return the control's type
  63      */
  64     public Type getType() {
  65         return type;
  66     }
  67 
  68     /**
  69      * Obtains a String describing the control type and its current state.
  70      *
  71      * @return a String representation of the Control
  72      */
  73     @Override
  74     public String toString() {
  75         return new String(getType() + " Control");
  76     }
  77 
  78     /**
  79      * An instance of the {@code Type} class represents the type of the control.
  80      * Static instances are provided for the common types.
  81      */
  82     public static class Type {
  83 
  84         /**
  85          * Type name.
  86          */
  87         private String name;
  88 
  89         /**
  90          * Constructs a new control type with the name specified. The name
  91          * should be a descriptive string appropriate for labelling the control
  92          * in an application, such as "Gain" or "Balance".
  93          *
  94          * @param  name the name of the new control type
  95          */
  96         protected Type(String name) {
  97             this.name = name;
  98         }
  99 
 100         /**
 101          * Finalizes the equals method.
 102          */
 103         @Override
 104         public final boolean equals(Object obj) {
 105             return super.equals(obj);
 106         }
 107 
 108         /**
 109          * Finalizes the hashCode method.
 110          */
 111         @Override
 112         public final int hashCode() {
 113             return super.hashCode();
 114         }
 115 
 116         /**
 117          * Provides the {@code String} representation of the control type. This
 118          * {@code String} is the same name that was passed to the constructor.
 119          *
 120          * @return the control type name
 121          */
 122         @Override
 123         public final String toString() {
 124             return name;
 125         }
 126     }
 127 }