ptolemy.kernel.util
Interface Settable

All Superinterfaces:
Nameable
All Known Subinterfaces:
FileOrURLAccessor, Locatable, ValueIterator
All Known Implementing Classes:
AbstractActionsAttribute, AbstractActionsAttribute, AbstractSettableAttribute, Action, Action, ActionsAttribute, AttributeExpressionAttribute, AttributeValueAttribute, BaseUnit, ChoiceParameter, ColorAttribute, CommitActionsAttribute, CommitActionsAttribute, Commutator.WidthDependentParameter, Commutator.WidthDependentParameter, ConfigurableAttribute, Constraint, ContainerIgnoringAttribute, DebugController, DebuggerParameter, DefaultDirectoryAttribute, DefaultModelAttribute, Distributor.WidthDependentParameter, Distributor.WidthDependentParameter, Documentation, DoubleRangeParameter, Event.EventParameter, ExpertParameter, FileAttribute, FileParameter, FilePortParameter, GraphTransformer.ReplacementObjectAttribute, GTIngredientsAttribute, GTParameter, HierarchyFlatteningAttribute, IntRangeParameter, IterativeParameter, LibraryAttribute, Location, LocationAttribute, LocationParameter, ModelParameter, MonitorReceiverAttribute, NamedObjVariable, NameParameter, OutputActionsAttribute, OutputActionsAttribute, Parameter, ParametersAttribute, PasswordAttribute, PatternObjectAttribute, PortParameter, Priority, PropertyParameter, PtalonExpressionParameter, PtalonParameter, PtinyOSNodeParameter, RelationCollapsingAttribute, RelationHidingAttribute, RequireVersion, SharedParameter, SingletonConfigurableAttribute, SingletonParameter, SizeAttribute, StringAttribute, StringParameter, SynchronizeToRealtime, TableauParameter, TemporaryVariable, TransformationMode, TransientSingletonConfigurableAttribute, TypeAttribute, UnitAttribute, Variable, VersionAttribute, Vertex, WindowPropertiesAttribute

public interface Settable
extends Nameable

This is an interface for attributes that can have their values externally set. An attribute class that implements this interface has to be able to have a value set by a string, via the setExpression() method. A string representation is returned by the getExpression() method. An expression may be an ordinary string with no further interpretation, or it may be a string that needs to be evaluated. In the latter case, an implementation of this attribute may not evaluate the string when the setExpression() method is called. It may instead only evaluate the string when the validate() method is called. Often this will not be called until the value of the expression is actually needed (this is known as "lazy evaluation"). Such an implementation will defer notification of listeners and the container until the string is evaluated. In a typical use of this interface, therefore, it is necessary to be sure that validate() is called sometime after setExpression() is called.

In addition, an attribute class that implements this interface needs to maintain a list of listeners that are informed whenever the value of the attribute changes. It should inform those listeners whenever setExpression() is called.

Among other uses, this interface marks attributes whose value can be set via the value attribute of a MoML property element. For example, if class XXX implements Settable, then the following is valid MoML:

 <property name="xxx" class="XXX" value="yyy"/>
 

This interface also supports annotations that hint to a user interface the level of visibility that an instance should have. The visibility is specified as one of the static instances of the inner class Visibility, currently NONE, EXPERT, FULL, and NOT_EDITABLE NONE indicates that the user should never see the instance, and should not be able to set its value through the user interface. EXPERT means that only expert users should see the instance. FULL means that the instance is always visible, and a user interface should always allow it to be set. NOT_EDITABLE is similar to FULL, except that the value of the expression is visible, but not editable by the user. This is commonly used for feedback from the model.

Since:
Ptolemy II 1.0
Version:
$Id: Settable.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
Accepted Rating:
Green (cxh)
Proposed Rating:
Green (eal)

Nested Class Summary
static class Settable.Visibility
          Inner class used for the static enumeration of indicators of visibility.
 
Field Summary
static Settable.Visibility EXPERT
          Indicator that a user interface should make an instance visible only to experts.
static Settable.Visibility FULL
          Indicator that a user interface should make an instance visible.
static Settable.Visibility NONE
          Indicator that a user interface should not make an instance visible.
static Settable.Visibility NOT_EDITABLE
          Indicator that a user interface should make an instance visible, but not allow editing of the variable.
 
