Class TextAreaSelection


  • public class TextAreaSelection
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void disableSelectionIfEmpty()  
      boolean getBiasLeft()  
      int getCaretLine()
      Returns the caret line.
      int getCaretPosition()
      Returns the caret position.
      @NotNull SyntaxDocument getDocument()
      Returns the document this text area is editing.
      int getDocumentLength()
      Returns the length of the document.
      int getLineCount()
      Returns the number of lines in the document.
      int getLineEndOffset​(int line)
      Returns the end offset of the specified line.
      int getLineLength​(int line)
      Returns the length of the specified line.
      int getLineOfOffset​(int offset)
      Returns the line containing the specified offset.
      int getLineStartOffset​(int line)
      Returns the start offset of the specified line.
      @NotNull java.lang.CharSequence getLineText​(int lineIndex)
      Returns the text on the specified line.
      void getLineText​(int lineIndex, @NotNull javax.swing.text.Segment segment)
      Copies the text on the specified line into a segment.
      int getMarkPosition()
      Returns the mark position.
      @Nullable java.lang.String getSelectedText()
      Returns the selected text, or null if no selection is active.
      int getSelectionEnd()
      Returns the selection end offset.
      int getSelectionEndLine()
      Returns the selection end line.
      int getSelectionStart()
      Returns the selection start offset.
      int getSelectionStartLine()
      Returns the selection start line.
      @NotNull java.lang.String getText()
      Returns the entire text of this text area.
      @Nullable java.lang.String getText​(int start, int len)
      Returns the specified substring of the document.
      void getText​(int start, int len, @NotNull javax.swing.text.Segment segment)
      Copies the specified substring of the document into a segment.
      @Nullable TokenMarker getTokenMarker()
      Returns the document's token marker.
      boolean isSelectionRectangular()
      Returns true if the selection is rectangular, false otherwise.
      void setSelectedText​(@NotNull java.lang.String selectedText)
      Replaces the selection with the specified text.
      void setSelection​(int newStart, int newEnd, int newStartLine, int newEndLine, boolean newBias)  
      void setSelectionRectangular​(boolean rectangleSelect)
      Sets if the selection should be rectangular.
      void setText​(@NotNull java.lang.String text)
      Sets the entire text of this text area.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TextAreaSelection

        public TextAreaSelection​(@NotNull
                                 @NotNull SyntaxDocument document)
        Creates a new instance.
        Parameters:
        document - the document to select in
    • Method Detail

      • getSelectionStart

        public int getSelectionStart()
        Returns the selection start offset.
      • getSelectionStartLine

        public int getSelectionStartLine()
        Returns the selection start line.
      • getSelectionEnd

        public int getSelectionEnd()
        Returns the selection end offset.
      • getSelectionEndLine

        public int getSelectionEndLine()
        Returns the selection end line.
      • getBiasLeft

        public boolean getBiasLeft()
      • getCaretPosition

        public int getCaretPosition()
        Returns the caret position. This will either be the selection start or the selection end, depending on which direction the selection was made in.
      • getCaretLine

        public int getCaretLine()
        Returns the caret line.
      • getMarkPosition

        public int getMarkPosition()
        Returns the mark position. This will be the opposite selection bound to the caret position.
        See Also:
        getCaretPosition()
      • setSelection

        public void setSelection​(int newStart,
                                 int newEnd,
                                 int newStartLine,
                                 int newEndLine,
                                 boolean newBias)
      • getSelectedText

        @Nullable
        public @Nullable java.lang.String getSelectedText()
        Returns the selected text, or null if no selection is active.
      • disableSelectionIfEmpty

        public void disableSelectionIfEmpty()
      • getText

        @Nullable
        public @Nullable java.lang.String getText​(int start,
                                                  int len)
        Returns the specified substring of the document.
        Parameters:
        start - the start offset
        len - the length of the substring
        Returns:
        the substring, or null if the offsets are invalid
      • getText

        public void getText​(int start,
                            int len,
                            @NotNull
                            @NotNull javax.swing.text.Segment segment)
        Copies the specified substring of the document into a segment. If the offsets are invalid, the segment will contain a null string.
        Parameters:
        start - the start offset
        len - the length of the substring
        segment - the segment
      • setSelectedText

        public void setSelectedText​(@NotNull
                                    @NotNull java.lang.String selectedText)
        Replaces the selection with the specified text.
        Parameters:
        selectedText - the replacement text for the selection
      • isSelectionRectangular

        public boolean isSelectionRectangular()
        Returns true if the selection is rectangular, false otherwise.
      • setSelectionRectangular

        public void setSelectionRectangular​(boolean rectangleSelect)
        Sets if the selection should be rectangular.
        Parameters:
        rectangleSelect - true if the selection should be rectangular, false otherwise
      • getDocument

        @NotNull
        public @NotNull SyntaxDocument getDocument()
        Returns the document this text area is editing.
      • getTokenMarker

        @Nullable
        public @Nullable TokenMarker getTokenMarker()
        Returns the document's token marker. Equivalent to calling getDocument().getTokenMarker().
      • getDocumentLength

        public int getDocumentLength()
        Returns the length of the document. Equivalent to calling getDocument().getLength().
      • getLineCount

        public int getLineCount()
        Returns the number of lines in the document.
      • getLineOfOffset

        public int getLineOfOffset​(int offset)
        Returns the line containing the specified offset.
        Parameters:
        offset - the offset
      • getLineStartOffset

        public int getLineStartOffset​(int line)
        Returns the start offset of the specified line.
        Parameters:
        line - the line
        Returns:
        the start offset of the specified line, or -1 if the line is invalid
      • getLineEndOffset

        public int getLineEndOffset​(int line)
        Returns the end offset of the specified line.
        Parameters:
        line - the line
        Returns:
        the end offset of the specified line, or -1 if the line is invalid
      • getLineLength

        public int getLineLength​(int line)
        Returns the length of the specified line.
        Parameters:
        line - the line
      • getText

        @NotNull
        public @NotNull java.lang.String getText()
        Returns the entire text of this text area.
      • setText

        public void setText​(@NotNull
                            @NotNull java.lang.String text)
        Sets the entire text of this text area.
      • getLineText

        @NotNull
        public @NotNull java.lang.CharSequence getLineText​(int lineIndex)
        Returns the text on the specified line.
        Parameters:
        lineIndex - the line
        Returns:
        the text, or null if the line is invalid
      • getLineText

        public void getLineText​(int lineIndex,
                                @NotNull
                                @NotNull javax.swing.text.Segment segment)
        Copies the text on the specified line into a segment. If the line is invalid, the segment will contain a null string.
        Parameters:
        lineIndex - the line