Interface TextEditingArea<PS,SEG,S>
-
- Type Parameters:
S
- type of style that can be applied to text.
- All Known Subinterfaces:
ClipboardActions<PS,SEG,S>
,EditActions<PS,SEG,S>
,NavigationActions<PS,SEG,S>
- All Known Implementing Classes:
CodeArea
,GenericStyledArea
,InlineCssTextArea
,InlineCssTextField
,StyleClassedTextArea
,StyleClassedTextField
,StyledTextArea
,StyledTextField
public interface TextEditingArea<PS,SEG,S>
Interface for a text editing control. Defines the core methods. Other interfaces define default higher-level methods implemented on top of the core methods.
-
-
Property Summary
Properties Type Property Description default ObservableValue<Integer>
anchor
SuspendableNo
beingUpdated
True when an update to the area'sunderling editable document
is still occurring or the viewport is being updated.default ObservableValue<Optional<Bounds>>
caretBounds
default ObservableValue<Integer>
caretColumn
default ObservableValue<Integer>
caretPosition
default ObservableValue<Integer>
currentParagraph
ObservableValue<Integer>
length
default ObservableValue<String>
selectedText
default ObservableValue<Optional<Bounds>>
selectionBounds
default ObservableValue<IndexRange>
selection
default Var<Caret.CaretVisibility>
showCaret
ObservableValue<String>
text
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ObservableValue<Integer>
anchorProperty()
SuspendableNo
beingUpdatedProperty()
True when an update to the area'sunderling editable document
is still occurring or the viewport is being updated.default ObservableValue<Optional<Bounds>>
caretBoundsProperty()
default ObservableValue<Integer>
caretColumnProperty()
default ObservableValue<Integer>
caretPositionProperty()
MultiChangeBuilder<PS,SEG,S>
createMultiChange()
Starts building a list of changes to be used to update multiple portions of the underlying document in one call.MultiChangeBuilder<PS,SEG,S>
createMultiChange(int numOfChanges)
Same ascreateMultiChange()
but the number of changes are specified to be more memory efficient.default ObservableValue<Integer>
currentParagraphProperty()
void
displaceCaret(int pos)
void
dispose()
Disposes this area, preventing memory leaks.int
getAbsolutePosition(int paragraphIndex, int columnIndex)
Returns the absolute position (i.e.default int
getAnchor()
The anchor of the selection.default Optional<Bounds>
getCaretBounds()
Gets the bounds of the caret in the Screen's coordinate system orOptional.empty()
if caret is not visible in the viewport.default int
getCaretColumn()
The caret position within the current paragraph.default int
getCaretPosition()
The current position of the caret, as a character offset in the text.CaretSelectionBind<PS,SEG,S>
getCaretSelectionBind()
Gets the area's mainCaretSelectionBind
.EditableStyledDocument<PS,SEG,S>
getContent()
The underlying document of this area that can be displayed by multipleStyledTextArea
s.default int
getCurrentParagraph()
Index of the current paragraph, i.e.StyledDocument<PS,SEG,S>
getDocument()
Rich-text content of this text-editing area.default int
getLength()
The number of Unicode code units in this text-editing area.default Locale
getLocale()
This is used to determine word and sentence breaks while navigating or selecting.default Paragraph<PS,SEG,S>
getParagraph(int index)
default int
getParagraphLength(int index)
ObservableList<Paragraph<PS,SEG,S>>
getParagraphs()
Unmodifiable observable list of paragraphs in this text area.default IndexRange
getParagraphSelection(int paragraph)
Returns the selection range in the given paragraph.IndexRange
getParagraphSelection(Selection selection, int paragraph)
SegmentOps<SEG,S>
getSegOps()
Returns the object used for operating oversegments
and their stylesdefault String
getSelectedText()
The selected text.default IndexRange
getSelection()
The selection range.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 orOptional.empty()
if selection is not visible in the viewport.default Caret.CaretVisibility
getShowCaret()
Indicates when this text area should display a caret.default String
getText()
Text content of this text-editing area.String
getText(int paragraphIndex)
Returns text content of the given paragraph.String
getText(int start, int end)
Returns text content of the given character range.default String
getText(int startParagraph, int startColumn, int endParagraph, int endColumn)
Returns text content of the given character range.String
getText(IndexRange range)
Returns text content of the given character range.default boolean
isBeingUpdated()
ObservableValue<Integer>
lengthProperty()
EventStream<List<PlainTextChange>>
multiPlainChanges()
EventStream<List<RichTextChange<PS,SEG,S>>>
multiRichChanges()
EventStream<PlainTextChange>
plainTextChanges()
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.default void
replace(int startParagraph, int startColumn, int endParagraph, int endColumn, SEG seg, S style)
Replaces a range of characters with the given segment.void
replace(int start, int end, StyledDocument<PS,SEG,S> replacement)
Replaces a range of characters with the given rich-text document.void
replace(int start, int end, SEG seg, S style)
Replaces a range of characters with the given segment.default void
replace(IndexRange range, StyledDocument<PS,SEG,S> replacement)
Equivalent toreplace(range.getStart(), range.getEnd(), replacement)
.default void
replace(IndexRange range, SEG seg, S style)
Replaces a range of characters with the given seg.default void
replaceText(int startParagraph, int startColumn, int endParagraph, int endColumn, String text)
Replaces a range of characters with the given text.void
replaceText(int start, int end, String text)
Replaces a range of characters with the given text.default void
replaceText(IndexRange range, String text)
Replaces a range of characters with the given text.EventStream<RichTextChange<PS,SEG,S>>
richChanges()
default ObservableValue<String>
selectedTextProperty()
default ObservableValue<Optional<Bounds>>
selectionBoundsProperty()
default ObservableValue<IndexRange>
selectionProperty()
default void
selectRange(int anchor, int caretPosition)
Positions the anchor and caretPosition explicitly, effectively creating a selection.default void
selectRange(int anchorParagraph, int anchorColumn, int caretPositionParagraph, int caretPositionColumn)
Positions the anchor and caretPosition explicitly, effectively creating a selection.default void
setShowCaret(Caret.CaretVisibility value)
Sets the value of the property showCaret.default Var<Caret.CaretVisibility>
showCaretProperty()
StyledDocument<PS,SEG,S>
subDocument(int paragraphIndex)
Returns rich-text content of the given paragraph.StyledDocument<PS,SEG,S>
subDocument(int start, int end)
Returns rich-text content of the given character range.default StyledDocument<PS,SEG,S>
subDocument(int startParagraph, int startColumn, int endParagraph, int endColumn)
Returns rich-text content of the given character range.default StyledDocument<PS,SEG,S>
subDocument(IndexRange range)
Returns rich-text content of the given character range.ObservableValue<String>
textProperty()
-
-
-
Property Detail
-
length
ObservableValue<Integer> lengthProperty
- See Also:
getLength()
-
text
ObservableValue<String> textProperty
- See Also:
getText()
-
caretPosition
default ObservableValue<Integer> caretPositionProperty
- See Also:
getCaretPosition()
-
currentParagraph
default ObservableValue<Integer> currentParagraphProperty
- See Also:
getCurrentParagraph()
-
caretColumn
default ObservableValue<Integer> caretColumnProperty
- See Also:
getCaretColumn()
-
caretBounds
default ObservableValue<Optional<Bounds>> caretBoundsProperty
- See Also:
getCaretBounds()
-
showCaret
default Var<Caret.CaretVisibility> showCaretProperty
-
anchor
default ObservableValue<Integer> anchorProperty
- See Also:
getAnchor()
-
selection
default ObservableValue<IndexRange> selectionProperty
- See Also:
getSelection()
-
selectedText
default ObservableValue<String> selectedTextProperty
- See Also:
getSelectedText()
-
selectionBounds
default ObservableValue<Optional<Bounds>> selectionBoundsProperty
- See Also:
getSelectionBounds()
-
beingUpdated
SuspendableNo beingUpdatedProperty
True when an update to the area'sunderling editable document
is still occurring or the viewport is being updated.
-
-
Method Detail
-
getLength
default int getLength()
The number of Unicode code units in this text-editing area.
-
lengthProperty
ObservableValue<Integer> lengthProperty()
- See Also:
getLength()
-
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.
-
textProperty
ObservableValue<String> textProperty()
- See Also:
getText()
-
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 multipleStyledTextArea
s.
-
getSegOps
SegmentOps<SEG,S> getSegOps()
Returns the object used for operating oversegments
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.
-
caretPositionProperty
default ObservableValue<Integer> caretPositionProperty()
- See Also:
getCaretPosition()
-
getCurrentParagraph
default int getCurrentParagraph()
Index of the current paragraph, i.e. the paragraph with the caret.
-
currentParagraphProperty
default ObservableValue<Integer> currentParagraphProperty()
- See Also:
getCurrentParagraph()
-
getCaretColumn
default int getCaretColumn()
The caret position within the current paragraph.
-
caretColumnProperty
default ObservableValue<Integer> caretColumnProperty()
- See Also:
getCaretColumn()
-
getCaretBounds
default Optional<Bounds> getCaretBounds()
Gets the bounds of the caret in the Screen's coordinate system orOptional.empty()
if caret is not visible in the viewport.
-
caretBoundsProperty
default ObservableValue<Optional<Bounds>> caretBoundsProperty()
- See Also:
getCaretBounds()
-
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:
-
showCaretProperty
default Var<Caret.CaretVisibility> showCaretProperty()
-
getCaretSelectionBind
CaretSelectionBind<PS,SEG,S> getCaretSelectionBind()
Gets the area's mainCaretSelectionBind
.
-
getAnchor
default int getAnchor()
The anchor of the selection. If there is no selection, this is the same as caret position.
-
anchorProperty
default ObservableValue<Integer> anchorProperty()
- See Also:
getAnchor()
-
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.
-
selectionProperty
default ObservableValue<IndexRange> selectionProperty()
- See Also:
getSelection()
-
getSelectedText
default String getSelectedText()
The selected text.
-
selectedTextProperty
default ObservableValue<String> selectedTextProperty()
- See Also:
getSelectedText()
-
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 orOptional.empty()
if selection is not visible in the viewport.
-
selectionBoundsProperty
default ObservableValue<Optional<Bounds>> selectionBoundsProperty()
- See Also:
getSelectionBounds()
-
getParagraphs
ObservableList<Paragraph<PS,SEG,S>> getParagraphs()
Unmodifiable observable list of paragraphs in this text area.
-
getParagraphLength
default int getParagraphLength(int index)
-
beingUpdatedProperty
SuspendableNo beingUpdatedProperty()
True when an update to the area'sunderling editable document
is still occurring or the viewport is being updated.
-
isBeingUpdated
default boolean isBeingUpdated()
-
multiPlainChanges
EventStream<List<PlainTextChange>> multiPlainChanges()
-
plainTextChanges
EventStream<PlainTextChange> plainTextChanges()
-
multiRichChanges
EventStream<List<RichTextChange<PS,SEG,S>>> multiRichChanges()
-
richChanges
EventStream<RichTextChange<PS,SEG,S>> richChanges()
-
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
default StyledDocument<PS,SEG,S> subDocument(IndexRange range)
Returns rich-text content of the given character range.
-
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 returnIndexRange(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'sanchor
or theselection
. Do not confuse this method withNavigationActions.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 hold0 <= 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 hold0 <= start <= end <= getLength()
wherestart = getAbsolutePosition(startParagraph, startColumn);
and is inclusive, andint 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.
-
createMultiChange
MultiChangeBuilder<PS,SEG,S> createMultiChange()
Starts building a list of changes to be used to update multiple portions of the underlying document in one call. To execute the changes, callMultiChangeBuilder.commit()
. If the number of changes are known at compile time, usecreateMultiChange(int)
for better memory efficiency.
-
createMultiChange
MultiChangeBuilder<PS,SEG,S> createMultiChange(int numOfChanges)
Same ascreateMultiChange()
but the number of changes are specified to be more memory efficient.
-
replace
void replace(int start, int end, SEG seg, S style)
Replaces a range of characters with the given segment. It must hold0 <= 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 hold0 <= start <= end <= getLength()
wherestart = getAbsolutePosition(startParagraph, startColumn);
and is inclusive, andint 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 toreplace(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 of1
, "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.
-
-