|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectplugins.adufour.vars.lang.Var<T>
T
- The type of the inner (boxed) valuepublic class Var<T>
Top-level class defining a generic variable. A Var
object embeds an inner value of
generic type T, and offers a number of methods to get/set this value, hide the inner value with a
virtual reference to another compatible Var
object, and listen to value or reference
changes via the VarListener
interface.
parse(String)
method should be overridden to provide the ability to read
text input (either from a graphical interface or when saving/reading data from XML files).getValueAsString()
method returns a pretty-printed version of the variable's
value, and is used to display and store the value into XML files. Overriding implementations
should make sure that the result of this method is compatible with the parse(String)
method to ensure proper reloading from XML files.isAssignableFrom(Var)
indicates which types of variables can be used as
reference variables. The default implementation relies on the native
Class.isAssignableFrom(Class)
method, but can be overridden to fine-tune the type of
supported data (see the VarGenericArray.isAssignableFrom(Var)
method for an example).createVarEditor()
method is responsible for generating a VarEditor
object that will handle user interaction in a graphical user interface. For each variable type, a
default VarEditor
is provided, but overriding implementation can provide their own
component.
VarEditor
Field Summary | |
---|---|
protected java.util.List<VarListener<T>> |
listeners
|
static java.lang.String |
NO_VALUE
User-friendly representation of the Java null keyword |
protected java.lang.Class<T> |
type
The Class definition describing the type of the variable value |
static java.lang.String |
XML_KEY_ID
Attribute key defining the unique identifier of a variable. |
Constructor Summary | |
---|---|
Var(java.lang.String name,
java.lang.Class<T> type)
Creates a new Var iable with specified name and inner value type (the default value is
set to null). |
|
Var(java.lang.String name,
java.lang.Class<T> type,
T defaultValue)
Creates a new Var iable with the specified name, and inner value type and default
value (may be null). |
|
Var(java.lang.String name,
T defaultValue)
Creates a new Var iable with given name and non-null default value. |
|
Var(java.lang.String name,
VarEditorModel<T> editorModel)
Creates a new Var iable with the specified name and editor model. |
Method Summary | |
---|---|
void |
addListener(VarListener<T> listener)
Adds the specified listener to the list of registered listeners |
VarEditor<T> |
createVarEditor()
Creates a new VarEditor object that allows the user to graphically adjust the value
of this variable. |
VarEditor<T> |
createVarViewer()
Creates a new VarEditor object that allows the user to view the value of this
variable (but not necessarily modify it). |
protected void |
fireVariableChanged(T oldValue,
T newValue)
|
protected void |
fireVariableChanged(Var<? extends T> oldRef,
Var<? extends T> newRef)
|
VarEditorModel<T> |
getDefaultEditorModel()
|
T |
getDefaultValue()
|
java.lang.Iterable<Var<? super T>> |
getIterableReferrers()
|
java.lang.String |
getName()
|
Var<? extends T> |
getReference()
|
VarReferencingPolicy |
getReferencingPolicy()
|
java.util.Iterator<Var<? super T>> |
getReferrers()
|
java.lang.Class<T> |
getType()
|
java.lang.String |
getTypeAsString()
|
T |
getValue()
|
T |
getValue(boolean forbidNull)
|
java.lang.String |
getValueAsString()
|
java.lang.String |
getValueAsString(boolean followReference)
|
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 |
boolean |
isEnabled()
|
boolean |
isOptional()
|
boolean |
isReferenced()
|
boolean |
loadFromXML(org.w3c.dom.Node node)
|
T |
parse(java.lang.String text)
Parses the given String into the current type |
java.lang.String |
prettyPrint(java.lang.String separator)
|
void |
referenceChanged(Var<T> source,
Var<? extends T> oldReference,
Var<? extends T> newReference)
Called when the variable reference changes |
void |
removeListener(VarListener<T> listener)
Removes the specified listener from the list of registered listeners. |
void |
removeListeners()
Removes all listeners currently registered to this variable. |
boolean |
saveToXML(org.w3c.dom.Node node)
Saves the current variable to the specified node |
void |
setDefaultEditorModel(VarEditorModel<T> model)
Sets a default VarEditorModel object which can be used to generate a graphical editor
for this variable. |
void |
setEnabled(boolean enabled)
Indicates whether this variable should be used or not by plug-ins. |
void |
setOptional(boolean optional)
Sets a flag indicating whether this variable should be considered "optional". |
void |
setReference(Var<T> variable)
Sets the current variable to reference the specified variable (or null to release the reference). |
void |
setReferencingPolicy(VarReferencingPolicy policy)
Sets whether this variable may or may not reference another one. |
void |
setValue(T newValue)
Sets the value of this variable and notify the listeners. |
java.lang.String |
toString()
|
void |
valueChanged(Var<T> source,
T oldValue,
T newValue)
Called when this variable has a non-null reference and receives a value-changed event from this reference |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String XML_KEY_ID
XMLPersistent
mechanism to save/load the variable value to/from XML files.
public static final java.lang.String NO_VALUE
null
keyword
protected java.lang.Class<T> type
Class
definition describing the type of the variable value
protected final java.util.List<VarListener<T>> listeners
Constructor Detail |
---|
public Var(java.lang.String name, T defaultValue) throws java.lang.NullPointerException
Var
iable with given name and non-null default value.
name
- the name of this variabledefaultValue
- the non-null default value of this variable
java.lang.NullPointerException
- if defaultValue
is nullpublic Var(java.lang.String name, java.lang.Class<T> type)
Var
iable with specified name and inner value type (the default value is
set to null).
name
- the name of this variabletype
- the type of this variablepublic Var(java.lang.String name, VarEditorModel<T> editorModel)
Var
iable with the specified name and editor model.
name
- the name of this variableeditorModel
- the default editor model of this variable (can be changed later via the
setDefaultEditorModel(VarEditorModel)
methodpublic Var(java.lang.String name, java.lang.Class<T> type, T defaultValue)
Var
iable with the specified name, and inner value type and default
value (may be null).
name
- the name of this variabletype
- the type of this variableMethod Detail |
---|
public void addListener(VarListener<T> listener)
listener
- the listener to registerpublic VarEditor<T> createVarEditor()
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.
public VarEditor<T> createVarViewer()
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
protected void fireVariableChanged(Var<? extends T> oldRef, Var<? extends T> newRef)
protected void fireVariableChanged(T oldValue, T newValue)
public VarEditorModel<T> getDefaultEditorModel()
public T getDefaultValue()
public java.lang.String getName()
public Var<? extends T> getReference()
getValue()
public java.util.Iterator<Var<? super T>> getReferrers()
public java.lang.Iterable<Var<? super T>> getIterableReferrers()
public boolean isEnabled()
true
if this variable should be used by plug-ins, or false
if it should not be usedpublic boolean isOptional()
true
if this variable has been flagged as "optional" by the user, e.g.
optional parameterspublic boolean isReferenced()
true
if at least one variable is referencing this variable,
false
otherwisepublic java.lang.Class<T> getType()
Class
object defining the type of the variable's value.public java.lang.String getTypeAsString()
Class.getSimpleName()
method).public T getValue()
getValue(boolean)
method instead.getReference()
public T getValue(boolean forbidNull) throws VarException
forbidNull
- true to throw an exception if the underlying value is null
VarException
if the
forbidNull
argument is true
VarException
getReference()
public java.lang.String getValueAsString(boolean followReference)
followReference
- set to true to return the String representation of the reference variable (if any)
parse(String)
method to ensure proper reloading from XML
files.public java.lang.String getValueAsString()
parse(String)
method to ensure proper reloading from XML files.public boolean isAssignableFrom(Var<?> source)
source
-
public boolean loadFromXML(org.w3c.dom.Node node)
loadFromXML
in interface icy.file.xml.XMLPersistent
public T parse(java.lang.String text)
text
-
java.lang.UnsupportedOperationException
- if the parser has not been implemented for the current typepublic java.lang.String prettyPrint(java.lang.String separator)
separator
- Separator character used if value
is an array
value
.public void removeListener(VarListener<T> listener)
listener
- the listener to removepublic void removeListeners()
public boolean saveToXML(org.w3c.dom.Node node) throws java.lang.UnsupportedOperationException
saveToXML
in interface icy.file.xml.XMLPersistent
java.lang.UnsupportedOperationException
- if the functionality is not supported by the current variable typepublic void setDefaultEditorModel(VarEditorModel<T> model)
VarEditorModel
object which can be used to generate a graphical editor
for this variable. This default model is used by the createVarEditor()
method is
overridden to provide a custom editor
model
- the model used by the createVarEditor()
method to generate the
appropriate graphical componentVarEditorModel
public void setOptional(boolean optional)
optional
- true
to indicate that this variable is optionalpublic void setEnabled(boolean enabled)
setOptional(boolean)
enabled
- true
if this variable can be used by plug-ins, and false
if the variable should not be used by plug-ins during computationspublic void setReference(Var<T> variable) throws java.lang.ClassCastException
getValue()
method will disregard the
local value and return the value of the referenced variable
variable
- the variable to reference
java.lang.ClassCastException
- if the two arguments are incompatible and cannot be linkedpublic void setReferencingPolicy(VarReferencingPolicy policy)
true
policy
- the new referencing policyVarReferencingPolicy
public VarReferencingPolicy getReferencingPolicy()
public void setValue(T newValue) throws java.lang.IllegalAccessError, java.lang.IllegalArgumentException
newValue
-
java.lang.IllegalAccessError
- if this variable is already linked to another one
java.lang.IllegalArgumentException
- if this variable has a non-null editor model and the specified value is not valid
for this modelpublic java.lang.String toString()
toString
in class java.lang.Object
public void valueChanged(Var<T> source, T oldValue, T newValue)
valueChanged
in interface VarListener<T>
source
- the variable sending the event. This should be equal to the result of
getReference()
oldValue
- the old variable valuenewValue
- the new variable valuepublic void referenceChanged(Var<T> source, Var<? extends T> oldReference, Var<? extends T> newReference)
VarListener
referenceChanged
in interface VarListener<T>
source
- the variable firing the listeneroldReference
- the old variable referencenewReference
- the new variable reference
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |