1 7 8 package javax.sound.sampled; 9 10 35 public abstract class EnumControl extends Control { 36 37 38 40 41 43 44 47 private Object [] values; 48 49 50 53 private Object value; 54 55 56 57 59 60 67 protected EnumControl(Type type, Object [] values, Object value) { 68 69 super(type); 70 71 this.values = values; 72 this.value = value; 73 } 74 75 76 77 79 80 90 public void setValue(Object value) { 91 if (!isValueSupported(value)) { 92 throw new IllegalArgumentException ("Requested value " + value + " is not supported."); 93 } 94 95 this.value = value; 96 } 97 98 99 103 public Object getValue() { 104 return value; 105 } 106 107 108 112 public Object [] getValues() { 113 114 Object [] localArray = new Object [values.length]; 115 116 for (int i = 0; i < values.length; i++) { 117 localArray[i] = values[i]; 118 } 119 120 return localArray; 121 } 122 123 124 130 private boolean isValueSupported(Object value) { 131 132 for (int i = 0; i < values.length; i++) { 133 if (value.equals(values[i])) { 136 return true; 137 } 138 } 139 140 return false; 141 } 142 143 144 145 147 148 152 public String toString() { 153 return new String (getType() + " with current value: " + getValue()); 154 } 155 156 157 159 160 171 public static class Type extends Control.Type { 172 173 174 176 183 public static final Type REVERB = new Type("Reverb"); 184 185 186 188 189 193 protected Type(String name) { 194 super(name); 195 } 196 } 198 } | Popular Tags |