Interface CaretSelectionBind<PS,​SEG,​S>

  • Type Parameters:
    PS - type for StyledDocument's paragraph style; only necessary when using the "selectedDocument" getter or property
    SEG - type for StyledDocument's segment type; only necessary when using the "selectedDocument" getter or property
    S - type for StyledDocument's segment style; only necessary when using the "selectedDocument" getter or property
    All Superinterfaces:
    Caret, Selection<PS,​SEG,​S>

    public interface CaretSelectionBind<PS,​SEG,​S>
    extends Selection<PS,​SEG,​S>, Caret
    An object for encapsulating a caret and a selection in a given area where the caret and selection are bound to one another. In other words, selecting some range in the area (via selectRangeExpl(int, int), selectRange(int, int, int, int)) will move the caret in the same call, except if one uses displaceSelection(int, int). Updating the selection via any method with an "update" prefix from Selection will also move the caret if it has been displaced or the anchor is not the boundary (i.e. the selection's the start or end position) that is being updated. Likewise, moving the caret via the "move" prefix methods from Caret will clear the selection in the same call, except if one uses displaceCaret(int).

    "Position" refers to the place in-between characters. In other words, every "|" in "|t|e|x|t|" is a valid position. There are two kinds of positions used here:

    1. Selection.getStartPosition()/Selection.getEndPosition(), which refers to a position somewhere in the entire area's content. It's bounds are 0 <= x <= area.getLength().
    2. Selection.getStartColumnPosition()/Selection.getEndColumnPosition(), which refers to a position somewhere in the current paragraph. It's bounds are 0 <= x <= area.getParagraphLength(index).
    Note: when parameter names are "position" without the "column" prefix, they refer to the position in the entire area.

    The selection is typically made using the anchor's position and the underlying caret's position. Hence, selectRangeExpl(int, int) is the typical method to use, although selectRange(int, int) can also be used.

    For type safety, Selection.getSelectedDocument() requires the same generic types from StyledDocument. This means that one must write a lot of boilerplate for the generics: CaretSelectionBind<Collection<String>, StyledText<Collection<String>>, Collection<String>> selection. However, this is only necessary if one is using Selection.getSelectedDocument() or Selection.selectedDocumentProperty(). If you are not going to use the "selectedDocument" getter or property, then just write the much simpler CaretSelectionBind<?, ?, ?> selection.

    See Also:
    Caret, Selection
    • Property Detail

      • anchorPosition

        javafx.beans.value.ObservableValue<java.lang.Integer> anchorPositionProperty
        See Also:
        getAnchorPosition()
      • anchorParIndex

        javafx.beans.value.ObservableValue<java.lang.Integer> anchorParIndexProperty
        See Also:
        getAnchorParIndex()
      • anchorColPosition

        javafx.beans.value.ObservableValue<java.lang.Integer> anchorColPositionProperty
        See Also:
        getAnchorColPosition()
    • Method Detail

      • getUnderlyingCaret

        CaretNode getUnderlyingCaret()
      • getUnderlyingSelection

        Selection<PS,​SEG,​S> getUnderlyingSelection()
      • getAnchorPosition

        int getAnchorPosition()
        Gets the value of the property anchorPosition.
        Property description:
      • anchorPositionProperty

        javafx.beans.value.ObservableValue<java.lang.Integer> anchorPositionProperty()
        See Also:
        getAnchorPosition()
      • getAnchorParIndex

        int getAnchorParIndex()
        Gets the value of the property anchorParIndex.
        Property description:
      • anchorParIndexProperty

        javafx.beans.value.ObservableValue<java.lang.Integer> anchorParIndexProperty()
        See Also:
        getAnchorParIndex()
      • getAnchorColPosition

        int getAnchorColPosition()
        Gets the value of the property anchorColPosition.
        Property description:
      • anchorColPositionProperty

        javafx.beans.value.ObservableValue<java.lang.Integer> anchorColPositionProperty()
        See Also:
        getAnchorColPosition()
      • moveTo

        default void moveTo​(int position)
        Moves the caret to the given position in the text and clears any selection.
        Specified by:
        moveTo in interface Caret
      • moveToParStart

        default void moveToParStart()
        Moves the caret to the beginning of the current paragraph and clears any selection
        Specified by:
        moveToParStart in interface Caret
      • moveToParEnd

        default void moveToParEnd()
        Moves the caret to the end of the current paragraph and clears any selection
        Specified by:
        moveToParEnd in interface Caret
      • moveToAreaStart

        default void moveToAreaStart()
        Moves the caret to the beginning of the area and clears any selection
        Specified by:
        moveToAreaStart in interface Caret
      • moveToAreaEnd

        default void moveToAreaEnd()
        Moves the caret to the end of the area and clears any selection
        Specified by:
        moveToAreaEnd in interface Caret
      • moveToPrevChar

        default void moveToPrevChar()
        Moves the caret backward one char in the text and clears any selection
        Specified by:
        moveToPrevChar in interface Caret
      • moveToNextChar

        default void moveToNextChar()
        Moves the caret forward one char in the text and clears any selection
        Specified by:
        moveToNextChar in interface Caret
      • moveBreaksForwards

        void moveBreaksForwards​(int numOfBreaks,
                                java.text.BreakIterator breakIterator)
        Moves the caret forwards by the number of breaks and clears any selection
        Specified by:
        moveBreaksForwards in interface Caret
      • moveBreaksBackwards

        void moveBreaksBackwards​(int numOfBreaks,
                                 java.text.BreakIterator breakIterator)
        Moves the caret backwards by the number of breaks and clears any selection
        Specified by:
        moveBreaksBackwards in interface Caret
      • selectRange

        void selectRange​(int startParagraphIndex,
                         int startColPosition,
                         int endParagraphIndex,
                         int endColPosition)
        Selects the given range and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end

        Caution: see TextEditingArea.getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

        Specified by:
        selectRange in interface Selection<PS,​SEG,​S>
      • selectRange

        void selectRange​(int startPosition,
                         int endPosition)
        Selects the given range and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end
        Specified by:
        selectRange in interface Selection<PS,​SEG,​S>
      • updateStartTo

        void updateStartTo​(int paragraphIndex,
                           int columnPosition)
        Specified by:
        updateStartTo in interface Selection<PS,​SEG,​S>
      • updateEndTo

        void updateEndTo​(int paragraphIndex,
                         int columnPosition)
        Specified by:
        updateEndTo in interface Selection<PS,​SEG,​S>
      • updateEndByBreaksForward

        void updateEndByBreaksForward​(int numOfBreaks,
                                      java.text.BreakIterator breakIterator)
        Specified by:
        updateEndByBreaksForward in interface Selection<PS,​SEG,​S>
      • updateEndByBreaksBackward

        void updateEndByBreaksBackward​(int numOfBreaks,
                                       java.text.BreakIterator breakIterator)
        Specified by:
        updateEndByBreaksBackward in interface Selection<PS,​SEG,​S>
      • selectAll

        void selectAll()
        Selects everything in the area and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end
        Specified by:
        selectAll in interface Selection<PS,​SEG,​S>
      • selectParagraph

        void selectParagraph​(int paragraphIndex)
        Selects the given paragraph and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end
        Specified by:
        selectParagraph in interface Selection<PS,​SEG,​S>
      • selectWord

        void selectWord​(int wordPositionInArea)
        Selects the closest word to the given position in the area and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end
        Specified by:
        selectWord in interface Selection<PS,​SEG,​S>
      • deselect

        void deselect()
        Clears the selection while keeping the caret position the same.
        Specified by:
        deselect in interface Selection<PS,​SEG,​S>
      • selectRangeExpl

        void selectRangeExpl​(int anchorParagraph,
                             int anchorColumn,
                             int caretParagraph,
                             int caretColumn)
        Positions the anchor and caretPosition explicitly, effectively creating a selection.
      • selectRangeExpl

        void selectRangeExpl​(int anchorPosition,
                             int caretPosition)
        Positions the anchor and caretPosition explicitly, effectively creating a selection.
      • moveTo

        default void moveTo​(int pos,
                            NavigationActions.SelectionPolicy selectionPolicy)
        Moves the caret to the position indicated by pos. Based on the selection policy, the selection is either cleared (i.e. anchor is set to the same position as caret), adjusted (i.e. anchor is not moved at all), or extended (i.e. pos becomes the new caret and, if pos points outside the current selection, the far end of the current selection becomes the anchor.
      • moveToPrevChar

        void moveToPrevChar​(NavigationActions.SelectionPolicy selectionPolicy)
        Moves the caret backward one char in the text. Based on the given selection policy, anchor either moves with the caret, stays put, or moves to the former caret position.
      • moveToNextChar

        void moveToNextChar​(NavigationActions.SelectionPolicy selectionPolicy)
        Moves the caret forward one char in the text. Based on the given selection policy, anchor either moves with the caret, stays put, or moves to the former caret position.
      • selectParagraph

        default void selectParagraph()
      • selectWord

        default void selectWord()
        Selects the word closest to the caret
      • displaceCaret

        void displaceCaret​(int position)
        Displaces the caret from the selection by positioning only the caret to the new location without also affecting the selection's getAnchorPosition() anchor} or the Selection.getRange() selection}. Do not confuse this method with moveTo(int), which is the normal way of moving the caret. This method can be used to achieve the special case of positioning the caret outside or inside the selection, as opposed to always being at the boundary. Use with care.
      • displaceSelection

        void displaceSelection​(int startPosition,
                               int endPosition)
        Displaces the caret from the selection by positioning only the selection to the new location without also affecting the caret's position. This method can be used to achieve the special case of selecting some range in the area without affecting the caret's position. Use with care.