Class ConnectorItem

All Implemented Interfaces:
IFeedbackProvider, IDrawable, EventListener

public class ConnectorItem extends PolylineItem
A connection between two connectable items, drawn as an open polyline with an editable elbow.

Geometry model

  • Vertex 0 — anchored to startItem.
  • Vertex 1 — elbow (user-draggable).
  • Vertex 2 — anchored to endItem.

Endpoints are recomputed from the connected items each time the connector's geometry needs to be validated, so the connection follows its endpoints when nodes move. The elbow vertex is preserved across anchor sync operations.

Anchor synchronisation

The connector compares the current endpoint world positions against the last-known anchor positions (lastStart and lastEnd) before redrawing. Synchronisation is skipped when the anchors have not moved, preventing the connector from being perpetually marked dirty on every frame.

  • Constructor Details

    • ConnectorItem

      public ConnectorItem(Layer layer, AItem startItem, AItem endItem)
      Create a connector with a single elbow between two items.

      The initial geometry is an L-shape: start anchor → elbow at (startAnchor.x, endAnchor.y) → end anchor.

      Parameters:
      layer - the layer to add the connector to; recommended to use a connection layer drawn below node layers
      startItem - the item the connector originates from; must not be null
      endItem - the item the connector terminates at; must not be null
      Throws:
      NullPointerException - if either item argument is null
  • Method Details

    • shouldDraw

      public boolean shouldDraw(Graphics2D g2, IContainer container)
      Checks whether the item should be drawn. This is an additional check, beyond the simple visibility flag check. For example, it might check whether the item intersects the area being drawn.

      Recomputes endpoint anchors before drawing if either endpoint item has moved since the last draw. Only performs the sync (and marks the item dirty) when a change is detected, avoiding a perpetual dirty-every-frame cycle.

      Overrides:
      shouldDraw in class PathBasedItem
      Parameters:
      g2 - the graphics context.
      container - the graphical container being rendered.
      Returns:
      true if the item passes any and all tests, and should be drawn.
    • drawItem

      public void drawItem(Graphics2D g2, IContainer container)
      Custom drawer for the item.

      Syncs anchors if needed, then delegates to PolylineItem.

      Overrides:
      drawItem in class PolylineItem
      Parameters:
      g2 - the graphics context.
      container - the graphical container being rendered.
    • modify

      public void modify()
      A modification such as a drag, resize or rotate is continuing.

      Lets PolylineItem reshape the elbow vertex, then forces endpoints back onto their anchored items so the connection cannot be accidentally detached by dragging a handle.

      Overrides:
      modify in class PathBasedItem
    • getWorldBounds

      public Rectangle2D.Double getWorldBounds()
      Get the world bounding rectangle of the item.

      Ensures anchors are current before bounds queries are used for picking and visibility tests.

      Overrides:
      getWorldBounds in class PathBasedItem
      Returns:
      the world box containing the item.
    • getStartItem

      public AItem getStartItem()
      Return the item this connector originates from.
      Returns:
      the start item; never null
    • getEndItem

      public AItem getEndItem()
      Return the item this connector terminates at.
      Returns:
      the end item; never null