org.eclipse.gef.mvc.fx.policies

## Class BendConnectionPolicy

- java.lang.Object
- - org.eclipse.gef.common.adapt.IAdaptable.Bound.Impl<IVisualPart<? extends Node>>
  - - org.eclipse.gef.mvc.fx.policies.AbstractPolicy
    - - org.eclipse.gef.mvc.fx.policies.BendConnectionPolicy

All Implemented Interfaces:
  IAdaptable.Bound<IVisualPart<? extends Node>>, IPolicy

    public class BendConnectionPolicy
    extends AbstractPolicy

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

Fields
`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 Summary

Constructors
Constructor and Description
`BendConnectionPolicy()`

### Method Summary

All Methods Instance Methods Concrete Methods
`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 previous `AbstractPolicy.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 `AbstractPolicy` through its "work" methods.
`protected BendVisualOperation` `getBendOperation()` Returns an `BendVisualOperation` that is extracted from the operation created by `createOperation()`.
`protected Connection` `getConnection()` Returns the `Connection` that is manipulated by this policy.
`protected 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.
`IBendableContentPart<Connection>` `getHost()` Returns the host of this `IPolicy`, i.e. the `IVisualPart` this `IPolicy` is attached to.
`protected List<IBendableContentPart.BendPoint>` `getInitialBendPoints()` Returns the initial bend points before bending the content.
`protected double` `getOverlayThreshold()` Removes the overlay threshold, i.e. the distance between two points, so that they are regarded as overlaying.
`List<Point>` `getSelectedInitialPositions()` Returns the initial positions of the selected points in the local coordinate system of the `getConnection()`.
`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.
`List<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.
`protected void` `setNewHints(Point startHint, Point endHint)` Updates the positions (hints) for attached bend points.
`String` `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 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

### Constructor Detail

#### BendConnectionPolicy

    public BendConnectionPolicy()

### 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:
  `true` if the anchor at the given index can be connected, otherwise `false`.

#### commit

    public ITransactionalOperation commit()

Description copied from class: `AbstractPolicy`
Returns an `ITransactionalOperation` that performs all manipulations applied by the policy since the previous `AbstractPolicy.init()` call.

Specified by:
  `commit` in interface `IPolicy`
Overrides:
  `commit` in class `AbstractPolicy`
Returns:
  An `ITransactionalOperation` that performs all manipulations applied by the policy since the last `AbstractPolicy.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: `AbstractPolicy`
Creates an `ITransactionalOperation` that is used to encapsulate the changes that are applied by this `AbstractPolicy` through its "work" methods. The created operation should allow for `local execution` at each time.

Specified by:
  `createOperation` in class `AbstractPolicy`
Returns:
  A new `ITransactionalOperation` to encapsulate all applied changes.

#### getBendOperation

    protected BendVisualOperation getBendOperation()

Returns an `BendVisualOperation` that is extracted from the operation created by `createOperation()`.

Returns:
  an `BendVisualOperation` that is extracted from the operation created by `createOperation()`.

#### getConnection

    protected Connection getConnection()

Returns the `Connection` that is manipulated by this policy.

Returns:
  The `Connection` that is manipulated by this policy.

#### getCurrentBendPoints

    protected 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. `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

    public IBendableContentPart<Connection> getHost()

Description copied from interface: `IPolicy`
Returns the host of this `IPolicy`, i.e. the `IVisualPart` this `IPolicy` is attached to.

Returns:
  The host of this `IPolicy`.

#### getInitialBendPoints

    protected 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, the `DEFAULT_OVERLAY_THRESHOLD` is used.

Returns:
  The overlay threshold.

#### getSelectedInitialPositions

    public List<Point> getSelectedInitialPositions()

Returns the initial positions of the selected points in the local coordinate system of the `getConnection()`. May be `null` prior to the first `move(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 an `IllegalStateException`, as well as re-initializing before committing or rolling back.

Specified by:
  `init` in interface `IPolicy`
Overrides:
  `init` in class `AbstractPolicy`

#### 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)

Returns `true` if the anchor at the given connection index is explicit. Otherwise returns `false`.

Parameters:
  `connectionIndex` - The connection index that specifies the anchor to test.
Returns:
  `true` if the specified anchor is explicit, otherwise `false`.

#### isSelectionHorizontal

    public boolean isSelectionHorizontal()

Returns `true` if the selected points are on a horizontal line. Otherwise returns `false`.

Returns:
  `true` if the selected points are on a horizontal line, otherwise `false`.

#### locallyExecuteOperation

    protected void locallyExecuteOperation()

Description copied from class: `AbstractPolicy`
Locally executes the `ITransactionalOperation` that is updated by this policy, i.e. not on the operation history. Maybe used in the "work" operations of subclasses.

Overrides:
  `locallyExecuteOperation` in class `AbstractPolicy`

#### 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 List<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's `IConnectionRouter` 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

    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 String toString()

Overrides:
  `toString` in class `Object`