Class ConnectionWidget
- All Implemented Interfaces:
Accessible
,org.openide.util.Lookup.Provider
- Direct Known Subclasses:
FreeConnectionWidget
,VMDConnectionWidget
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
This enum represents a policy which is used for re-routing control points of a ConnectionWidget.Nested classes/interfaces inherited from class org.netbeans.api.visual.widget.Widget
Widget.Dependency
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Rectangle
Calculates a client area of the connection widget.final void
Forces path routing.getControlPoint
(int index) Returns a location of control point at the specified index in the list of control points.int
Returns the cut distance at control points.final int
getControlPointHitAt
(Point localLocation) Returns an index of a control point that is hit by the local locationReturns a list of control points.final Cursor
Returns the cursor for control point.Returns a point shape of control points of the connection widget.protected Cursor
getCursorAt
(Point localLocation) Returns a cursor for a specified local location in the widget.Returns a point shape of end points of the connection widget.final Point
Returns the first control point.final Point
Returns the last control point.final Color
Returns line color of the widget.final Router
Returns the control-points-based path router of the connection widget.Returns a routing policy.final Anchor
Returns a source anchor of the connection widget.Returns an anchor entry representing the source of the connection widget.Returns an anchor shape of the source of the connection widget.final Stroke
Returns a stroke of the connection widget.final Anchor
Returns a target anchor of the connection widget.Returns an anchor entry representing the target of the connection widget.Returns an anchor shape of the target of the connection widget.double
Returns the rotation of the target anchor shape.final boolean
isFirstControlPointHitAt
(Point localLocation) Returns whether the local location hits the first control point (also meant to be the source anchor).boolean
Returns whether a specified local location is a part of the connection widget.final boolean
isLastControlPointHitAt
(Point localLocation) Returns whether the local location hits the last control point (also meant to be the target anchor).final boolean
Returns whether the control (and end) points are paintedfinal boolean
isRouted()
Returns whether the connection widget is routed.boolean
Returns whether the connection widget is validated and routed.void
notifyStateChanged
(ObjectState previousState, ObjectState state) Implements the widget-state specific look of the widget.protected void
Paints the connection widget (the path, the anchor shapes, the control points, the end points).void
removeConstraint
(Widget childWidget) Removes a constraint for a child widget.final void
reroute()
Schedules the connection widget for re-routing its path.void
setConstraint
(Widget childWidget, LayoutFactory.ConnectionWidgetLayoutAlignment alignment, float placementInPercentage) Sets a constraint for a child widget when ConnectionWidgetLayout (by default) is used.void
setConstraint
(Widget childWidget, LayoutFactory.ConnectionWidgetLayoutAlignment alignment, int placementAtDistance) Sets a constraint for a child widget when ConnectionWidgetLayout (by default) is used.void
setControlPointCutDistance
(int controlPointCutDistance) Sets the cut distance at control points.void
setControlPoints
(Collection<Point> controlPoints, boolean sceneLocations) Sets control points.final void
setControlPointsCursor
(Cursor controlPointsCursor) Sets a control points cursor.void
setControlPointShape
(PointShape controlPointShape) Sets a point shape of control points of the connection widget.void
setEndPointShape
(PointShape endPointShape) Sets a point shape of end points of the connection widget.final void
setLineColor
(Color lineColor) Sets a line color of the widget.final void
setPaintControlPoints
(boolean paintControlPoints) Sets whether the control (and end) points are paintedfinal void
Sets a control-points-based path router of the connection widget.final void
setRoutingPolicy
(ConnectionWidget.RoutingPolicy routingPolicy) Sets a routing policy.final void
setSourceAnchor
(Anchor sourceAnchor) Sets a source anchor of the connection widget.void
setSourceAnchorShape
(AnchorShape sourceAnchorShape) Sets the anchor shape of the source of the connection widget.final void
Sets a stroke.final void
setTargetAnchor
(Anchor targetAnchor) Sets a target anchor of the connection widget.void
setTargetAnchorShape
(AnchorShape targetAnchorShape) Sets the anchor shape of the target of the connection widget.Methods inherited from class org.netbeans.api.visual.widget.Widget
addChild, addChild, addChild, addChild, addChildren, addDependency, bringToBack, bringToFront, convertLocalToScene, convertLocalToScene, convertSceneToLocal, convertSceneToLocal, createActions, equals, getAccessibleContext, getActions, getActions, getBackground, getBorder, getBounds, getChildConstraint, getChildren, getClientArea, getCursor, getDependencies, getFont, getForeground, getGraphics, getLayout, getLocation, getLookup, getMaximumSize, getMinimumSize, getParentWidget, getPreferredBounds, getPreferredLocation, getPreferredSize, getResourceTable, getScene, getState, getToolTipText, hashCode, isCheckClipping, isEnabled, isOpaque, isPreferredBoundsSet, isRepaintRequiredForRevalidating, isVisible, notifyAdded, notifyBackgroundChanged, notifyFontChanged, notifyForegroundChanged, notifyRemoved, paint, paintBackground, paintBorder, paintChildren, removeChild, removeChildren, removeChildren, removeDependency, removeFromParent, repaint, resolveBounds, revalidate, revalidate, setAccessibleContext, setBackground, setBackgroundFromResource, setBorder, setBorder, setCheckClipping, setChildConstraint, setCursor, setEnabled, setFont, setFontFromResource, setForeground, setForegroundFromResource, setLayout, setMaximumSize, setMinimumSize, setOpaque, setPreferredBounds, setPreferredLocation, setPreferredSize, setResourceTable, setState, setToolTipText, setVisible, updateResources
-
Constructor Details
-
ConnectionWidget
-
-
Method Details
-
notifyStateChanged
Implements the widget-state specific look of the widget.- Overrides:
notifyStateChanged
in classWidget
- Parameters:
previousState
- the previous statestate
- the new state
-
getStroke
-
setStroke
-
getLineColor
Returns line color of the widget.- Returns:
- the line color; null if no line color is specified
-
setLineColor
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
Returns the cursor for control point.- Returns:
- the cursor
- Since:
- 2.3
-
setControlPointsCursor
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
Returns a source anchor of the connection widget.- Returns:
- the source anchor
-
setSourceAnchor
Sets a source anchor of the connection widget.- Parameters:
sourceAnchor
- the source anchor
-
getTargetAnchor
Returns a target anchor of the connection widget.- Returns:
- the target anchor
-
setTargetAnchor
Sets a target anchor of the connection widget.- Parameters:
targetAnchor
- the target anchor
-
getSourceAnchorEntry
Returns an anchor entry representing the source of the connection widget.- Returns:
- the anchor entry representing the source of the connection widget
-
getTargetAnchorEntry
Returns an anchor entry representing the target of the connection widget.- Returns:
- the anchor entry representing the target of the connection widget
-
getSourceAnchorShape
Returns an anchor shape of the source of the connection widget.- Returns:
- the source anchor shape
-
setSourceAnchorShape
Sets the anchor shape of the source of the connection widget.- Parameters:
sourceAnchorShape
- the source anchor shape
-
getTargetAnchorShape
Returns an anchor shape of the target of the connection widget.- Returns:
- the target anchor shape
-
setTargetAnchorShape
Sets the anchor shape of the target of the connection widget.- Parameters:
targetAnchorShape
- the target anchor shape
-
getControlPointShape
Returns a point shape of control points of the connection widget.- Returns:
- the control points shape
-
setControlPointShape
Sets a point shape of control points of the connection widget.- Parameters:
controlPointShape
- the control points shape
-
getEndPointShape
Returns a point shape of end points of the connection widget.- Returns:
- the end points shape
-
setEndPointShape
Sets a point shape of end points of the connection widget.- Parameters:
endPointShape
- the end points shape
-
getRoutingPolicy
Returns a routing policy.- Returns:
- the routing policy
- Since:
- 2.9
-
setRoutingPolicy
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
Returns the control-points-based path router of the connection widget.- Returns:
- the path router
-
setRouter
Sets a control-points-based path router of the connection widget.- Parameters:
router
- the path router
-
getControlPoints
-
getControlPoint
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
Sets control points.- Parameters:
controlPoints
- the list of control pointssceneLocations
- 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 setalignment
- the alignment specified relatively to the origin pointplacementInPercentage
- 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 setalignment
- the alignment specified relatively to the origin pointplacementAtDistance
- the placement on a path in pixels as a distance from the source anchor
-
removeConstraint
Removes a constraint for a child widget.- Parameters:
childWidget
- the child widget
-
calculateRouting
public final void calculateRouting()Forces path routing. -
calculateClientArea
Calculates a client area of the connection widget.- Overrides:
calculateClientArea
in classWidget
- Returns:
- the calculated client area
-
isValidated
public boolean isValidated()Returns whether the connection widget is validated and routed.- Overrides:
isValidated
in classWidget
- 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
Returns the first control point.- Returns:
- the first control point; null, if list of control points is empty
-
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
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). -
isFirstControlPointHitAt
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
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
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
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 classWidget
- 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 classWidget
-