Class ConnectionWidget

java.lang.Object
org.netbeans.api.visual.widget.Widget
org.netbeans.api.visual.widget.ConnectionWidget
All Implemented Interfaces:
Accessible, org.openide.util.Lookup.Provider
Direct Known Subclasses:
FreeConnectionWidget, VMDConnectionWidget

public class ConnectionWidget extends Widget
This class represents a connection between two location. The locations are resolved by Anchors. The path of the connection is specified by control points which are resolved by Routers (DirectRouter is used by default).

The connection is rendered using the foreground color and a specified stroke. It also renders control points, end points (first and last control points) and anchors. The shape of points are defined by assigned AnchorShape and PointShape.

For speed optimalization, the connection widget are usually placed in the a separate layer widget that is rendered after the main layer with widgets (that used anchors depends on) is rendered.

Line color is defined by foregroundColor property. Note: If you are changing a state of the ConnectionWidget (e.g. using it as a representation of an object in ObjectScene, GraphScene or GraphPinScene classes, then the ConnectionWidget.notifyStateChanged method is automatically called. The built-in implementation of this method overrides foregroundColor based on a new state of the widget (the particular color is resolved by the LookFeel of the scene).

  • Constructor Details

    • ConnectionWidget

      public ConnectionWidget(Scene scene)
      Creates a connection widget.
      Parameters:
      scene - the scene
  • Method Details

    • notifyStateChanged

      public void notifyStateChanged(ObjectState previousState, ObjectState state)
      Implements the widget-state specific look of the widget.
      Overrides:
      notifyStateChanged in class Widget
      Parameters:
      previousState - the previous state
      state - the new state
    • getStroke

      public final Stroke getStroke()
      Returns a stroke of the connection widget.
      Returns:
      the stroke
    • setStroke

      public final void setStroke(Stroke stroke)
      Sets a stroke.
      Parameters:
      stroke - the stroke
    • getLineColor

      public final Color getLineColor()
      Returns line color of the widget.
      Returns:
      the line color; null if no line color is specified
    • setLineColor

      public final void setLineColor(Color lineColor)
      Sets a line color of the widget.
      Parameters:
      lineColor - the line color; if null, then the line color will be resolved from LookFeel of the scene.
    • isPaintControlPoints

      public final boolean isPaintControlPoints()
      Returns whether the control (and end) points are painted
      Returns:
      true, if the control points (and end points) are painted
    • setPaintControlPoints

      public final void setPaintControlPoints(boolean paintControlPoints)
      Sets whether the control (and end) points are painted
      Parameters:
      paintControlPoints - if true, then control points are painted
    • getControlPointsCursor

      public final Cursor getControlPointsCursor()
      Returns the cursor for control point.
      Returns:
      the cursor
      Since:
      2.3
    • setControlPointsCursor

      public final void setControlPointsCursor(Cursor controlPointsCursor)
      Sets a control points cursor. The cursor is used only when mouse is over a visible control point
      Parameters:
      controlPointsCursor - the control points cursor
      Since:
      2.3
    • getControlPointCutDistance

      public int getControlPointCutDistance()
      Returns the cut distance at control points.
      Returns:
      the cut distance
      Since:
      2.5
    • setControlPointCutDistance

      public void setControlPointCutDistance(int controlPointCutDistance)
      Sets the cut distance at control points.
      Parameters:
      controlPointCutDistance - if positive number, then the path is cut to render smooth corners; otherwise the path is rendered using control points only
      Since:
      2.5
    • getSourceAnchor

      public final Anchor getSourceAnchor()
      Returns a source anchor of the connection widget.
      Returns:
      the source anchor
    • setSourceAnchor

      public final void setSourceAnchor(Anchor sourceAnchor)
      Sets a source anchor of the connection widget.
      Parameters:
      sourceAnchor - the source anchor
    • getTargetAnchor

      public final Anchor getTargetAnchor()
      Returns a target anchor of the connection widget.
      Returns:
      the target anchor
    • setTargetAnchor

      public final void setTargetAnchor(Anchor targetAnchor)
      Sets a target anchor of the connection widget.
      Parameters:
      targetAnchor - the target anchor
    • getSourceAnchorEntry

      public Anchor.Entry getSourceAnchorEntry()
      Returns an anchor entry representing the source of the connection widget.
      Returns:
      the anchor entry representing the source of the connection widget
    • getTargetAnchorEntry

      public Anchor.Entry getTargetAnchorEntry()
      Returns an anchor entry representing the target of the connection widget.
      Returns:
      the anchor entry representing the target of the connection widget
    • getSourceAnchorShape

      public AnchorShape getSourceAnchorShape()
      Returns an anchor shape of the source of the connection widget.
      Returns:
      the source anchor shape
    • setSourceAnchorShape

      public void setSourceAnchorShape(AnchorShape sourceAnchorShape)
      Sets the anchor shape of the source of the connection widget.
      Parameters:
      sourceAnchorShape - the source anchor shape
    • getTargetAnchorShape

      public AnchorShape getTargetAnchorShape()
      Returns an anchor shape of the target of the connection widget.
      Returns:
      the target anchor shape
    • setTargetAnchorShape

      public void setTargetAnchorShape(AnchorShape targetAnchorShape)
      Sets the anchor shape of the target of the connection widget.
      Parameters:
      targetAnchorShape - the target anchor shape
    • getControlPointShape

      public PointShape getControlPointShape()
      Returns a point shape of control points of the connection widget.
      Returns:
      the control points shape
    • setControlPointShape

      public void setControlPointShape(PointShape controlPointShape)
      Sets a point shape of control points of the connection widget.
      Parameters:
      controlPointShape - the control points shape
    • getEndPointShape

      public PointShape getEndPointShape()
      Returns a point shape of end points of the connection widget.
      Returns:
      the end points shape
    • setEndPointShape

      public void setEndPointShape(PointShape endPointShape)
      Sets a point shape of end points of the connection widget.
      Parameters:
      endPointShape - the end points shape
    • getRoutingPolicy

      public final ConnectionWidget.RoutingPolicy getRoutingPolicy()
      Returns a routing policy.
      Returns:
      the routing policy
      Since:
      2.9
    • setRoutingPolicy

      public final void setRoutingPolicy(ConnectionWidget.RoutingPolicy routingPolicy)
      Sets a routing policy. It invokes re-routing in case of routing policy change unless its is changed to DISABLE_ROUTING.
      Parameters:
      routingPolicy - the new routing policy
      Since:
      2.9
    • getRouter

      public final Router getRouter()
      Returns the control-points-based path router of the connection widget.
      Returns:
      the path router
    • setRouter

      public final void setRouter(Router router)
      Sets a control-points-based path router of the connection widget.
      Parameters:
      router - the path router
    • getControlPoints

      public List<Point> getControlPoints()
      Returns a list of control points.
      Returns:
      the list of control points
    • getControlPoint

      public Point getControlPoint(int index)
      Returns a location of control point at the specified index in the list of control points.
      Parameters:
      index - index of the control point to return
      Returns:
      the point; null if the control point does not exist
    • setControlPoints

      public void setControlPoints(Collection<Point> controlPoints, boolean sceneLocations)
      Sets control points.
      Parameters:
      controlPoints - the list of control points
      sceneLocations - if true, then controlPoints argyment is taken as a list of scene locations; if false, then controlPoints argument is taken as a list of local locations
    • setConstraint

      public void setConstraint(Widget childWidget, LayoutFactory.ConnectionWidgetLayoutAlignment alignment, float placementInPercentage)
      Sets a constraint for a child widget when ConnectionWidgetLayout (by default) is used.
      Parameters:
      childWidget - the child widget for which the constraint is set
      alignment - the alignment specified relatively to the origin point
      placementInPercentage - the placement on a path in percentage of the path length
    • setConstraint

      public void setConstraint(Widget childWidget, LayoutFactory.ConnectionWidgetLayoutAlignment alignment, int placementAtDistance)
      Sets a constraint for a child widget when ConnectionWidgetLayout (by default) is used.
      Parameters:
      childWidget - the child widget for which the constraint is set
      alignment - the alignment specified relatively to the origin point
      placementAtDistance - the placement on a path in pixels as a distance from the source anchor
    • removeConstraint

      public void removeConstraint(Widget childWidget)
      Removes a constraint for a child widget.
      Parameters:
      childWidget - the child widget
    • calculateRouting

      public final void calculateRouting()
      Forces path routing.
    • calculateClientArea

      protected Rectangle calculateClientArea()
      Calculates a client area of the connection widget.
      Overrides:
      calculateClientArea in class Widget
      Returns:
      the calculated client area
    • isValidated

      public boolean isValidated()
      Returns whether the connection widget is validated and routed.
      Overrides:
      isValidated in class Widget
      Returns:
      true, if the connection widget is validated and routed
    • isRouted

      public final boolean isRouted()
      Returns whether the connection widget is routed.
      Returns:
      true if the connection widget is routed
    • reroute

      public final void reroute()
      Schedules the connection widget for re-routing its path.
    • getFirstControlPoint

      public final Point getFirstControlPoint()
      Returns the first control point.
      Returns:
      the first control point; null, if list of control points is empty
    • getLastControlPoint

      public final Point getLastControlPoint()
      Returns the last control point.
      Returns:
      the last control point; null, if list of control points is empty
    • getTargetAnchorShapeRotation

      public double getTargetAnchorShapeRotation()
      Returns the rotation of the target anchor shape.
      Returns:
      the target anchor shape rotation
    • isHitAt

      public boolean isHitAt(Point localLocation)
      Returns whether a specified local location is a part of the connection widget. It checks whether the location is close to the control-points-based path (up to 4px from the line), close to the anchors (defined by AnchorShape) or close to the control points (PointShape).
      Overrides:
      isHitAt in class Widget
      Parameters:
      localLocation - the local locaytion
      Returns:
      true, if the location is a part of the connection widget
    • isFirstControlPointHitAt

      public final boolean isFirstControlPointHitAt(Point localLocation)
      Returns whether the local location hits the first control point (also meant to be the source anchor).
      Parameters:
      localLocation - the local location
      Returns:
      true if it hits the first control point
    • isLastControlPointHitAt

      public final boolean isLastControlPointHitAt(Point localLocation)
      Returns whether the local location hits the last control point (also meant to be the target anchor).
      Parameters:
      localLocation - the local location
      Returns:
      true if it hits the last control point
    • getControlPointHitAt

      public final int getControlPointHitAt(Point localLocation)
      Returns an index of a control point that is hit by the local location
      Parameters:
      localLocation - the local location
      Returns:
      the index; -1 if no control point was hit
    • getCursorAt

      protected Cursor getCursorAt(Point localLocation)
      Returns a cursor for a specified local location in the widget. If paintControlPoints is true and controlPointsCursor is non-null and local location is over a control point, then it return controlPointsCursor. Otherwise it return value from super.getCursorAt method.
      Overrides:
      getCursorAt in class Widget
      Parameters:
      localLocation - the local location
      Returns:
      the cursor
      Since:
      2.3
    • paintWidget

      protected void paintWidget()
      Paints the connection widget (the path, the anchor shapes, the control points, the end points).
      Overrides:
      paintWidget in class Widget