Package org.eclipse.gef.mvc.fx.policies
Class BendConnectionPolicy
java.lang.Object
org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl<IVisualPart<? extends javafx.scene.Node>>
org.eclipse.gef.mvc.fx.policies.AbstractPolicy
org.eclipse.gef.mvc.fx.policies.BendConnectionPolicy
- All Implemented Interfaces:
IAdaptable.Bound<IVisualPart<? extends javafx.scene.Node>>
,IPolicy
The
BendConnectionPolicy
can be used to manipulate the points
constituting an Connection
, i.e. its start, way, and end points. Each
point is realized though an IBendableContentPart.BendPoint
, 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:
- Removing overlaid neighbor points.
- Re-adding temporarily removed neighbor points.
- Reconnecting points to the
IVisualPart
under mouse when applicable.
-
Property Summary
Properties inherited from class org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl
adaptable
Properties inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound
adaptable
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound
IAdaptable.Bound.Impl<T extends IAdaptable>
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final double
The overlay threshold, i.e. the distance between two points so that they are regarded as overlying.protected static final double
The overlay threshold, i.e. the distance between two points so that they are regarded as overlying. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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.commit()
Returns anITransactionalOperation
that performs all manipulations applied by the policy since the previousAbstractPolicy.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
Creates anITransactionalOperation
that is used to encapsulate the changes that are applied by thisAbstractPolicy
through its "work" methods.protected BendVisualOperation
Returns anBendVisualOperation
that is extracted from the operation created bycreateOperation()
.protected Connection
Returns theConnection
that is manipulated by this policy.protected List<IBendableContentPart.BendPoint>
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.getHost()
protected List<IBendableContentPart.BendPoint>
Returns the initial bend points before bending the content.protected double
Removes the overlay threshold, i.e. the distance between two points, so that they are regarded as overlaying.Returns the initial positions of the selected points in the local coordinate system of thegetConnection()
.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) Returnstrue
if the anchor at the given connection index is explicit.boolean
Returnstrue
if the selected points are on a horizontal line.protected void
Locally executes theITransactionalOperation
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.makeExplicit
(int startConnectionIndex, int endConnectionIndex) Makes the connection anchors within the given range of connection indices explicit and returns their explicit indices.void
Moves the currently selected point to the given mouse position in scene coordinates.void
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'sIConnectionRouter
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.protected void
setNewHints
(Point startHint, Point endHint) Updates the positions (hints) for attached bend points.toString()
Methods inherited from class org.eclipse.gef.mvc.fx.policies.AbstractPolicy
checkInitialized, getOperation, isInitialized, rollback
Methods inherited from class org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl
adaptableProperty, getAdaptable, setAdaptable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound
adaptableProperty, getAdaptable, setAdaptable
-
Field Details
-
DEFAULT_OVERLAY_THRESHOLD
protected static final double DEFAULT_OVERLAY_THRESHOLDThe overlay threshold, i.e. the distance between two points so that they are regarded as overlying.- See Also:
-
DEFAULT_SEGMENT_OVERLAY_THRESHOLD
protected static final double DEFAULT_SEGMENT_OVERLAY_THRESHOLDThe overlay threshold, i.e. the distance between two points so that they are regarded as overlying.- See Also:
-
-
Constructor Details
-
BendConnectionPolicy
public BendConnectionPolicy()
-
-
Method Details
-
canConnect
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. Per default, only the start and the end index can be connected.- Parameters:
explicitAnchorIndex
- The explicit anchor index for which to determine if it can be connected.- Returns:
true
if the anchor at the given index can be connected, otherwisefalse
.
-
commit
Description copied from class:AbstractPolicy
Returns anITransactionalOperation
that performs all manipulations applied by the policy since the previousAbstractPolicy.init()
call.- Specified by:
commit
in interfaceIPolicy
- Overrides:
commit
in classAbstractPolicy
- Returns:
- An
ITransactionalOperation
that performs all manipulations applied by the policy since the lastAbstractPolicy.init()
call.
-
createAfter
Creates a new anchor after the anchor specified by the given explicit anchor index. Returns the new anchor's explicit index.- Parameters:
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.- Returns:
- The index for the new anchor.
-
createBefore
Creates a new anchor before the anchor specified by the given explicit anchor index. Returns the new anchor's explicit index.- Parameters:
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.- Returns:
- The index for the new anchor.
-
createOperation
Description copied from class:AbstractPolicy
Creates anITransactionalOperation
that is used to encapsulate the changes that are applied by thisAbstractPolicy
through its "work" methods. The created operation should allow forlocal execution
at each time.- Specified by:
createOperation
in classAbstractPolicy
- Returns:
- A new
ITransactionalOperation
to encapsulate all applied changes.
-
getBendOperation
Returns anBendVisualOperation
that is extracted from the operation created bycreateOperation()
.- Returns:
- an
BendVisualOperation
that is extracted from the operation created bycreateOperation()
.
-
getConnection
Returns theConnection
that is manipulated by this policy.- Returns:
- The
Connection
that is manipulated by this policy.
-
getCurrentBendPoints
Returns the current control points of the content.- Returns:
- The current control points.
-
getExplicitIndex
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.- Parameters:
startConnectionIndex
- The index at which the search starts.step
- The increment step (e.g.1
or-1
).- 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 index.
-
getExplicitIndexAtOrAfter
public 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. If the anchor at the given index is an explicit anchor, an explicit anchor index 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.- Parameters:
connectionIndex
- The index that specifies the anchor of the connection at which the search starts.- Returns:
- An explicit anchor index for the next explicit anchor.
-
getExplicitIndexAtOrBefore
public 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. If the anchor at the given index is an explicit anchor, an explicit anchor index 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.- Parameters:
connectionIndex
- The index that specifies the anchor of the connection at which the search starts.- Returns:
- An explicit anchor index for the previous explicit anchor.
-
getHost
Description copied from interface:IPolicy
- Returns:
- The host of this
IPolicy
.
-
getInitialBendPoints
Returns the initial bend points before bending the content.- Returns:
- The initial bend points.
-
getOverlayThreshold
protected double getOverlayThreshold()Removes the overlay threshold, i.e. the distance between two points, so that they are regarded as overlaying. When the background grid is enables (GridModel.isShowGrid()
, then the grid cell size is used to determine the overlay threshold. Otherwise, theDEFAULT_OVERLAY_THRESHOLD
is used.- Returns:
- The overlay threshold.
-
getSelectedInitialPositions
Returns the initial positions of the selected points in the local coordinate system of thegetConnection()
. May benull
prior to the firstmove(Point, Point)
call.- Returns:
- The initial positions of the selected points in the local
coordinate system of the
getConnection()
.
-
init
public void init()Description copied from class:AbstractPolicy
Initializes the policy, so that the policy's "work" methods can be used. Calling a "work" method while the policy is not initialized will result in anIllegalStateException
, as well as re-initializing before committing or rolling back.- Specified by:
init
in interfaceIPolicy
- Overrides:
init
in classAbstractPolicy
-
insertExplicitAnchor
Creates a new static anchor for the given position and inserts it at the given index.- Parameters:
insertionIndex
- The explicit anchor index at which the new anchor is inserted.mouseInScene
- The position for the new anchor in scene coordinates.
-
isExplicit
public boolean isExplicit(int connectionIndex) Returnstrue
if the anchor at the given connection index is explicit. Otherwise returnsfalse
.- Parameters:
connectionIndex
- The connection index that specifies the anchor to test.- Returns:
true
if the specified anchor is explicit, otherwisefalse
.
-
isSelectionHorizontal
public boolean isSelectionHorizontal()Returnstrue
if the selected points are on a horizontal line. Otherwise returnsfalse
.- Returns:
true
if the selected points are on a horizontal line, otherwisefalse
.
-
locallyExecuteOperation
protected void locallyExecuteOperation()Description copied from class:AbstractPolicy
Locally executes theITransactionalOperation
that is updated by this policy, i.e. not on the operation history. Maybe used in the "work" operations of subclasses.- Overrides:
locallyExecuteOperation
in classAbstractPolicy
-
makeExplicit
public int makeExplicit(int connectionIndex) Makes the connection anchor at the given connection index explicit and returns its explicit index.- Parameters:
connectionIndex
- The connection index to make explicit.- Returns:
- The (new) explicit index for the given connection index.
-
makeExplicit
Makes the connection anchors within the given range of connection indices explicit and returns their explicit indices.- Parameters:
startConnectionIndex
- The first connection index to make explicit.endConnectionIndex
- The last connection index to make explicit.- Returns:
- A list of explicit anchor indices for the given range of connection indices.
-
move
Moves the currently selected point to the given mouse position in scene coordinates.- Parameters:
initialMouseInScene
- The initial mouse position in scene coordinates.currentMouseInScene
- The current mouse position in scene coordinates.
-
normalize
public 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. -
route
protected void route()Provides position hints to the connection'sIConnectionRouter
and let's the router route the connection, so these position hints can be forwarded to the anchors. -
select
public void select(int explicitAnchorIndex) Selects the point specified by the given segment index and parameter for manipulation. Captures the initial position of the selected point and the related initial mouse location.- Parameters:
explicitAnchorIndex
- Index of the explicit anchor to select for manipulation.
-
selectSegment
public void selectSegment(int segmentIndex) Selects the end points of the connection segment specified by the given index. Makes the corresponding anchors explicit first and copies them if they are connected.- Parameters:
segmentIndex
- The index of a connection segment.
-
setNewHints
Updates the positions (hints) for attached bend points.- Parameters:
startHint
- The new start point hint.endHint
- The new end point hint.
-
toString
-