com.ryanm.config.imp
Class AbstractConfigurator

java.lang.Object
  extended by com.ryanm.config.imp.AbstractConfigurator
All Implemented Interfaces:
Configurator
Direct Known Subclasses:
AnnotatedConfigurator, GLMaterialConfigurator, SpeckPosition.Configurator, StringSink.StringSinkConfigurator

public abstract class AbstractConfigurator
extends java.lang.Object
implements Configurator

Eases implementation of a configurator. Handles all requirements of a configurator, subclasses need only concern themselves with defining variables, and getting/setting values.

Author:
ryanm

Field Summary
 
Fields inherited from interface com.ryanm.config.Configurator
ACTION_TYPE, BOOLEAN_TYPE, COLOUR_TYPE, FILE_TYPE, FLOAT_TYPE, INT_TYPE, STRING_LIST_TYPE, STRING_TYPE, VECTOR_TYPE
 
Constructor Summary
  AbstractConfigurator(java.lang.String name)
          Constructs a new AbstractConfigurator
protected AbstractConfigurator(java.lang.String name, java.lang.String description)
          Constructs a new AbstractConfigurator
 
Method Summary
 void addConfiguratorListener(ConfiguratorListener listener)
          Registers a ConfiguratorListener to this configuration.
 void addValueListener(ValueListener listener)
          Registers a ValueListener to this configuration.
 void addVariable(Configurator conf)
          Adds a sub-configurator
 void addVariable(java.lang.String variable)
          Adds a variable to this configurator
protected abstract  void applyValue(java.lang.String name, java.lang.Object value)
          This should be overridden to actually apply the new value
 void buildPaths()
          This should be called on the root configurator to build configurator path information
static void copyValues(Configurator source, Configurator sink)
          Sets the values of the sink Configurator's variables to be the same as the source Configurator.
 java.lang.String getDescription()
          Gets a descriptive string for this Configurator
 java.lang.String getDescription(java.lang.String name)
          Gets a descriptive string for a variable, such as could be put in a tooltip
 java.lang.String getName()
          Gets the name of this configurator.
 java.lang.Object[] getNames()
          Gets the names of all configurable variables.
 Configurator getParent()
          Gets a reference to the Configurator that contains this configurator.
 java.lang.String getPath()
          Gets a "/" separated sequence of configurator names that lead to this configurator
 java.lang.Object getRange(java.lang.String name)
          Gets an object that describes the range for a variable.
 java.lang.Class getType(java.lang.String name)
          Gets the type of a given variable
 java.lang.Object getValue(java.lang.String name)
          Gets the current value of a variable.
 boolean isGUIEnabled(java.lang.String variable)
          Gets the status of a variable's widgets, vis-a-vis enablement
 boolean pathsBuilt()
          Determines whether or not the paths have been built for this configurator
 void removeConfiguratorListener(ConfiguratorListener listener)
          Removes a ConfiguratorListener.
 void removeValueListener(ValueListener listener)
          Removes a ValueListener.
 void removeVariable(java.lang.Object variable)
          Removes a variable or subconfigurator from this configurator
abstract  java.lang.Object retrieveValue(java.lang.String name)
          Get the current value of the named variable
 void setDescription(java.lang.String name, java.lang.String desc)
          Sets the description for a variable
 void setGUIEnabled(java.lang.String variable, boolean b, java.lang.Object key)
          Enables or disables any widgets associated with a particular variable.
 void setRange(java.lang.String name, java.lang.Object bounds)
          Sets the bounds for a variable.
 void setType(java.lang.String name, java.lang.Class type)
          Sets the type of a variable
 void setValue(java.lang.String name, java.lang.Object value)
          Sets the value of a variable
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractConfigurator

public AbstractConfigurator(java.lang.String name)
Constructs a new AbstractConfigurator

Parameters:
name - The name for this configurator

AbstractConfigurator

protected AbstractConfigurator(java.lang.String name,
                               java.lang.String description)
Constructs a new AbstractConfigurator

Parameters:
name - The name for this configurator
description - A decsriptive string for this configurator
Method Detail

getName

public final java.lang.String getName()
Description copied from interface: Configurator
Gets the name of this configurator. This name must not contain any "/", "#" or ":" characters

Specified by:
getName in interface Configurator
Returns:
the name of this configurator

getNames

public java.lang.Object[] getNames()
Description copied from interface: Configurator
Gets the names of all configurable variables. The array of objects returned can consist of two types:

Specified by:
getNames in interface Configurator
Returns:
A list of Objects defining the variables and sub-configurators

addVariable

public void addVariable(java.lang.String variable)
Adds a variable to this configurator

Parameters:
variable - The name of the variable, or the Configurator object itself, to add

addVariable

public void addVariable(Configurator conf)
Adds a sub-configurator

Parameters:
conf - The configurator to add

removeVariable

public void removeVariable(java.lang.Object variable)
Removes a variable or subconfigurator from this configurator

Parameters:
variable - The name of the variable, or the configurator object, to remove

getType

public java.lang.Class getType(java.lang.String name)
Description copied from interface: Configurator
Gets the type of a given variable

Specified by:
getType in interface Configurator
Parameters:
name - The name of the variable
Returns:
The type of the variable, or null if no type has been set

setType

public void setType(java.lang.String name,
                    java.lang.Class type)
