public class ConnectionWidget extends Widget
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).
Modifier and Type | Class and Description |
---|---|
static class |
ConnectionWidget.RoutingPolicy
This enum represents a policy which is used for re-routing control points of a ConnectionWidget.
|
Widget.Dependency
Constructor and Description |
---|
ConnectionWidget(Scene scene)
Creates a connection widget.
|
Modifier and Type | Method and Description |
---|---|
protected Rectangle |
calculateClientArea()
Calculates a client area of the connection widget.
|
void |
calculateRouting()
Forces path routing.
|
Point |
getControlPoint(int index)
Returns a location of control point at the specified index in the list of control points.
|
int |
getControlPointCutDistance()
Returns the cut distance at control points.
|
int |
getControlPointHitAt(Point localLocation)
Returns an index of a control point that is hit by the local location
|
List<Point> |
getControlPoints()
Returns a list of control points.
|
Cursor |
getControlPointsCursor()
Returns the cursor for control point.
|
PointShape |
getControlPointShape()
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.
|
PointShape |
getEndPointShape()
Returns a point shape of end points of the connection widget.
|
Point |
getFirstControlPoint()
Returns the first control point.
|
Point |
getLastControlPoint()
Returns the last control point.
|
Color |
getLineColor()
Returns line color of the widget.
|
Router |
getRouter()
Returns the control-points-based path router of the connection widget.
|
ConnectionWidget.RoutingPolicy |
getRoutingPolicy()
Returns a routing policy.
|
Anchor |
getSourceAnchor()
Returns a source anchor of the connection widget.
|
Anchor.Entry |
getSourceAnchorEntry()
Returns an anchor entry representing the source of the connection widget.
|
AnchorShape |
getSourceAnchorShape()
Returns an anchor shape of the source of the connection widget.
|
Stroke |
getStroke()
Returns a stroke of the connection widget.
|
Anchor |
getTargetAnchor()
Returns a target anchor of the connection widget.
|
Anchor.Entry |
getTargetAnchorEntry()
Returns an anchor entry representing the target of the connection widget.
|
AnchorShape |
getTargetAnchorShape()
Returns an anchor shape of the target of the connection widget.
|
double |
getTargetAnchorShapeRotation()
Returns the rotation of the target anchor shape.
|
boolean |
isFirstControlPointHitAt(Point localLocation)
Returns whether the local location hits the first control point (also meant to be the source anchor).
|
boolean |
isHitAt(Point localLocation)
Returns whether a specified local location is a part of the connection widget.
|
boolean |
isLastControlPointHitAt(Point localLocation)
Returns whether the local location hits the last control point (also meant to be the target anchor).
|
boolean |
isPaintControlPoints()
Returns whether the control (and end) points are painted
|
boolean |
isRouted()
Returns whether the connection widget is routed.
|
boolean |
isValidated()
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 |
paintWidget()
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.
|
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.
|
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.
|
void |
setLineColor(Color lineColor)
Sets a line color of the widget.
|
void |
setPaintControlPoints(boolean paintControlPoints)
Sets whether the control (and end) points are painted
|
void |
setRouter(Router router)
Sets a control-points-based path router of the connection widget.
|
void |
setRoutingPolicy(ConnectionWidget.RoutingPolicy routingPolicy)
Sets a routing policy.
|
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.
|
void |
setStroke(Stroke stroke)
Sets a stroke.
|
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.
|
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
public ConnectionWidget(Scene scene)
scene
- the scenepublic void notifyStateChanged(ObjectState previousState, ObjectState state)
notifyStateChanged
in class Widget
previousState
- the previous statestate
- the new statepublic final Stroke getStroke()
public final void setStroke(Stroke stroke)
stroke
- the strokepublic final Color getLineColor()
public final void setLineColor(Color lineColor)
lineColor
- the line color; if null, then the line color will be resolved from LookFeel of the scene.public final boolean isPaintControlPoints()
public final void setPaintControlPoints(boolean paintControlPoints)
paintControlPoints
- if true, then control points are paintedpublic final Cursor getControlPointsCursor()
public final void setControlPointsCursor(Cursor controlPointsCursor)
controlPointsCursor
- the control points cursorpublic int getControlPointCutDistance()
public void setControlPointCutDistance(int controlPointCutDistance)
controlPointCutDistance
- if positive number, then the path is cut to render smooth corners;
otherwise the path is rendered using control points onlypublic final Anchor getSourceAnchor()
public final void setSourceAnchor(Anchor sourceAnchor)
sourceAnchor
- the source anchorpublic final Anchor getTargetAnchor()
public final void setTargetAnchor(Anchor targetAnchor)
targetAnchor
- the target anchorpublic Anchor.Entry getSourceAnchorEntry()
public Anchor.Entry getTargetAnchorEntry()
public AnchorShape getSourceAnchorShape()
public void setSourceAnchorShape(AnchorShape sourceAnchorShape)
sourceAnchorShape
- the source anchor shapepublic AnchorShape getTargetAnchorShape()
public void setTargetAnchorShape(AnchorShape targetAnchorShape)
targetAnchorShape
- the target anchor shapepublic PointShape getControlPointShape()
public void setControlPointShape(PointShape controlPointShape)
controlPointShape
- the control points shapepublic PointShape getEndPointShape()
public void setEndPointShape(PointShape endPointShape)
endPointShape
- the end points shapepublic final ConnectionWidget.RoutingPolicy getRoutingPolicy()
public final void setRoutingPolicy(ConnectionWidget.RoutingPolicy routingPolicy)
routingPolicy
- the new routing policypublic final Router getRouter()
public final void setRouter(Router router)
router
- the path routerpublic List<Point> getControlPoints()
public Point getControlPoint(int index)
index
- index of the control point to returnpublic void setControlPoints(Collection<Point> controlPoints, boolean sceneLocations)
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 locationspublic void setConstraint(Widget childWidget, LayoutFactory.ConnectionWidgetLayoutAlignment alignment, float placementInPercentage)
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 lengthpublic void setConstraint(Widget childWidget, LayoutFactory.ConnectionWidgetLayoutAlignment alignment, int placementAtDistance)
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 anchorpublic void removeConstraint(Widget childWidget)
childWidget
- the child widgetpublic final void calculateRouting()
protected Rectangle calculateClientArea()
calculateClientArea
in class Widget
public boolean isValidated()
isValidated
in class Widget
public final boolean isRouted()
public final void reroute()
public final Point getFirstControlPoint()
public final Point getLastControlPoint()
public double getTargetAnchorShapeRotation()
public boolean isHitAt(Point localLocation)
public final boolean isFirstControlPointHitAt(Point localLocation)
localLocation
- the local locationpublic final boolean isLastControlPointHitAt(Point localLocation)
localLocation
- the local locationpublic final int getControlPointHitAt(Point localLocation)
localLocation
- the local locationprotected Cursor getCursorAt(Point localLocation)
getCursorAt
in class Widget
localLocation
- the local locationprotected void paintWidget()
paintWidget
in class Widget