public class FXBendConnectionPolicy extends AbstractBendPolicy<javafx.scene.Node>
FXBendConnectionPolicy
can be used to manipulate the points
constituting an Connection
, i.e. its start, way, and end points. Each
point is realized though an IAnchor
, which may either be local to the
Connection
(i.e. the anchor refers to the Connection
as
anchorage), or it may be provided by another IVisualPart
(i.e. the
anchor is provided by a Provider
adapted to the part), to which the
connection is being connected.
When moving a point the policy takes care of:
IVisualPart
under mouse when
applicable.Modifier and Type | Class and Description |
---|---|
class |
FXBendConnectionPolicy.AnchorHandle
An
FXBendConnectionPolicy.AnchorHandle represents an explicit IAnchor within the
manipulated Connection . |
class |
FXBendConnectionPolicy.PointOverlay
A
FXBendConnectionPolicy.PointOverlay represents a 2-point-overlay. |
class |
FXBendConnectionPolicy.SegmentOverlay
A
FXBendConnectionPolicy.SegmentOverlay represents a 3-segment-overlay. |
Modifier and Type | Field and Description |
---|---|
protected static double |
DEFAULT_OVERLAY_THRESHOLD
The overlay threshold, i.e. the distance between two points so that they
are regarded as overlying.
|
Constructor and Description |
---|
FXBendConnectionPolicy() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canConnect(int explicitAnchorIndex)
Determines if the anchor at the given explicit index can be replaced with
an anchor that is obtained from an underlying visual part.
|
ITransactionalOperation |
commit()
Returns an
ITransactionalOperation that performs all
manipulations applied by the policy since the last AbstractTransactionPolicy.init() call. |
FXBendConnectionPolicy.AnchorHandle |
createAfter(FXBendConnectionPolicy.AnchorHandle explicitAnchorHandle,
Point mouseInScene)
Creates a new anchor after the anchor specified by the given explicit
anchor index.
|
FXBendConnectionPolicy.AnchorHandle |
createBefore(FXBendConnectionPolicy.AnchorHandle explicitAnchorHandle,
Point mouseInScene)
Creates a new anchor before the anchor specified by the given explicit
anchor index.
|
protected ITransactionalOperation |
createOperation()
Creates an
ITransactionalOperation that is used to encapsulate
the changes that are applied by this AbstractTransactionPolicy
through its "work" methods. |
protected ReverseUndoCompositeOperation |
createReselectOperation()
Create an
IUndoableOperation to re-select the host part. |
protected IAnchor |
createUnconnectedAnchor(Point selectedPointCurrentPositionInLocal)
Creates an (unconnected) anchor (i.e. one anchored on the
Connection ) for the given position (in scene coordinates). |
protected FXBendConnectionPolicy.AnchorHandle |
findExplicitAnchor(int startConnectionIndex,
int step)
Returns the
FXBendConnectionPolicy.AnchorHandle for the first explicit anchor that is
found within the connection's anchors when starting to search at the
given connection index, and incrementing the index by the given step per
iteration. |
FXBendConnectionPolicy.AnchorHandle |
findExplicitAnchorBackward(int connectionIndex)
Returns an
FXBendConnectionPolicy.AnchorHandle for the first explicit anchor that can be
found when iterating the connection anchors backwards, starting at the
given connection index. |
FXBendConnectionPolicy.AnchorHandle |
findExplicitAnchorForward(int connectionIndex)
Returns an
FXBendConnectionPolicy.AnchorHandle for the first explicit anchor that can be
found when iterating the connection anchors forwards, starting at the
given connection index. |
protected IAnchor |
findOrCreateAnchor(Point positionInLocal,
boolean canConnect)
Determines the
IAnchor that should replace the anchor of the
currently selected point. |
protected FXBendConnectionOperation |
getBendOperation()
Returns an
FXBendConnectionOperation that is extracted from the
operation created by createOperation() . |
protected Connection |
getConnection()
Returns the
Connection that is manipulated by this policy. |
protected java.util.List<IBendableContentPart.BendPoint> |
getCurrentBendPoints()
Returns the current control points of the content.
|
IVisualPart<javafx.scene.Node,Connection> |
getHost()
|
protected Point |
getMouseDeltaInLocal(Point initialMousePositionInScene,
Point currentMousePositionInScene)
Computes the mouse movement delta (w.r.t. to the initial mouse position)
in local coordinates .
|
protected double |
getOverlayThreshold()
Removes the overlay threshold, i.e. the distance between two points, so
that they are regarded as overlaying.
|
void |
init()
Initializes the policy, so that the policy's "work" methods can be used.
|
protected void |
insertExplicitAnchor(int insertionIndex,
Point mouseInScene)
Creates a new static anchor for the given position and inserts it at the
given index.
|
boolean |
isExplicit(int connectionIndex)
Returns
true if the anchor at the given connection index is
explicit. |
boolean |
isSelectionOnHorizontalLine()
Returns
true if the selected anchors are on a horizontal
line, i.e. they share an equal Y coordinate. |
FXBendConnectionPolicy.AnchorHandle |
makeExplicit(int connectionIndex)
Makes the connection anchor at the given connection index explicit and
returns an
FXBendConnectionPolicy.AnchorHandle for it. |
java.util.List<FXBendConnectionPolicy.AnchorHandle> |
makeExplicit(int startConnectionIndex,
int endConnectionIndex)
Makes the connection anchors within the given range of connection indices
explicit and returns
FXBendConnectionPolicy.AnchorHandle s for them. |
void |
move(Point initialMouseInScene,
Point currentMouseInScene)
Moves the currently selected point to the given mouse position in scene
coordinates.
|
void |
normalize()
For segment based connections, the control points need to be normalized,
i.e. all control points that lie on the orthogonal connection between two
other control points have to be removed.
|
void |
select(FXBendConnectionPolicy.AnchorHandle explicitAnchorHandle)
Selects the point specified by the given segment index and parameter for
manipulation.
|
void |
selectSegment(int segmentIndex)
Selects the end points of the connection segment specified by the given
index.
|
java.lang.String |
toString() |
getInitialBendPoints
checkInitialized, getOperation, isInitialized, locallyExecuteOperation, rollback
getAdaptable, setAdaptable
protected static final double DEFAULT_OVERLAY_THRESHOLD
protected boolean canConnect(int explicitAnchorIndex)
explicitAnchorIndex
- The explicit anchor index for which to determine if it can be
connected.true
if the anchor at the given index can be
connected, otherwise false
.public ITransactionalOperation commit()
AbstractTransactionPolicy
ITransactionalOperation
that performs all
manipulations applied by the policy since the last AbstractTransactionPolicy.init()
call.
When called multiple times in sequence, only the first call will yield an
operation, the subsequent calls will yield null
.commit
in class AbstractBendPolicy<javafx.scene.Node>
ITransactionalOperation
that performs all
manipulations applied by the policy since the last
AbstractTransactionPolicy.init()
call.public FXBendConnectionPolicy.AnchorHandle createAfter(FXBendConnectionPolicy.AnchorHandle explicitAnchorHandle, Point mouseInScene)
explicitAnchorHandle
- An FXBendConnectionPolicy.AnchorHandle
that references the explicit anchor
after which the new anchor is inserted.mouseInScene
- The position for the new anchor in scene coordinates.FXBendConnectionPolicy.AnchorHandle
for the new anchor.public FXBendConnectionPolicy.AnchorHandle createBefore(FXBendConnectionPolicy.AnchorHandle explicitAnchorHandle, Point mouseInScene)
explicitAnchorHandle
- An FXBendConnectionPolicy.AnchorHandle
that references the explicit anchor
after which the new anchor is inserted.mouseInScene
- The position for the new anchor in scene coordinates.FXBendConnectionPolicy.AnchorHandle
for the new anchor.protected ITransactionalOperation createOperation()
AbstractTransactionPolicy
ITransactionalOperation
that is used to encapsulate
the changes that are applied by this AbstractTransactionPolicy
through its "work" methods. The created operation should allow for
local execution
at each time.createOperation
in class AbstractTransactionPolicy<javafx.scene.Node>
ITransactionalOperation
to encapsulate all applied
changes.protected ReverseUndoCompositeOperation createReselectOperation()
IUndoableOperation
to re-select the host part.IUndoableOperation
that deselects and selects the root
part.protected IAnchor createUnconnectedAnchor(Point selectedPointCurrentPositionInLocal)
Connection
) for the given position (in scene coordinates).selectedPointCurrentPositionInLocal
- The location in local coordinates of the connectionIAnchor
that yields the given position.protected FXBendConnectionPolicy.AnchorHandle findExplicitAnchor(int startConnectionIndex, int step)
FXBendConnectionPolicy.AnchorHandle
for the first explicit anchor that is
found within the connection's anchors when starting to search at the
given connection index, and incrementing the index by the given step per
iteration.startConnectionIndex
- The index at which the search starts.step
- The increment step (e.g. 1
or -1
).FXBendConnectionPolicy.AnchorHandle
for the first explicit anchor that is
found within the connection's anchors when starting to search at
the given index.public FXBendConnectionPolicy.AnchorHandle findExplicitAnchorBackward(int connectionIndex)
FXBendConnectionPolicy.AnchorHandle
for the first explicit anchor that can be
found when iterating the connection anchors backwards, starting at the
given connection index. If the anchor at the given index is an explicit
anchor, an FXBendConnectionPolicy.AnchorHandle
for that anchor will be returned. If no
explicit anchor is found, an exception is thrown, because the start and
end anchor of a connection need to be explicit.connectionIndex
- The index that specifies the anchor of the connection at which
the search starts.FXBendConnectionPolicy.AnchorHandle
for the previous explicit anchor.public FXBendConnectionPolicy.AnchorHandle findExplicitAnchorForward(int connectionIndex)
FXBendConnectionPolicy.AnchorHandle
for the first explicit anchor that can be
found when iterating the connection anchors forwards, starting at the
given connection index. If the anchor at the given index is an explicit
anchor, an FXBendConnectionPolicy.AnchorHandle
for that anchor will be returned. If no
explicit anchor is found, an exception is thrown, because the start and
end anchor of a connection need to be explicit.connectionIndex
- The index that specifies the anchor of the connection at which
the search starts.FXBendConnectionPolicy.AnchorHandle
for the next explicit anchor.protected IAnchor findOrCreateAnchor(Point positionInLocal, boolean canConnect)
IAnchor
that should replace the anchor of the
currently selected point. If the point can connect, the
IVisualPart
at the mouse position is queried for an
IAnchor
via a Provider
<IAnchor
> adapter.
Otherwise an (unconnected) anchor is create using
createUnconnectedAnchor(Point)
.positionInLocal
- A position in local coordinates of the connection.canConnect
- true
if the point can be attached to an
underlying IVisualPart
, otherwise false
.IAnchor
that replaces the anchor of the currently
modified point.protected FXBendConnectionOperation getBendOperation()
FXBendConnectionOperation
that is extracted from the
operation created by createOperation()
.FXBendConnectionOperation
that is extracted from the
operation created by createOperation()
.protected Connection getConnection()
Connection
that is manipulated by this policy.Connection
that is manipulated by this policy.protected java.util.List<IBendableContentPart.BendPoint> getCurrentBendPoints()
AbstractBendPolicy
getCurrentBendPoints
in class AbstractBendPolicy<javafx.scene.Node>
public IVisualPart<javafx.scene.Node,Connection> getHost()
IPolicy
getHost
in interface IPolicy<javafx.scene.Node>
getHost
in class AbstractPolicy<javafx.scene.Node>
IPolicy
.protected Point getMouseDeltaInLocal(Point initialMousePositionInScene, Point currentMousePositionInScene)
initialMousePositionInScene
- The initial mouse position in scene coordinates.currentMousePositionInScene
- The current mouse position in scene coordinates.protected double getOverlayThreshold()
GridModel.isShowGrid()
, then the grid cell size is used to
determine the overlay threshold. Otherwise, the
DEFAULT_OVERLAY_THRESHOLD
is used.public void init()
AbstractTransactionPolicy
IllegalStateException
. It is safe to call AbstractTransactionPolicy.init()
multiple times in sequence.init
in class AbstractBendPolicy<javafx.scene.Node>
protected void insertExplicitAnchor(int insertionIndex, Point mouseInScene)
insertionIndex
- The explicit anchor index at which the new anchor is inserted.mouseInScene
- The position for the new anchor in scene coordinates.public boolean isExplicit(int connectionIndex)
true
if the anchor at the given connection index is
explicit. Otherwise returns false
.connectionIndex
- The connection index that specifies the anchor to test.true
if the specified anchor is explicit, otherwise
false
.public boolean isSelectionOnHorizontalLine()
true
if the selected anchors are on a horizontal
line, i.e. they share an equal Y coordinate. Otherwise returns
false
.true
if the Y coordinates of the selected anchors
are the same, otherwise false
.public FXBendConnectionPolicy.AnchorHandle makeExplicit(int connectionIndex)
FXBendConnectionPolicy.AnchorHandle
for it.connectionIndex
- The connection index to make explicit.FXBendConnectionPolicy.AnchorHandle
for the given connection index.public java.util.List<FXBendConnectionPolicy.AnchorHandle> makeExplicit(int startConnectionIndex, int endConnectionIndex)
FXBendConnectionPolicy.AnchorHandle
s for them.startConnectionIndex
- The first connection index to make explicit.endConnectionIndex
- The last connection index to make explicit.FXBendConnectionPolicy.AnchorHandle
s for the given range of indices.public void move(Point initialMouseInScene, Point currentMouseInScene)
initialMouseInScene
- The initial mouse position in scene coordinates.currentMouseInScene
- The current mouse position in scene coordinates.public void normalize()
public void select(FXBendConnectionPolicy.AnchorHandle explicitAnchorHandle)
explicitAnchorHandle
- Index of the explicit anchor to select for manipulation.public void selectSegment(int segmentIndex)
segmentIndex
- The index of a connection segment.public java.lang.String toString()
toString
in class java.lang.Object
Copyright (c) 2014 itemis AG and others. All rights reserved.