Class TextAreaSelection
- java.lang.Object
-
- net.sf.gridarta.textedit.textarea.TextAreaSelection
-
public class TextAreaSelection extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description TextAreaSelection(@NotNull SyntaxDocument document)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisableSelectionIfEmpty()booleangetBiasLeft()intgetCaretLine()Returns the caret line.intgetCaretPosition()Returns the caret position.@NotNull SyntaxDocumentgetDocument()Returns the document this text area is editing.intgetDocumentLength()Returns the length of the document.intgetLineCount()Returns the number of lines in the document.intgetLineEndOffset(int line)Returns the end offset of the specified line.intgetLineLength(int line)Returns the length of the specified line.intgetLineOfOffset(int offset)Returns the line containing the specified offset.intgetLineStartOffset(int line)Returns the start offset of the specified line.@NotNull java.lang.CharSequencegetLineText(int lineIndex)Returns the text on the specified line.voidgetLineText(int lineIndex, @NotNull javax.swing.text.Segment segment)Copies the text on the specified line into a segment.intgetMarkPosition()Returns the mark position.@Nullable java.lang.StringgetSelectedText()Returns the selected text, or null if no selection is active.intgetSelectionEnd()Returns the selection end offset.intgetSelectionEndLine()Returns the selection end line.intgetSelectionStart()Returns the selection start offset.intgetSelectionStartLine()Returns the selection start line.@NotNull java.lang.StringgetText()Returns the entire text of this text area.@Nullable java.lang.StringgetText(int start, int len)Returns the specified substring of the document.voidgetText(int start, int len, @NotNull javax.swing.text.Segment segment)Copies the specified substring of the document into a segment.@Nullable TokenMarkergetTokenMarker()Returns the document's token marker.booleanisSelectionRectangular()Returns true if the selection is rectangular, false otherwise.voidsetSelectedText(@NotNull java.lang.String selectedText)Replaces the selection with the specified text.voidsetSelection(int newStart, int newEnd, int newStartLine, int newEndLine, boolean newBias)voidsetSelectionRectangular(boolean rectangleSelect)Sets if the selection should be rectangular.voidsetText(@NotNull java.lang.String text)Sets the entire text of this text area.
-
-
-
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 offsetlen- 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 offsetlen- the length of the substringsegment- 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 callinggetDocument().getTokenMarker().
-
getDocumentLength
public int getDocumentLength()
Returns the length of the document. Equivalent to callinggetDocument().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
-
-