Class PolylineConnection

All Implemented Interfaces:
AnchorListener, Connection, IFigure

public class PolylineConnection extends Polyline implements Connection, AnchorListener
An implementation of Connection based on Polyline. PolylineConnection adds the following additional features:
  • A ConnectionRouter may be provided which will be used to determine the connections points.
  • Children may be added. The bounds calculation is extended such that the bounds is the smallest Rectangle which is large enough to display the Polyline and all of its children figures.
  • A DelegatingLayout is set as the default layout. A delegating layout allows children to position themselves via Locators.

  • Constructor Details

    • PolylineConnection

      public PolylineConnection()
  • Method Details

    • addNotify

      public void addNotify()
      Hooks the source and target anchors.
      Specified by:
      addNotify in interface IFigure
      Overrides:
      addNotify in class Figure
      See Also:
    • addRoutingListener

      public void addRoutingListener(RoutingListener listener)
      Appends the given routing listener to the list of listeners.
      Parameters:
      listener - the routing listener
      Since:
      3.2
    • anchorMoved

      public void anchorMoved(ConnectionAnchor anchor)
      Called by the anchors of this connection when they have moved, revalidating this polyline connection.
      Specified by:
      anchorMoved in interface AnchorListener
      Parameters:
      anchor - the anchor that moved
    • getBounds

      public Rectangle getBounds()
      Returns the bounds which holds all the points in this polyline connection. Returns any previously existing bounds, else calculates by unioning all the children's dimensions.
      Specified by:
      getBounds in interface IFigure
      Overrides:
      getBounds in class Polyline
      Returns:
      the bounds
      See Also:
    • getConnectionRouter

      public ConnectionRouter getConnectionRouter()
      Returns the ConnectionRouter used to layout this connection. Will not return null.
      Specified by:
      getConnectionRouter in interface Connection
      Returns:
      this connection's router
    • getRoutingConstraint

      public Object getRoutingConstraint()
      Returns this connection's routing constraint from its connection router. May return null.
      Specified by:
      getRoutingConstraint in interface Connection
      Returns:
      the connection's routing constraint
    • getSourceAnchor

      public ConnectionAnchor getSourceAnchor()
      Description copied from interface: Connection
      Returns the ConnectionAnchor at the source end of this Connection.
      Specified by:
      getSourceAnchor in interface Connection
      Returns:
      the anchor at the start of this polyline connection (may be null)
    • getSourceDecoration

      protected RotatableDecoration getSourceDecoration()
      Returns:
      the source decoration (may be null)
    • getTargetAnchor

      public ConnectionAnchor getTargetAnchor()
      Description copied from interface: Connection
      Returns the ConnectionAnchor at the target end of this Connection.
      Specified by:
      getTargetAnchor in interface Connection
      Returns:
      the anchor at the end of this polyline connection (may be null)
    • getTargetDecoration

      protected RotatableDecoration getTargetDecoration()
      Returns:
      the target decoration (may be null)
      Since:
      2.0
    • layout

      public void layout()
      Layouts this polyline. If the start and end anchors are present, the connection router is used to route this, after which it is laid out. It also fires a moved method.
      Overrides:
      layout in class Figure
    • removeNotify

      public void removeNotify()
      Called just before the receiver is being removed from its parent. Results in removing itself from the connection router.
      Specified by:
      removeNotify in interface IFigure
      Overrides:
      removeNotify in class Figure
      Since:
      2.0
    • removeRoutingListener

      public void removeRoutingListener(RoutingListener listener)
      Removes the first occurence of the given listener.
      Parameters:
      listener - the listener being removed
      Since:
      3.2
    • revalidate

      public void revalidate()
      Description copied from interface: IFigure
      Invalidates this figure and revalidates() its parent. If a figure does not have a parent, it will request a validation from it UpdateManager. Calling this method does not guarantee that a repaint will occur.
      Specified by:
      revalidate in interface IFigure
      Overrides:
      revalidate in class Figure
      See Also:
    • setConnectionRouter

      public void setConnectionRouter(ConnectionRouter cr)
      Sets the connection router which handles the layout of this polyline. Generally set by the parent handling the polyline connection.
      Specified by:
      setConnectionRouter in interface Connection
      Parameters:
      cr - the connection router
    • setRoutingConstraint

      public void setRoutingConstraint(Object cons)
      Sets the routing constraint for this connection.
      Specified by:
      setRoutingConstraint in interface Connection
      Parameters:
      cons - the constraint
    • setSourceAnchor

      public void setSourceAnchor(ConnectionAnchor anchor)
      Sets the anchor to be used at the start of this polyline connection.
      Specified by:
      setSourceAnchor in interface Connection
      Parameters:
      anchor - the new source anchor
    • setSourceDecoration

      public void setSourceDecoration(RotatableDecoration dec)
      Sets the decoration to be used at the start of the Connection.
      Parameters:
      dec - the new source decoration
      Since:
      2.0
    • setTargetAnchor

      public void setTargetAnchor(ConnectionAnchor anchor)
      Sets the anchor to be used at the end of the polyline connection. Removes this listener from the old anchor and adds it to the new anchor.
      Specified by:
      setTargetAnchor in interface Connection
      Parameters:
      anchor - the new target anchor
    • setTargetDecoration

      public void setTargetDecoration(RotatableDecoration dec)
      Sets the decoration to be used at the end of the Connection.
      Parameters:
      dec - the new target decoration