plugins.adufour.vars.lang
Class VarMutable

java.lang.Object
  extended by plugins.adufour.vars.lang.Var
      extended by plugins.adufour.vars.lang.VarMutable
All Implemented Interfaces:
icy.file.xml.XMLPersistent, MutableType, VarListener
Direct Known Subclasses:
VarMutableArray

public class VarMutable
extends Var
implements MutableType

Variable holding a value with mutable type, i.e. its type may be changed at runtime

Author:
Alexandre Dufour

Field Summary
 
Fields inherited from class plugins.adufour.vars.lang.Var
NO_VALUE, type, XML_KEY_ID
 
Constructor Summary
VarMutable(java.lang.String name, java.lang.Class<?> initialType)
          Constructs a new mutable variable with specified name and type.
 
Method Summary
 void addTypeChangeListener(TypeChangeListener listener)
           
 VarEditor createVarEditor()
          Creates a new VarEditor object that allows the user to graphically adjust the value of this variable.
 VarEditor createVarViewer()
          Creates a new VarEditor object that allows the user to view the value of this variable (but not necessarily modify it).
 boolean isAssignableFrom(Var source)
          Checks whether the type of the given variable is equal or extends this variable's type.
If the result is true, then the given variable can become a link source for this variable
 void removeTypeChangeListener(TypeChangeListener listener)
           
 void setDefaultEditorModel(VarEditorModel model)
          Sets a default VarEditorModel object which can be used to generate a graphical editor for this variable.
 void setReference(Var variable)
          Sets the current variable to reference the specified variable (or null to release the reference).
 void setType(java.lang.Class<?> newType)
           
 void setValue(java.lang.Object newValue)
          Sets the value of this variable and notify the listeners.
 
Methods inherited from class plugins.adufour.vars.lang.Var
addListener, fireVariableChanged, fireVariableChanged, getDefaultEditorModel, getDefaultValue, getIterableReferrers, getName, getReference, getReferencingPolicy, getReferrers, getType, getTypeAsString, getValue, getValue, getValueAsString, getValueAsString, isEnabled, isOptional, isReferenced, loadFromXML, parse, prettyPrint, referenceChanged, removeListener, removeListeners, saveToXML, setEnabled, setOptional, setReferencingPolicy, toString, valueChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VarMutable

public VarMutable(java.lang.String name,
                  java.lang.Class<?> initialType)
Constructs a new mutable variable with specified name and type. The default value for mutable variables is always null, in order to be reset properly

Parameters:
name -
initialType - the type of variable to handle (this can be changed via the setType(Class) method
Method Detail

createVarEditor

public VarEditor createVarEditor()
Description copied from class: Var
Creates a new VarEditor object that allows the user to graphically adjust the value of this variable. By default this editor is an empty label for generic types, but this method can be overridden to provide a custom editor.

Overrides:
createVarEditor in class Var
Returns:
the variable editor embarking the graphical component

createVarViewer

public VarEditor createVarViewer()
Description copied from class: Var
Creates a new VarEditor object that allows the user to view the value of this variable (but not necessarily modify it). By default this editor is an empty label for generic types, but this method can be overridden to provide a custom viewer

Overrides:
createVarViewer in class Var
Returns:
the variable editor embarking the graphical component

addTypeChangeListener

public void addTypeChangeListener(TypeChangeListener listener)
Specified by:
addTypeChangeListener in interface MutableType

removeTypeChangeListener

public void removeTypeChangeListener(TypeChangeListener listener)
Specified by:
removeTypeChangeListener in interface MutableType

isAssignableFrom

public boolean isAssignableFrom(Var source)
Description copied from class: Var
Checks whether the type of the given variable is equal or extends this variable's type.
If the result is true, then the given variable can become a link source for this variable

Overrides:
isAssignableFrom in class Var
Returns:
true if the source type is equal or wider than this variable's type, false otherwise (including if source has null type)

setDefaultEditorModel

public void setDefaultEditorModel(VarEditorModel model)
Description copied from class: Var
Sets a default VarEditorModel object which can be used to generate a graphical editor for this variable. This default model is used by the Var.createVarEditor() method is overridden to provide a custom editor

Overrides:
setDefaultEditorModel in class Var
Parameters:
model - the model used by the Var.createVarEditor() method to generate the appropriate graphical component
See Also:
VarEditorModel

setType

public void setType(java.lang.Class<?> newType)
Specified by:
setType in interface MutableType

setValue

public void setValue(java.lang.Object newValue)
Description copied from class: Var
Sets the value of this variable and notify the listeners. This method can only be called if this variable is not referencing another one.

Overrides:
setValue in class Var

setReference

public void setReference(Var variable)
                  throws java.lang.ClassCastException
Description copied from class: Var
Sets the current variable to reference the specified variable (or null to release the reference). If the reference is non-null, the Var.getValue() method will disregard the local value and return the value of the referenced variable

Overrides:
setReference in class Var
Parameters:
variable - the variable to reference
Throws:
java.lang.ClassCastException - if the two arguments are incompatible and cannot be linked