public class LayoutHint extends SingletonAttribute implements Settable
LayoutHint.LayoutHintItem
objects because one Relation can correspond to
multiple links, which are not real objects in the Ptolemy abstract syntax and
therefore can not carry any attributes. Each item carries a list of
bendpoints for a specific link as well as a location for a label
of the link (if it exists).
The LayoutHint uses a Ptolemy Expression as its value in which the
LayoutHint.LayoutHintItem
objects are encoded. Therefore the Expression is
expected to contain an ArrayToken
of LayoutHint.LayoutHintItem
objects.
A complete LayoutHint with two LayoutHint.LayoutHintItem
s could look like this:
{ { head={id="Discard.input",x=60.0,y=115.0,index=2}, tail={id="CompositeActor.port3",x=300.0,y=380.0,index=3}, points={105.0,235.0,105.0,190.0,265.0,190.0,265.0,135.0} }, { head={id="Ramp.output",x=320.0,y=225.0}, tail={id="CompositeActor.port2",x=580.0,y=200.0,index=3}, points={135.0,25.0,135.0,125.0}, labelLocation={x=340.0,y=210.0} } }
This storage works like a Map
with always two keys. One
LayoutHint.LayoutHintItem
is unambiguously identified by its head and tail,
which are Ptolemy objects like Port
s or Relation
s. The
methods to access this are getLayoutHintItem(Object, Object)
,
setLayoutHintItem(NamedObj, NamedObj, double[], Point2D.Double)
and
removeLayoutHintItem(LayoutHintItem)
.
The class extends SingletonAttribute
because every
Relation is expected to have only one such Attribute, while one of
these Attributes can carry multiple LayoutHint.LayoutHintItem
s as
explained above. It is also Settable
as
it can be set by loading a MOML file or by setting it manually
through the GUI. However, usually its visibility is set to EXPERT
mode only.
Some of the standard code for example for value listeners is copied from
Location
.
Modifier and Type | Class and Description |
---|---|
static class |
LayoutHint.LayoutHintItem
A LayoutHintItem is the specification of layout information for one Link.
|
NamedObj.ContainedObjectsIterator
Settable.Visibility
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
EXPERT, FULL, NONE, NOT_EDITABLE
Constructor and Description |
---|
LayoutHint(NamedObj container,
java.lang.String name)
Construct an attribute with the given container and name.
|
LayoutHint(Workspace workspace)
Construct a new attribute with
no container and an empty string as a name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_propagateValue(NamedObj destination)
Propagate the value of this object to the specified object.
|
void |
addValueListener(ValueListener listener)
Add a listener to be notified when the value of this attribute changes.
|
void |
exportMoML(java.io.Writer output,
int depth,
java.lang.String name)
Write a MoML description of this object.
|
java.lang.String |
getDefaultExpression()
A LayoutHint has no default expression.
|
java.lang.String |
getExpression()
Get the value that has been set by setExpression() or by
setLayoutHintItem(), whichever was most recently called, or return an
empty string if neither has been called.
|
LayoutHint.LayoutHintItem |
getLayoutHintItem(java.lang.Object head,
java.lang.Object tail)
Get the
LayoutHint.LayoutHintItem stored in this LayoutHint that is
identified by the head and tail of the link for which it specifies bend
points. |
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 |
removeLayoutHintItem(LayoutHint.LayoutHintItem itemToRemove)
Remove a
LayoutHint.LayoutHintItem from this storage. |
void |
removeValueListener(ValueListener listener)
Remove a listener from the list of listeners that is 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 |
setLayoutHintItem(NamedObj head,
NamedObj tail,
double[] bendPoints,
java.awt.geom.Point2D.Double labelLocation)
Set a
LayoutHint.LayoutHintItem for a link which is specified by its head
and tail, i.e. |
void |
setVisibility(Settable.Visibility visibility)
Set the visibility of this attribute.
|
java.util.Collection |
validate()
Parse the layout hint specification given by setExpression(), if there
has been one, and otherwise do nothing, i.e. keep the list of layout
hints empty.
|
setContainer
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDisplayName
description, getContainer, getFullName, getName, getName, setName
public LayoutHint(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of this attribute.IllegalActionException
- If the attribute cannot be contained
by the proposed container.NameDuplicationException
- If the container already has an
attribute with this name, and the class of that container is not
SingletonAttribute.SingletonAttribute.SingletonAttribute(NamedObj, String)
public LayoutHint(Workspace workspace)
workspace
- The workspace that will list the attribute.SingletonAttribute.SingletonAttribute(Workspace)
public void addValueListener(ValueListener listener)
addValueListener
in interface Settable
listener
- The listener to add.removeValueListener(ValueListener)
public void exportMoML(java.io.Writer output, int depth, java.lang.String name) throws java.io.IOException
exportMoML
in interface MoMLExportable
exportMoML
in class NamedObj
output
- The output writer to write to.depth
- The depth in the hierarchy, to determine indenting.name
- The name to use instead of the current name.java.io.IOException
- If an I/O error occurs.Location.exportMoML(Writer, int, String)
,
NamedObj.isPersistent()
public java.lang.String getDefaultExpression()
getDefaultExpression
in interface Settable
public java.lang.String getExpression()
If setExpression(String value) was called, then the return value is exactly what ever was passed in as the argument to setExpression. This means that there is no guarantee that the return value of getExpression() is a well formed Ptolemy array expression.
If setLayoutHintItem(NamedObj, NamedObj, double[]) was called, then the
return value is a well formed Ptolemy array expression that starts with
"{" and ends with "}", and contains the expressions of
LayoutHint.LayoutHintItem
s as array elements. Example:
{ item1, item2 }
getExpression
in interface Settable
Location.getExpression()
,
setExpression(String)
public LayoutHint.LayoutHintItem getLayoutHintItem(java.lang.Object head, java.lang.Object tail)
LayoutHint.LayoutHintItem
stored in this LayoutHint that is
identified by the head and tail of the link for which it specifies bend
points. If no LayoutHint.LayoutHintItem
is stored for the given head and
tail, null is returned. It works like a map with two keys that have to
match. As links in Ptolemy are not directed, it does not matter if head
and tail get switched. However, for layout the direction does matter and
the bendpoint list is directed from head to tail. So if there is an item
available where head and tail are swapped, then this item will be
returned but the entries get swapped again to guarantee that head and
tail and the bendpoint order are correct.head
- The starting point of the link, e.g. a Ptolemy Port or
Relation.tail
- The ending point of the link, e.g. a Ptolemy Port or
Relation.setLayoutHintItem(NamedObj, NamedObj, double[], Point2D.Double)
public java.lang.String getValueAsString()
getValueAsString
in interface Settable
Settable.getValueAsString()
public Settable.Visibility getVisibility()
Settable.Visibility
inner class.getVisibility
in interface Settable
setVisibility(ptolemy.kernel.util.Settable.Visibility)
,
Settable.getVisibility()
public void removeLayoutHintItem(LayoutHint.LayoutHintItem itemToRemove)
LayoutHint.LayoutHintItem
from this storage. If that is the last
item contained in this layout hint, then the layout hint itself is
removed from its container.itemToRemove
- The layout hint item to removepublic void removeValueListener(ValueListener listener)
removeValueListener
in interface Settable
listener
- The listener to remove.Location.removeValueListener(ValueListener)
,
addValueListener(ValueListener)
public void setExpression(java.lang.String expression)
setExpression
in interface Settable
expression
- The value of the attribute.getExpression()
public void setLayoutHintItem(NamedObj head, NamedObj tail, double[] bendPoints, java.awt.geom.Point2D.Double labelLocation)
LayoutHint.LayoutHintItem
for a link which is specified by its head
and tail, i.e. Ptolemy Port
s or Relation
s. For this link
store the given list of bend points. Like in a Map
with two keys,
a possibly existing item for the given head and tail will be reused and
updated with the bend points. If no such item yet exists, a new one is
added.head
- the head object of the corresponding linktail
- the tail object of the corresponding linkbendPoints
- an array of double coordinates, where always two
correspond to a bend pointlabelLocation
- the location of a label if it exists, may be nullgetLayoutHintItem(Object, Object)
public void setVisibility(Settable.Visibility visibility)
setVisibility
in interface Settable
visibility
- The visibility of this attribute.getVisibility()
public java.util.Collection validate() throws IllegalActionException
validate
in interface Settable
IllegalActionException
- If the expression is invalid.protected void _propagateValue(NamedObj destination) throws IllegalActionException
_propagateValue
in class NamedObj
destination
- Object to which to propagate the value.IllegalActionException
- If the value cannot be propagated.Location._propagateValue(NamedObj)