Class BendConnectionPolicy

  • All Implemented Interfaces:
    IAdaptable.Bound<IVisualPart<? extends javafx.scene.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.
    • 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.
      • 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.
      • getConnection

        protected Connection getConnection()
        Returns the Connection that is manipulated by this policy.
        Returns:
        The Connection that 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. 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.
      • 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, the DEFAULT_OVERLAY_THRESHOLD is 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 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.
      • 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'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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object