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.adaptable
IAdaptable.Bound.Impl<T extends IAdaptable>
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.
|
protected static double |
DEFAULT_SEGMENT_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. |
int |
createAfter(int explicitAnchorIndex,
Point mouseInScene)
Creates a new anchor after the anchor specified by the given explicit
anchor index.
|
int |
createBefore(int explicitAnchorIndex,
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 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.
|
protected int |
getExplicitIndex(int startConnectionIndex,
int step)
Returns the explicit anchor index 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.
|
int |
getExplicitIndexAtOrAfter(int connectionIndex)
Returns an explicit anchor index for the first explicit anchor that can
be found when iterating the connection anchors forwards, starting at the
given connection index.
|
int |
getExplicitIndexAtOrBefore(int connectionIndex)
Returns an explicit anchor index for the first explicit anchor that can
be found when iterating the connection anchors backwards, starting at the
given connection index.
|
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 |
isSelectionHorizontal()
Returns
true if the selected points are on a horizontal
line. |
protected void |
locallyExecuteOperation()
Locally executes the
ITransactionalOperation that is updated by
this policy, i.e. not on the operation history. |
int |
makeExplicit(int connectionIndex)
Makes the connection anchor at the given connection index explicit and
returns its explicit index.
|
java.util.List<java.lang.Integer> |
makeExplicit(int startConnectionIndex,
int endConnectionIndex)
Makes the connection anchors within the given range of connection indices
explicit and returns their explicit indices.
|
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.
|
protected void |
route()
Provides position hints to the connection's
IConnectionRouter and
let's the router route the connection, so these position hints can be
forwarded to the anchors. |
void |
select(int explicitAnchorIndex)
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, rollback
adaptableProperty, getAdaptable, setAdaptable
protected static final double DEFAULT_OVERLAY_THRESHOLD
protected static final double DEFAULT_SEGMENT_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 int createAfter(int explicitAnchorIndex, Point mouseInScene)
explicitAnchorIndex
- An explicit anchor index that references the explicit anchor
after which the new anchor is inserted.mouseInScene
- The position for the new anchor in scene coordinates.public int createBefore(int explicitAnchorIndex, Point mouseInScene)
explicitAnchorIndex
- An explicit anchor index that references the explicit anchor
before which the new anchor is inserted.mouseInScene
- The position for the new anchor in scene coordinates.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 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>
protected int getExplicitIndex(int startConnectionIndex, int step)
startConnectionIndex
- The index at which the search starts.step
- The increment step (e.g. 1
or -1
).public int getExplicitIndexAtOrAfter(int connectionIndex)
connectionIndex
- The index that specifies the anchor of the connection at which
the search starts.public int getExplicitIndexAtOrBefore(int connectionIndex)
connectionIndex
- The index that specifies the anchor of the connection at which
the search starts.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 isSelectionHorizontal()
true
if the selected points are on a horizontal
line. Otherwise returns false
.true
if the selected points are on a horizontal
line, otherwise false
.protected void locallyExecuteOperation()
AbstractTransactionPolicy
ITransactionalOperation
that is updated by
this policy, i.e. not on the operation history. Maybe used in the "work"
operations of subclasses.locallyExecuteOperation
in class AbstractTransactionPolicy<javafx.scene.Node>
public int makeExplicit(int connectionIndex)
connectionIndex
- The connection index to make explicit.public java.util.List<java.lang.Integer> makeExplicit(int startConnectionIndex, int endConnectionIndex)
startConnectionIndex
- The first connection index to make explicit.endConnectionIndex
- The last connection index to make explicit.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()
protected void route()
IConnectionRouter
and
let's the router route the connection, so these position hints can be
forwarded to the anchors.public void select(int explicitAnchorIndex)
explicitAnchorIndex
- 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.