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
IVisualPartunder mouse when applicable.
-
Property Summary
Properties inherited from class org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl
adaptableProperties 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
FieldsModifier and TypeFieldDescriptionprotected static final doubleThe overlay threshold, i.e. the distance between two points so that they are regarded as overlying.protected static final doubleThe overlay threshold, i.e. the distance between two points so that they are regarded as overlying. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanConnect(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 anITransactionalOperationthat performs all manipulations applied by the policy since the previousAbstractPolicy.init()call.intcreateAfter(int explicitAnchorIndex, Point mouseInScene) Creates a new anchor after the anchor specified by the given explicit anchor index.intcreateBefore(int explicitAnchorIndex, Point mouseInScene) Creates a new anchor before the anchor specified by the given explicit anchor index.protected ITransactionalOperationCreates anITransactionalOperationthat is used to encapsulate the changes that are applied by thisAbstractPolicythrough its "work" methods.protected BendVisualOperationReturns anBendVisualOperationthat is extracted from the operation created bycreateOperation().protected ConnectionReturns theConnectionthat is manipulated by this policy.protected List<IBendableContentPart.BendPoint>Returns the current control points of the content.protected intgetExplicitIndex(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.intgetExplicitIndexAtOrAfter(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.intgetExplicitIndexAtOrBefore(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 doubleRemoves 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().voidinit()Initializes the policy, so that the policy's "work" methods can be used.protected voidinsertExplicitAnchor(int insertionIndex, Point mouseInScene) Creates a new static anchor for the given position and inserts it at the given index.booleanisExplicit(int connectionIndex) Returnstrueif the anchor at the given connection index is explicit.booleanReturnstrueif the selected points are on a horizontal line.protected voidLocally executes theITransactionalOperationthat is updated by this policy, i.e. not on the operation history.intmakeExplicit(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.voidMoves the currently selected point to the given mouse position in scene coordinates.voidFor 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 voidroute()Provides position hints to the connection'sIConnectionRouterand let's the router route the connection, so these position hints can be forwarded to the anchors.voidselect(int explicitAnchorIndex) Selects the point specified by the given segment index and parameter for manipulation.voidselectSegment(int segmentIndex) Selects the end points of the connection segment specified by the given index.protected voidsetNewHints(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, rollbackMethods inherited from class org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl
adaptableProperty, getAdaptable, setAdaptableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:
trueif the anchor at the given index can be connected, otherwisefalse.
-
commit
Description copied from class:AbstractPolicyReturns anITransactionalOperationthat performs all manipulations applied by the policy since the previousAbstractPolicy.init()call.- Specified by:
commitin interfaceIPolicy- Overrides:
commitin classAbstractPolicy- Returns:
- An
ITransactionalOperationthat 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:AbstractPolicyCreates anITransactionalOperationthat is used to encapsulate the changes that are applied by thisAbstractPolicythrough its "work" methods. The created operation should allow forlocal executionat each time.- Specified by:
createOperationin classAbstractPolicy- Returns:
- A new
ITransactionalOperationto encapsulate all applied changes.
-
getBendOperation
Returns anBendVisualOperationthat is extracted from the operation created bycreateOperation().- Returns:
- an
BendVisualOperationthat is extracted from the operation created bycreateOperation().
-
getConnection
Returns theConnectionthat is manipulated by this policy.- Returns:
- The
Connectionthat 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.1or-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_THRESHOLDis used.- Returns:
- The overlay threshold.
-
getSelectedInitialPositions
Returns the initial positions of the selected points in the local coordinate system of thegetConnection(). May benullprior 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:AbstractPolicyInitializes 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:
initin interfaceIPolicy- Overrides:
initin 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) Returnstrueif the anchor at the given connection index is explicit. Otherwise returnsfalse.- Parameters:
connectionIndex- The connection index that specifies the anchor to test.- Returns:
trueif the specified anchor is explicit, otherwisefalse.
-
isSelectionHorizontal
public boolean isSelectionHorizontal()Returnstrueif the selected points are on a horizontal line. Otherwise returnsfalse.- Returns:
trueif the selected points are on a horizontal line, otherwisefalse.
-
locallyExecuteOperation
protected void locallyExecuteOperation()Description copied from class:AbstractPolicyLocally executes theITransactionalOperationthat is updated by this policy, i.e. not on the operation history. Maybe used in the "work" operations of subclasses.- Overrides:
locallyExecuteOperationin 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'sIConnectionRouterand 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
-