Method Summary
 void addValueListener(ValueListener listener)
          Add a listener to be notified when the value of this settable object changes.
 java.lang.String getDefaultExpression()
          Return the default value of this attribute, if there is one, or null if there is none.
 java.lang.String getDisplayName()
          Return a name to present to the user.
 java.lang.String getExpression()
          Get the expression of the attribute that has been set by setExpression(), or null if there is none.
 java.lang.String getValueAsString()
          Get the value of the attribute, which is the evaluated expression.
 Settable.Visibility getVisibility()
          Get the visibility of this Settable, as set by setVisibility().
 void removeValueListener(ValueListener listener)
          Remove a listener from the list of listeners that are notified when the value of this variable changes.
 void setExpression(java.lang.String expression)
          Set the value of the attribute by giving some expression.
 void setVisibility(Settable.Visibility visibility)
          Set the visibility of this Settable.
 java.util.Collection validate()
          Check the validity of the expression set in setExpression().
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName, setName
 

Field Detail

NONE

static final Settable.Visibility NONE
Indicator that a user interface should not make an instance visible.


EXPERT

static final Settable.Visibility EXPERT
Indicator that a user interface should make an instance visible only to experts.


FULL

static final Settable.Visibility FULL
Indicator that a user interface should make an instance visible.


NOT_EDITABLE

static final Settable.Visibility NOT_EDITABLE
Indicator that a user interface should make an instance visible, but not allow editing of the variable.

Method Detail

addValueListener

void addValueListener(ValueListener listener)
Add a listener to be notified when the value of this settable object changes. An implementation of this method should ignore the call if the specified listener is already on the list of listeners. In other words, it should not be possible for the same listener to be notified twice of a value update.

Parameters:
listener - The listener to add.
See Also:
removeValueListener(ValueListener)

getDefaultExpression

java.lang.String getDefaultExpression()
Return the default value of this attribute, if there is one, or null if there is none.

Returns:
The default value of this attribute, or null if there is none.

getDisplayName

java.lang.String getDisplayName()
Return a name to present to the user.

Specified by:
getDisplayName in interface Nameable
Returns:
A name to present to the user.

getExpression

java.lang.String getExpression()
Get the expression of the attribute that has been set by setExpression(), or null if there is none.

Returns:
The expression.
See Also:
setExpression(String)

getValueAsString

java.lang.String getValueAsString()
Get the value of the attribute, which is the evaluated expression.

Returns:
The value.
See Also:
getExpression()

getVisibility

Settable.Visibility getVisibility()
Get the visibility of this Settable, as set by setVisibility(). If setVisibility() has not been called, then implementations of this interface should return some default, not null, indicating user-level visibility. The returned value is one of the static instances of the Visibility inner class.

Returns:
The visibility of this Settable.
See Also:
setVisibility(Settable.Visibility)

removeValueListener

void removeValueListener(ValueListener listener)
Remove a listener from the list of listeners that are notified when the value of this variable changes. If no such listener exists, do nothing.

Parameters:
listener - The listener to remove.
See Also:
addValueListener(ValueListener)

setExpression

void setExpression(java.lang.String expression)
                   throws IllegalActionException
Set the value of the attribute by giving some expression. In some implementations, the listeners and the container will be notified immediately. However, some implementations may defer notification until validate() is called.

Parameters:
expression - The value of the attribute.
Throws:
IllegalActionException - If the expression is invalid.
See Also:
getExpression()

setVisibility

void setVisibility(Settable.Visibility visibility)
Set the visibility of this Settable. The argument should be one of the static public instances of the inner class Visibility. This is enforced by making it impossible to construct instances of this inner class outside this interface definition. If this method is not called, then implementations of this interface should return some default, not null.

Parameters:
visibility - The visibility of this Settable.
See Also:
getVisibility()

validate

java.util.Collection validate()
                              throws IllegalActionException
Check the validity of the expression set in setExpression(). Implementations of this method should notify the container by calling attributeChanged(), unless the container has already been notified in setExpression(). They should also notify any registered value listeners if they have not already been notified. If any other instances of Settable are validated as a side effect, then an implementation should return a Collection containing those instances. This can be used by the caller to avoid validating those again. The list may contain this instance of Settable.

Returns:
A collection of settables that are also validated as a side effect, or null if there are none.
Throws:
IllegalActionException - If the expression is not valid, or its value is not acceptable to the container or the listeners.