Sets the type of a variable

Parameters:
name - The name of the variable to set
type - The type identifier of the variable

getDescription

public java.lang.String getDescription(java.lang.String name)
Description copied from interface: Configurator
Gets a descriptive string for a variable, such as could be put in a tooltip

Specified by:
getDescription in interface Configurator
Parameters:
name - The variable to describe
Returns:
A descriptive string for the variable

getDescription

public java.lang.String getDescription()
Description copied from interface: Configurator
Gets a descriptive string for this Configurator

Specified by:
getDescription in interface Configurator
Returns:
A descriptive String for the configurator

setDescription

public void setDescription(java.lang.String name,
                           java.lang.String desc)
Sets the description for a variable

Parameters:
name - The name of the variable to describe
desc - The description for the variable

getRange

public java.lang.Object getRange(java.lang.String name)
Description copied from interface: Configurator
Gets an object that describes the range for a variable. This will be different for different types of variables. A numerical variable could have a 2-element array describing the min and max values, a String variable could have a list of possible values, a file type could have a list of acceptable file suffixes.

Specified by:
getRange in interface Configurator
Parameters:
name - The variable to get the range for
Returns:
An object describing the range

setRange

public void setRange(java.lang.String name,
                     java.lang.Object bounds)
Sets the bounds for a variable. Permissable types to pass a s a range object are null, String[] and float[]. How these bounds are interpreted is dependent on the variable type. See the type flags in Configurator for examples of the default types

Parameters:
name - The variable to constrain
bounds - The bounds object

setValue

public final void setValue(java.lang.String name,
                           java.lang.Object value)
Description copied from interface: Configurator
Sets the value of a variable

Specified by:
setValue in interface Configurator
Parameters:
name - The name of the variable to set
value - The new value of that variable

applyValue

protected abstract void applyValue(java.lang.String name,
                                   java.lang.Object value)
This should be overridden to actually apply the new value

Parameters:
name - The name of the variable to change
value - The new value of that variable

getValue

public java.lang.Object getValue(java.lang.String name)
Description copied from interface: Configurator
Gets the current value of a variable.

Specified by:
getValue in interface Configurator
Parameters:
name - The name of the variable to inspect
Returns:
The current value of the variable

retrieveValue

public abstract java.lang.Object retrieveValue(java.lang.String name)
Get the current value of the named variable

Parameters:
name - The name of the variable
Returns:
The value of the variable

getPath

public java.lang.String getPath()
Description copied from interface: Configurator
Gets a "/" separated sequence of configurator names that lead to this configurator

Specified by:
getPath in interface Configurator
Returns:
the path to this configurator

addValueListener

public void addValueListener(ValueListener listener)
Description copied from interface: Configurator
Registers a ValueListener to this configuration. All listeners should be notified whenever a variable is changed.

Specified by:
addValueListener in interface Configurator
Parameters:
listener - The listener to add

removeValueListener

public void removeValueListener(ValueListener listener)
Description copied from interface: Configurator
Removes a ValueListener. The specified listener will no longer receive notification about variable changes.

Specified by:
removeValueListener in interface Configurator
Parameters:
listener - The listener to remove

addConfiguratorListener

public void addConfiguratorListener(ConfiguratorListener listener)
Description copied from interface: Configurator
Registers a ConfiguratorListener to this configuration. All listeners should be notified whenever the Configurator is altered

Specified by:
addConfiguratorListener in interface Configurator
Parameters:
listener - The listener to add

removeConfiguratorListener

public void removeConfiguratorListener(ConfiguratorListener listener)
Description copied from interface: Configurator
Removes a ConfiguratorListener. The specified listener will no longer receive notification about Configurator changes

Specified by:
removeConfiguratorListener in interface Configurator
Parameters:
listener - The listener to remove

setGUIEnabled

public void setGUIEnabled(java.lang.String variable,
                          boolean b,
                          java.lang.Object key)
Description copied from interface: Configurator
Enables or disables any widgets associated with a particular variable. When a variable is disabled with a particular key object, it cannot be enabled again without using the same key object.

Specified by:
setGUIEnabled in interface Configurator
Parameters:
variable - The name of the variable to alter
b - true to enable, false to disable
key - The locking object

isGUIEnabled

public boolean isGUIEnabled(java.lang.String variable)
Description copied from interface: Configurator
Gets the status of a variable's widgets, vis-a-vis enablement

Specified by:
isGUIEnabled in interface Configurator
Parameters:
variable - The variable to query
Returns:
true if enabled, false otherwise

getParent

public Configurator getParent()
Description copied from interface: Configurator
Gets a reference to the Configurator that contains this configurator.

Specified by:
getParent in interface Configurator
Returns:
The parent configurator, or null if this is a root configurator

buildPaths

public void buildPaths()
This should be called on the root configurator to build configurator path information


pathsBuilt

public boolean pathsBuilt()
Determines whether or not the paths have been built for this configurator

Returns:
true if the paths have been built, false otherwise

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

copyValues

public static void copyValues(Configurator source,
                              Configurator sink)
Sets the values of the sink Configurator's variables to be the same as the source Configurator. Variables with the same name will have their values copied accross. This process will recurse into sub-configurators

Parameters:
source - The source of the configuration
sink - The configurator to change