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
public class BendConnectionPolicy extends AbstractPolicy
TheBendConnectionPolicycan be used to manipulate the points constituting anConnection, i.e. its start, way, and end points. Each point is realized though anIBendableContentPart.BendPoint, which may either be local to theConnection(i.e. the anchor refers to theConnectionas anchorage), or it may be provided by anotherIVisualPart(i.e. the anchor is provided by aProvideradapted 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.gef.common.adapt.IAdaptable.Bound
IAdaptable.Bound.Impl<T extends IAdaptable>
-
-
Field Summary
Fields Modifier and Type Field Description protected static doubleDEFAULT_OVERLAY_THRESHOLDThe overlay threshold, i.e. the distance between two points so that they are regarded as overlying.protected static doubleDEFAULT_SEGMENT_OVERLAY_THRESHOLDThe overlay threshold, i.e. the distance between two points so that they are regarded as overlying.
-
Constructor Summary
Constructors Constructor Description BendConnectionPolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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.ITransactionalOperationcommit()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 ITransactionalOperationcreateOperation()Creates anITransactionalOperationthat is used to encapsulate the changes that are applied by thisAbstractPolicythrough its "work" methods.protected BendVisualOperationgetBendOperation()Returns anBendVisualOperationthat is extracted from the operation created bycreateOperation().protected ConnectiongetConnection()Returns theConnectionthat is manipulated by this policy.protected java.util.List<IBendableContentPart.BendPoint>getCurrentBendPoints()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.IBendableContentPart<Connection>getHost()protected java.util.List<IBendableContentPart.BendPoint>getInitialBendPoints()Returns the initial bend points before bending the content.protected doublegetOverlayThreshold()Removes the overlay threshold, i.e. the distance between two points, so that they are regarded as overlaying.java.util.List<Point>getSelectedInitialPositions()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.booleanisSelectionHorizontal()Returnstrueif the selected points are on a horizontal line.protected voidlocallyExecuteOperation()Locally 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.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.voidmove(Point initialMouseInScene, Point currentMouseInScene)Moves the currently selected point to the given mouse position in scene coordinates.voidnormalize()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 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.java.lang.StringtoString()-
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 Detail
-
DEFAULT_OVERLAY_THRESHOLD
protected static final double DEFAULT_OVERLAY_THRESHOLD
The overlay threshold, i.e. the distance between two points so that they are regarded as overlying.- See Also:
- Constant Field Values
-
DEFAULT_SEGMENT_OVERLAY_THRESHOLD
protected static final double DEFAULT_SEGMENT_OVERLAY_THRESHOLD
The overlay threshold, i.e. the distance between two points so that they are regarded as overlying.- See Also:
- Constant Field Values
-
-
Method Detail
-
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
public ITransactionalOperation 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
public int createAfter(int explicitAnchorIndex, Point mouseInScene)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
public int createBefore(int explicitAnchorIndex, Point mouseInScene)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
protected ITransactionalOperation 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
protected BendVisualOperation getBendOperation()
Returns anBendVisualOperationthat is extracted from the operation created bycreateOperation().- Returns:
- an
BendVisualOperationthat is extracted from the operation created bycreateOperation().
-
getConnection
protected Connection getConnection()
Returns theConnectionthat is manipulated by this policy.- Returns:
- The
Connectionthat is manipulated by this policy.
-
getCurrentBendPoints
protected java.util.List<IBendableContentPart.BendPoint> 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
public IBendableContentPart<Connection> getHost()
Description copied from interface:IPolicy- Returns:
- The host of this
IPolicy.
-
getInitialBendPoints
protected java.util.List<IBendableContentPart.BendPoint> 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
public java.util.List<Point> 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
protected void insertExplicitAnchor(int insertionIndex, Point mouseInScene)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
public 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.- 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
public void move(Point initialMouseInScene, Point currentMouseInScene)
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
protected void setNewHints(Point startHint, Point endHint)
Updates the positions (hints) for attached bend points.- Parameters:
startHint- The new start point hint.endHint- The new end point hint.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-