FileDocCategorySizeDatePackage
EnumControl.javaAPI DocJava SE 5 API5377Fri Aug 26 14:57:50 BST 2005javax.sound.sampled

EnumControl

public abstract class EnumControl extends Control
A EnumControl provides control over a set of discrete possible values, each represented by an object. In a graphical user interface, such a control might be represented by a set of buttons, each of which chooses one value or setting. For example, a reverb control might provide several preset reverberation settings, instead of providing continuously adjustable parameters of the sort that would be represented by {@link FloatControl} objects.

Controls that provide a choice between only two settings can often be implemented instead as a {@link BooleanControl}, and controls that provide a set of values along some quantifiable dimension might be implemented instead as a FloatControl with a coarse resolution. However, a key feature of EnumControl is that the returned values are arbitrary objects, rather than numerical or boolean values. This means that each returned object can provide further information. As an example, the settings of a {@link EnumControl.Type#REVERB REVERB} control are instances of {@link ReverbType} that can be queried for the parameter values used for each setting.

author
Kara Kytle
version
1.14, 03/12/19
since
1.3

Fields Summary
private Object[]
values
The set of possible values.
private Object
value
The current value.
Constructors Summary
protected EnumControl(Type type, Object[] values, Object value)
Constructs a new enumerated control object with the given parameters.

param
type the type of control represented this enumerated control object
param
values the set of possible values for the control
param
value the initial control value

	
	super(type);
	
	this.values = values;
	this.value = value;
    
Methods Summary
public java.lang.ObjectgetValue()
Obtains this control's current value.

return
the current value

	return value;
    
public java.lang.Object[]getValues()
Returns the set of possible values for this control.

return
the set of possible values

	
	Object[] localArray = new Object[values.length];
	
	for (int i = 0; i < values.length; i++) {
	    localArray[i] = values[i];
	}
	
	return localArray;
    
private booleanisValueSupported(java.lang.Object value)
Indicates whether the value specified is supported.

param
value the value for which support is queried
return
true if the value is supported, otherwise false

	
	for (int i = 0; i < values.length; i++) {
	    //$$fb 2001-07-20: Fix for bug 4400392: setValue() in ReverbControl always throws Exception
	    //if (values.equals(values[i])) {
	    if (value.equals(values[i])) {
		return true;
	    }
	}
	
	return false;
    
public voidsetValue(java.lang.Object value)
Sets the current value for the control. The default implementation simply sets the value as indicated. If the value indicated is not supported, an IllegalArgumentException is thrown. Some controls require that their line be open before they can be affected by setting a value.

param
value the desired new value
throws
IllegalArgumentException if the value indicated does not fall within the allowable range

	if (!isValueSupported(value)) {
	    throw new IllegalArgumentException("Requested value " + value + " is not supported.");
	}
	
	this.value = value;
    
public java.lang.StringtoString()
Provides a string representation of the control.

return
a string description

	return new String(getType() + " with current value: " + getValue());