Interface Caret

  • All Known Subinterfaces:
    CaretSelectionBind<PS,​SEG,​S>
    All Known Implementing Classes:
    CaretNode

    public interface Caret
    An object for encapsulating a caret in a given area.

    "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. getPosition(), which refers to a position somewhere in the entire area's content. It's bounds are 0 <= x <= area.getLength().
    2. getColumnPosition(), 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.

    "Line" refers either to a single paragraph when the area does not wrap its text or to a line on a multi-line paragraph when the area does wrap its text.

    • Method Detail

      • getPosition

        int getPosition()
        Gets the value of the property position.
        Property description:
        The position of the caret within the text
      • getParagraphIndex

        int getParagraphIndex()
        Gets the value of the property paragraphIndex.
        Property description:
        The paragraph index that contains this caret
      • getLineIndex

        OptionalInt getLineIndex()
        Gets the value of the property lineIndex.
        Property description:
        The line index of a multi-line paragraph that contains this caret
      • getColumnPosition

        int getColumnPosition()
        Gets the value of the property columnPosition.
        Property description:
        The column position of the caret on its given line
      • visibleProperty

        ObservableValue<Boolean> visibleProperty()
        Whether the caret is being shown in the viewport
      • isVisible

        boolean isVisible()
      • getBlinkRate

        Duration getBlinkRate()
        Gets the value of the property blinkRate.
        Property description:
      • setBlinkRate

        void setBlinkRate​(Duration blinkRate)
        Sets the value of the property blinkRate.
        Property description:
      • getCaretBounds

        Optional<Bounds> getCaretBounds()
        Gets the value of the property caretBounds.
        Property description:
        The selectionBoundsProperty of the caret in the Screen's coordinate system or Optional.empty() if caret is not visible in the viewport.
      • clearTargetOffset

        void clearTargetOffset()
        Clears the caret's x offset
      • getTargetOffset

        org.fxmisc.richtext.ParagraphBox.CaretOffsetX getTargetOffset()
        Stores the caret's current column position, so that moving the caret vertically will keep it close to its original offset in a line.
      • isBeingUpdated

        boolean isBeingUpdated()
      • moveTo

        void moveTo​(int paragraphIndex,
                    int columnPosition)
        Moves the caret to the given position in the area. If this caret is bound to a CaretSelectionBind, it displaces the caret from the selection by positioning only the caret to the new location without also affecting the CaretSelectionBind.getAnchorPosition() bounded selection's anchor} or the Selection.getRange() selection}.
        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.

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

      • moveTo

        void moveTo​(int position)
        Moves the caret to the given position in the area. If this caret is bound to a CaretSelectionBind, it displaces the caret from the selection by positioning only the caret to the new location without also affecting the CaretSelectionBind.getAnchorPosition() bounded selection's anchor} or the Selection.getRange() selection}.
        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.
      • moveToParStart

        void moveToParStart()
        Moves the caret to the beginning of the current paragraph.
      • moveToParEnd

        void moveToParEnd()
        Moves the caret to the end of the current paragraph.
      • moveToAreaStart

        default void moveToAreaStart()
        Moves the caret to the beginning of the area.
      • moveToAreaEnd

        void moveToAreaEnd()
        Moves the caret to the end of the area.
      • moveToPrevChar

        void moveToPrevChar()
        Moves the caret backward one char in the text.
      • moveToNextChar

        void moveToNextChar()
        Moves the caret forward one char in the text.
      • moveBreaksForwards

        void moveBreaksForwards​(int numOfBreaks,
                                BreakIterator breakIterator)
        Moves the caret forwards by the number of breaks.
      • moveWordBreaksForwards

        default void moveWordBreaksForwards​(int numOfWordBreaks)
      • moveSentenceBreaksForwards

        default void moveSentenceBreaksForwards​(int numOfSentenceBreaks)
      • moveBreaksBackwards

        void moveBreaksBackwards​(int numOfBreaks,
                                 BreakIterator breakIterator)
        Moves the caret backwards by the number of breaks.
      • moveWordBreaksBackwards

        default void moveWordBreaksBackwards​(int numOfWordBreaks)
      • moveSentenceBreaksBackwards

        default void moveSentenceBreaksBackwards​(int numOfSentenceBreaks)
      • dispose

        void dispose()
        Disposes the caret and prevents memory leaks
      • getArea

        GenericStyledArea<?,​?,​?> getArea()
        Gets the area with which this caret is associated.
      • getCaretName

        String getCaretName()
        Gets the name of this caret. Each caret that is added to an area must have a unique name since it is used to distinguish it from others in a Set.