Class LayoutHint
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.kernel.util.SingletonAttribute
-
- ptolemy.vergil.actor.LayoutHint
-
- All Implemented Interfaces:
java.lang.Cloneable,Changeable,Debuggable,DebugListener,Derivable,ModelErrorHandler,MoMLExportable,Moveable,Nameable,Settable,Singleton
public class LayoutHint extends SingletonAttribute implements Settable
A LayoutHint is an Attribute for Ptolemy Relations that holds the specification of bend points for links. Its value field contains a list ofLayoutHint.LayoutHintItemobjects 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.LayoutHintItemobjects are encoded. Therefore the Expression is expected to contain anArrayTokenofLayoutHint.LayoutHintItemobjects.A complete LayoutHint with two
LayoutHint.LayoutHintItems 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
Mapwith always two keys. OneLayoutHint.LayoutHintItemis unambiguously identified by its head and tail, which are Ptolemy objects likePorts orRelations. The methods to access this aregetLayoutHintItem(Object, Object),setLayoutHintItem(NamedObj, NamedObj, double[], Point2D.Double)andremoveLayoutHintItem(LayoutHintItem).The class extends
SingletonAttributebecause every Relation is expected to have only one such Attribute, while one of these Attributes can carry multipleLayoutHint.LayoutHintItems as explained above. It is alsoSettableas 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.- Since:
- Ptolemy II 11.0
- Author:
- Hauke Fuhrmann, (kieler@informatik.uni-kiel.de), Ulf Rueegg
- Pt.AcceptedRating:
- Red (haf)
- Pt.ProposedRating:
- Red (haf)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLayoutHint.LayoutHintItemA LayoutHintItem is the specification of layout information for one Link.-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
Nested classes/interfaces inherited from interface ptolemy.kernel.util.Settable
Settable.Visibility
-
-
Field Summary
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.kernel.util.Settable
EXPERT, FULL, NONE, NOT_EDITABLE
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_propagateValue(NamedObj destination)Propagate the value of this object to the specified object.voidaddValueListener(ValueListener listener)Add a listener to be notified when the value of this attribute changes.voidexportMoML(java.io.Writer output, int depth, java.lang.String name)Write a MoML description of this object.java.lang.StringgetDefaultExpression()A LayoutHint has no default expression.java.lang.StringgetExpression()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.LayoutHintItemgetLayoutHintItem(java.lang.Object head, java.lang.Object tail)Get theLayoutHint.LayoutHintItemstored in this LayoutHint that is identified by the head and tail of the link for which it specifies bend points.java.lang.StringgetValueAsString()Get the value of the attribute, which is the evaluated expression.Settable.VisibilitygetVisibility()Get the visibility of this Settable, as set by setVisibility().voidremoveLayoutHintItem(LayoutHint.LayoutHintItem itemToRemove)Remove aLayoutHint.LayoutHintItemfrom this storage.voidremoveValueListener(ValueListener listener)Remove a listener from the list of listeners that is notified when the value of this variable changes.voidsetExpression(java.lang.String expression)Set the value of the attribute by giving some expression.voidsetLayoutHintItem(NamedObj head, NamedObj tail, double[] bendPoints, java.awt.geom.Point2D.Double labelLocation)Set aLayoutHint.LayoutHintItemfor a link which is specified by its head and tail, i.e.voidsetVisibility(Settable.Visibility visibility)Set the visibility of this attribute.java.util.Collectionvalidate()Parse the layout hint specification given by setExpression(), if there has been one, and otherwise do nothing, i.e.-
Methods inherited from class ptolemy.kernel.util.SingletonAttribute
setContainer
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_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
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName, setName
-
Methods inherited from interface ptolemy.kernel.util.Settable
getDisplayName
-
-
-
-
Constructor Detail
-
LayoutHint
public LayoutHint(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct an attribute with the given container and name.- Parameters:
container- The container.name- The name of this attribute.- Throws:
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.- See Also:
SingletonAttribute(NamedObj, String)
-
LayoutHint
public LayoutHint(Workspace workspace)
Construct a new attribute with no container and an empty string as a name.- Parameters:
workspace- The workspace that will list the attribute.- See Also:
SingletonAttribute(Workspace)
-
-
Method Detail
-
addValueListener
public void addValueListener(ValueListener listener)
Add a listener to be notified when the value of this attribute changes. If the listener is already on the list of listeners, then do nothing.- Specified by:
addValueListenerin interfaceSettable- Parameters:
listener- The listener to add.- See Also:
removeValueListener(ValueListener)
-
exportMoML
public void exportMoML(java.io.Writer output, int depth, java.lang.String name) throws java.io.IOExceptionWrite a MoML description of this object. MoML is an XML modeling markup language. In this class, the object is identified by the "property" element, with "name", "class", and "value" (XML) attributes. The body of the element, between the "<property>" and "</property>", is written using the _exportMoMLContents() protected method, so that derived classes can override that method alone to alter only how the contents of this object are described. The text that is written is indented according to the specified depth, with each line (including the last one) terminated with a newline. If this object is non-persistent, then nothing is written.- Specified by:
exportMoMLin interfaceMoMLExportable- Overrides:
exportMoMLin classNamedObj- Parameters:
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.- Throws:
java.io.IOException- If an I/O error occurs.- See Also:
Location.exportMoML(Writer, int, String),NamedObj.isPersistent()
-
getDefaultExpression
public java.lang.String getDefaultExpression()
A LayoutHint has no default expression.- Specified by:
getDefaultExpressionin interfaceSettable- Returns:
- always null
-
getExpression
public 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.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.LayoutHintItems as array elements. Example:{ item1, item2 }- Specified by:
getExpressionin interfaceSettable- Returns:
- The expression.
- See Also:
Location.getExpression(),setExpression(String)
-
getLayoutHintItem
public LayoutHint.LayoutHintItem getLayoutHintItem(java.lang.Object head, java.lang.Object tail)
Get theLayoutHint.LayoutHintItemstored in this LayoutHint that is identified by the head and tail of the link for which it specifies bend points. If noLayoutHint.LayoutHintItemis 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.- Parameters:
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.- Returns:
- the LayoutHintItem stored for this link or null
- See Also:
setLayoutHintItem(NamedObj, NamedObj, double[], Point2D.Double)
-
getValueAsString
public java.lang.String getValueAsString()
Get the value of the attribute, which is the evaluated expression.- Specified by:
getValueAsStringin interfaceSettable- Returns:
- The value.
- See Also:
Settable.getValueAsString()
-
getVisibility
public Settable.Visibility getVisibility()
Get the visibility of this Settable, as set by setVisibility(). The returned value is one of the static instances of theSettable.Visibilityinner class.- Specified by:
getVisibilityin interfaceSettable- Returns:
- The visibility of this Settable.
- See Also:
setVisibility(ptolemy.kernel.util.Settable.Visibility),Settable.getVisibility()
-
removeLayoutHintItem
public void removeLayoutHintItem(LayoutHint.LayoutHintItem itemToRemove)
Remove aLayoutHint.LayoutHintItemfrom this storage. If that is the last item contained in this layout hint, then the layout hint itself is removed from its container.- Parameters:
itemToRemove- The layout hint item to remove
-
removeValueListener
public void removeValueListener(ValueListener listener)
Remove a listener from the list of listeners that is notified when the value of this variable changes. If no such listener exists, do nothing.- Specified by:
removeValueListenerin interfaceSettable- Parameters:
listener- The listener to remove.- See Also:
Location.removeValueListener(ValueListener),addValueListener(ValueListener)
-
setExpression
public void setExpression(java.lang.String expression)
Set the value of the attribute by giving some expression. This expression is not parsed until validate() is called, and the container and value listeners are not notified until validate() is called. See the class comment for a description of the format.- Specified by:
setExpressionin interfaceSettable- Parameters:
expression- The value of the attribute.- See Also:
getExpression()
-
setLayoutHintItem
public void setLayoutHintItem(NamedObj head, NamedObj tail, double[] bendPoints, java.awt.geom.Point2D.Double labelLocation)
Set aLayoutHint.LayoutHintItemfor a link which is specified by its head and tail, i.e. PtolemyPorts orRelations. For this link store the given list of bend points. Like in aMapwith 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.- Parameters:
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 null- See Also:
getLayoutHintItem(Object, Object)
-
setVisibility
public void setVisibility(Settable.Visibility visibility)
Set the visibility of this attribute. The argument should be one of the public static instances in Settable.- Specified by:
setVisibilityin interfaceSettable- Parameters:
visibility- The visibility of this attribute.- See Also:
getVisibility()
-
validate
public java.util.Collection validate() throws IllegalActionExceptionParse 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. Notify the container and any value listeners of the new location, if it has changed. See the class comment for a description of the format.- Specified by:
validatein interfaceSettable- Returns:
- Null, indicating that no other instances of Settable are validated.
- Throws:
IllegalActionException- If the expression is invalid.
-
_propagateValue
protected void _propagateValue(NamedObj destination) throws IllegalActionException
Propagate the value of this object to the specified object. The specified object is required to be an instance of the same class as this one, or a ClassCastException will be thrown.- Overrides:
_propagateValuein classNamedObj- Parameters:
destination- Object to which to propagate the value.- Throws:
IllegalActionException- If the value cannot be propagated.- See Also:
Location._propagateValue(NamedObj)
-
-