public static class LayoutHint.LayoutHintItem
extends java.lang.Object
Relation
,
a LayoutHint
is attached to a Relation and carries multiple of
these LayoutHintItems corresponding to the links. As links are no
persisted objects in Ptolemy, a link is identified by its head and tail
objects, which are Port
s or Relation
s.
The most important information such item carries is a list of bend points
that can be used to explicitly route a link along these bend points
instead of using a simple routing strategy like the
ManhattanConnector
. A router that uses the bend point information
for example is the KielerLayoutConnector
.
Such item can be serialized to the String representation of a Ptolemy
Expression by getExpression()
. This is used for persisting
LayoutHintItems. However, the bend point data are absolute coordinates
and therefore are only valid until the head and/or tail of the link are
moved. Hence, the LayoutHintItem also stores the coordinates and
optionally the multiport width of head and tail, which specify for which
layout of nodes the bend point information is only valid. The
revalidate()
method is used to check the validity of the
LayoutHintItem by comparing the stored positions with the actual
positions in the diagram, i.e. checking whether head and/or tail have
been moved or the width of a multiport has changed. If the LayoutHintItem
is not valid anymore, its bend points should not be used.
A special case is when head and tail moved relatively exactly the same,
which happens, if multiple elements are selected and moved together. In
such case the bend points are still valid relatively, but not absolutely.
Therefore the revalidate()
method also checks this case and
translates the bend point coordinates as well as the new head and tail
locations making the LayoutHintItem valid again. This avoids invalidating
bend points when whole model parts get moved.
An example for one LayoutHintItem's String representation is the following
{ head={"CompositeActor.port",20.0,200.0,2}, tail={"Discard.input",70.0,25.0}, points={135.0,25.0,135.0,125.0} }The head contains the object's name, its coordinates in x and y and the width, because the port is a multiport. The width defaults to 1 as can be seen at the tail where it is omitted.
Constructor and Description |
---|
LayoutHintItem(NamedObj head,
NamedObj tail)
Simple constructor specifying only head and tail for this
LayoutHintItem.
|
LayoutHintItem(NamedObj head,
NamedObj tail,
java.awt.geom.Point2D.Double locationHead,
java.awt.geom.Point2D.Double locationTail,
int multiportWidthHead,
int multiportWidthTail,
java.awt.geom.Point2D.Double labelPosition)
Constructor passing not only head and tail but also all required
layout information for the conditions under which this LayoutHintItem
is only valid.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_reverse()
Reverse the list of bend points.
|
java.util.List<java.awt.geom.Point2D> |
getBendPointList()
Get a list of
Point2D corresponding to the bend points stored
in this item. |
double[] |
getBendPoints()
Get the bend points stored in this hint as an array of doubles, where
each two entries correspond to x and y of one bend point.
|
java.lang.String |
getExpression()
Get the String representation of the Ptolemy Expression by which this
LayoutHint is persisted.
|
NamedObj |
getHead()
Get the head of this LayoutHint which is used to identify this hint.
|
java.awt.geom.Point2D.Double |
getLabelLocation()
A
Point2D representing the position where a label of an
edge should be positioned. |
NamedObj |
getTail()
Get the tail of this LayoutHint which is used to identify this hint.
|
boolean |
revalidate()
Check if the head and tail objects have been moved.
|
void |
setBendpoints(double[] bendPoints)
Set a new list of bend points and update the current validation
information such as the current location of head and tail and their
port widths.
|
void |
setLabelLocation(java.awt.geom.Point2D.Double labelLocation)
Sets the position a label should be placed at.
|
java.lang.String |
toString()
Get a String representation of a LayoutHint which will be the same as
getExpression() . |
public LayoutHintItem(NamedObj head, NamedObj tail)
head
- the head object of the corresponding linktail
- the tail object of the corresponding linkpublic LayoutHintItem(NamedObj head, NamedObj tail, java.awt.geom.Point2D.Double locationHead, java.awt.geom.Point2D.Double locationTail, int multiportWidthHead, int multiportWidthTail, java.awt.geom.Point2D.Double labelPosition)
head
- the head object of the corresponding linktail
- the tail object of the corresponding linklocationHead
- the location of the head as vectorlocationTail
- the location of the tail as vectormultiportWidthHead
- the width of the head, which is relevant
for multiports, 1, if no multiportmultiportWidthTail
- the width of the tail, which is relevant
for multiports, 1, if no multiportlabelPosition
- The position of the label.public double[] getBendPoints()
public java.util.List<java.awt.geom.Point2D> getBendPointList()
Point2D
corresponding to the bend points stored
in this item. If by setting the bend points with
setBendpoints(double[])
the list of bend point coordinates
is odd, the last coordinate is discarded, and a list of points
without the dangling coordinate is returned.public java.awt.geom.Point2D.Double getLabelLocation()
Point2D
representing the position where a label of an
edge should be positioned.setLabelLocation(Point2D.Double)
public java.lang.String getExpression()
public NamedObj getHead()
public NamedObj getTail()
public boolean revalidate()
public void setBendpoints(double[] bendPoints)
bendPoints
- new bend pointspublic void setLabelLocation(java.awt.geom.Point2D.Double labelLocation)
labelLocation
- a Point2D
with the position, may be null.getLabelLocation()
public java.lang.String toString()
getExpression()
.toString
in class java.lang.Object
getExpression()
protected void _reverse()