Interface TextEditingArea<PS,​SEG,​S>

    • Method Detail

      • getLength

        default int getLength()
        The number of Unicode code units in this text-editing area.
      • getLocale

        default Locale getLocale()
        This is used to determine word and sentence breaks while navigating or selecting. Override this method if your paragraph or text style accommodates Locales as well.
      • getText

        default String getText()
        Text content of this text-editing area.
      • getDocument

        StyledDocument<PS,​SEG,​S> getDocument()
        Rich-text content of this text-editing area. The returned document is immutable, it does not reflect subsequent edits of this text-editing area.
      • getContent

        EditableStyledDocument<PS,​SEG,​S> getContent()
        The underlying document of this area that can be displayed by multiple StyledTextAreas.
      • getSegOps

        SegmentOps<SEG,​S> getSegOps()
        Returns the object used for operating over segments and their styles
      • getCaretPosition

        default int getCaretPosition()
        The current position of the caret, as a character offset in the text. Most of the time, caret is at the boundary of the selection (if there is any selection). However, there are circumstances when the caret is positioned inside or outside the selected text. For example, when the user is dragging the selected text, the caret moves with the cursor to point at the position where the selected text moves upon release.
      • getCurrentParagraph

        default int getCurrentParagraph()
        Index of the current paragraph, i.e. the paragraph with the caret.
      • getCaretColumn

        default int getCaretColumn()
        The caret position within the current paragraph.
      • getCaretBounds

        default Optional<Bounds> getCaretBounds()
        Gets the bounds of the caret in the Screen's coordinate system or Optional.empty() if caret is not visible in the viewport.
      • getShowCaret

        default Caret.CaretVisibility getShowCaret()
        Indicates when this text area should display a caret.
      • setShowCaret

        default void setShowCaret​(Caret.CaretVisibility value)
        Sets the value of the property showCaret.
        Property description:
      • getAnchor

        default int getAnchor()
        The anchor of the selection. If there is no selection, this is the same as caret position.
      • getSelection

        default IndexRange getSelection()
        The selection range. One boundary is always equal to anchor, and the other one is most of the time equal to caret position.
      • getSelectedText

        default String getSelectedText()
        The selected text.
      • getSelectionBounds

        default Optional<Bounds> getSelectionBounds()
        Gets the bounds of the selection in the Screen's coordinate system if something is selected and visible in the viewport or Optional.empty() if selection is not visible in the viewport.
      • getParagraph

        default Paragraph<PS,​SEG,​S> getParagraph​(int index)
      • getParagraphLength

        default int getParagraphLength​(int index)
      • isBeingUpdated

        default boolean isBeingUpdated()
      • getText

        String getText​(int paragraphIndex)
        Returns text content of the given paragraph.
      • getText

        String getText​(int start,
                       int end)
        Returns text content of the given character range.
      • getText

        String getText​(IndexRange range)
        Returns text content of the given character range.
      • getText

        default String getText​(int startParagraph,
                               int startColumn,
                               int endParagraph,
                               int endColumn)
        Returns text content of the given character range.

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

      • subDocument

        StyledDocument<PS,​SEG,​S> subDocument​(int paragraphIndex)
        Returns rich-text content of the given paragraph.
      • subDocument

        StyledDocument<PS,​SEG,​S> subDocument​(int start,
                                                         int end)
        Returns rich-text content of the given character range.
      • subDocument

        default StyledDocument<PS,​SEG,​S> subDocument​(int startParagraph,
                                                                 int startColumn,
                                                                 int endParagraph,
                                                                 int endColumn)
        Returns rich-text content of the given character range.

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

      • getParagraphSelection

        default IndexRange getParagraphSelection​(int paragraph)
        Returns the selection range in the given paragraph. Note: this method will return IndexRange(start, paragraph.length() + 1) when the selection includes a newline character.
      • getParagraphSelection

        IndexRange getParagraphSelection​(Selection selection,
                                         int paragraph)
      • selectRange

        default void selectRange​(int anchor,
                                 int caretPosition)
        Positions the anchor and caretPosition explicitly, effectively creating a selection.
      • selectRange

        default void selectRange​(int anchorParagraph,
                                 int anchorColumn,
                                 int caretPositionParagraph,
                                 int caretPositionColumn)
        Positions the anchor and caretPosition explicitly, effectively creating a selection.

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

      • displaceCaret

        void displaceCaret​(int pos)
        Displaces the caret from the selection by positioning only the caret to the new location without also affecting the selection's anchor or the selection. Do not confuse this method with NavigationActions.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.
      • replaceText

        void replaceText​(int start,
                         int end,
                         String text)
        Replaces a range of characters with the given text. It must hold 0 <= start <= end <= getLength().
        Parameters:
        start - Start index of the range to replace, inclusive.
        end - End index of the range to replace, exclusive.
        text - The text to put in place of the deleted range. It must not be null.
      • replaceText

        default void replaceText​(int startParagraph,
                                 int startColumn,
                                 int endParagraph,
                                 int endColumn,
                                 String text)
        Replaces a range of characters with the given text. It must hold 0 <= start <= end <= getLength() where start = getAbsolutePosition(startParagraph, startColumn); and is inclusive, and int end = getAbsolutePosition(endParagraph, endColumn); and is exclusive.

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

        Parameters:
        text - The text to put in place of the deleted range. It must not be null.
      • replace

        void replace​(int start,
                     int end,
                     StyledDocument<PS,​SEG,​S> replacement)
        Replaces a range of characters with the given rich-text document.
      • replace

        void replace​(int start,
                     int end,
                     SEG seg,
                     S style)
        Replaces a range of characters with the given segment. It must hold 0 <= start <= end <= getLength().
        Parameters:
        start - Start index of the range to replace, inclusive.
        end - End index of the range to replace, exclusive.
        seg - The seg to put in place of the deleted range. It must not be null.
      • replace

        default void replace​(int startParagraph,
                             int startColumn,
                             int endParagraph,
                             int endColumn,
                             SEG seg,
                             S style)
        Replaces a range of characters with the given segment. It must hold 0 <= start <= end <= getLength() where start = getAbsolutePosition(startParagraph, startColumn); and is inclusive, and int end = getAbsolutePosition(endParagraph, endColumn); and is exclusive.

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

        Parameters:
        seg - The segment to put in place of the deleted range. It must not be null.
      • replace

        default void replace​(int startParagraph,
                             int startColumn,
                             int endParagraph,
                             int endColumn,
                             StyledDocument<PS,​SEG,​S> replacement)
        Replaces a range of characters with the given rich-text document.

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

      • replaceText

        default void replaceText​(IndexRange range,
                                 String text)
        Replaces a range of characters with the given text.
        Parameters:
        range - The range to replace. It must not be null.
        text - The text to put in place of the deleted range. It must not be null.
        See Also:
        replaceText(int, int, String)
      • replace

        default void replace​(IndexRange range,
                             SEG seg,
                             S style)
        Replaces a range of characters with the given seg.
        Parameters:
        range - The range to replace. It must not be null.
        seg - The segment to put in place of the deleted range. It must not be null.
        See Also:
        replace(int, int, Object, Object)
      • replace

        default void replace​(IndexRange range,
                             StyledDocument<PS,​SEG,​S> replacement)
        Equivalent to replace(range.getStart(), range.getEnd(), replacement).
      • getAbsolutePosition

        int getAbsolutePosition​(int paragraphIndex,
                                int columnIndex)
        Returns the absolute position (i.e. the spot in-between characters) to the left of the given column in the given paragraph.

        For example, given a text with only one line "text" and the columnIndex value of 1, "position 1" would be returned:

          ┌ character index 0
          | ┌ character index 1
          | |   ┌ character index 3
          | |   |
          v v   v
        
         |t|e|x|t|
        
         ^ ^     ^
         | |     |
         | |     â”” position 4
         | â”” position 1
         â”” position 0
         

        Warning: Off-By-One errors can easily occur

        If the column index spans outside of the given paragraph's length, the returned value will pass on to the previous/next paragraph. In other words, given a document with two paragraphs (where the first paragraph's text is "some" and the second "thing"), then the following statements are true:

        • getAbsolutePosition(0, "some".length()) == 4 == getAbsolutePosition(1, -1)
        • getAbsolutePosition(0, "some".length() + 1) == 5 == getAbsolutePosition(1, 0)
        Parameters:
        paragraphIndex - The index of the paragraph from which to start.
        columnIndex - If positive, the index going forward (the given paragraph's line or the next one(s)). If negative, the index going backward (the previous paragraph's line(s)
      • dispose

        void dispose()
        Disposes this area, preventing memory leaks.