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 javafx.beans.value.ObservableValue<java.lang.Integer>
anchor
SuspendableNo
beingUpdated
True when an update to the area'sunderling editable document
is still occurring or the viewport is being updated.default javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.Bounds>>
caretBounds
default javafx.beans.value.ObservableValue<java.lang.Integer>
caretColumn
default javafx.beans.value.ObservableValue<java.lang.Integer>
caretPosition
default javafx.beans.value.ObservableValue<java.lang.Integer>
currentParagraph
javafx.beans.value.ObservableValue<java.lang.Integer>
length
default javafx.beans.value.ObservableValue<java.lang.String>
selectedText
default javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.Bounds>>
selectionBounds
default javafx.beans.value.ObservableValue<javafx.scene.control.IndexRange>
selection
default Var<Caret.CaretVisibility>
showCaret
javafx.beans.value.ObservableValue<java.lang.String>
text
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default javafx.beans.value.ObservableValue<java.lang.Integer>
anchorProperty()
SuspendableNo
beingUpdatedProperty()
True when an update to the area'sunderling editable document
is still occurring or the viewport is being updated.default javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.Bounds>>
caretBoundsProperty()
default javafx.beans.value.ObservableValue<java.lang.Integer>
caretColumnProperty()
default javafx.beans.value.ObservableValue<java.lang.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 javafx.beans.value.ObservableValue<java.lang.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 java.util.Optional<javafx.geometry.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 characters in this text-editing area.default java.util.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)
javafx.collections.ObservableList<Paragraph<PS,SEG,S>>
getParagraphs()
Unmodifiable observable list of paragraphs in this text area.default javafx.scene.control.IndexRange
getParagraphSelection(int paragraph)
Returns the selection range in the given paragraph.javafx.scene.control.IndexRange
getParagraphSelection(Selection selection, int paragraph)
SegmentOps<SEG,S>
getSegOps()
Returns the object used for operating oversegments
and their stylesdefault java.lang.String
getSelectedText()
The selected text.default javafx.scene.control.IndexRange
getSelection()
The selection range.default java.util.Optional<javafx.geometry.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 java.lang.String
getText()
Text content of this text-editing area.java.lang.String
getText(int paragraphIndex)
Returns text content of the given paragraph.java.lang.String
getText(int start, int end)
Returns text content of the given character range.default java.lang.String
getText(int startParagraph, int startColumn, int endParagraph, int endColumn)
Returns text content of the given character range.java.lang.String
getText(javafx.scene.control.IndexRange range)
Returns text content of the given character range.default boolean
isBeingUpdated()
javafx.beans.value.ObservableValue<java.lang.Integer>
lengthProperty()
EventStream<java.util.List<PlainTextChange>>
multiPlainChanges()
EventStream<java.util.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(javafx.scene.control.IndexRange range, StyledDocument<PS,SEG,S> replacement)
Equivalent toreplace(range.getStart(), range.getEnd(), replacement)
.default void
replace(javafx.scene.control.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, java.lang.String text)
Replaces a range of characters with the given text.void
replaceText(int start, int end, java.lang.String text)
Replaces a range of characters with the given text.default void
replaceText(javafx.scene.control.IndexRange range, java.lang.String text)
Replaces a range of characters with the given text.EventStream<RichTextChange<PS,SEG,S>>
richChanges()
default javafx.beans.value.ObservableValue<java.lang.String>
selectedTextProperty()
default javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.Bounds>>
selectionBoundsProperty()
default javafx.beans.value.ObservableValue<javafx.scene.control.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(javafx.scene.control.IndexRange range)
Returns rich-text content of the given character range.javafx.beans.value.ObservableValue<java.lang.String>
textProperty()
-
-
-
Property Detail
-
length
javafx.beans.value.ObservableValue<java.lang.Integer> lengthProperty
- See Also:
getLength()
-
text
javafx.beans.value.ObservableValue<java.lang.String> textProperty
- See Also:
getText()
-
caretPosition
default javafx.beans.value.ObservableValue<java.lang.Integer> caretPositionProperty
- See Also:
getCaretPosition()
-
currentParagraph
default javafx.beans.value.ObservableValue<java.lang.Integer> currentParagraphProperty
- See Also:
getCurrentParagraph()
-
caretColumn
default javafx.beans.value.ObservableValue<java.lang.Integer> caretColumnProperty
- See Also:
getCaretColumn()
-
caretBounds
default javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.Bounds>> caretBoundsProperty
- See Also:
getCaretBounds()
-
showCaret
default Var<Caret.CaretVisibility> showCaretProperty
-
anchor
default javafx.beans.value.ObservableValue<java.lang.Integer> anchorProperty
- See Also:
getAnchor()
-
selection
default javafx.beans.value.ObservableValue<javafx.scene.control.IndexRange> selectionProperty
- See Also:
getSelection()
-
selectedText
default javafx.beans.value.ObservableValue<java.lang.String> selectedTextProperty
- See Also:
getSelectedText()
-
selectionBounds
default javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.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 characters in this text-editing area.
-
lengthProperty
javafx.beans.value.ObservableValue<java.lang.Integer> lengthProperty()
- See Also:
getLength()
-
getLocale
default java.util.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 java.lang.String getText()
Text content of this text-editing area.
-
textProperty
javafx.beans.value.ObservableValue<java.lang.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 javafx.beans.value.ObservableValue<java.lang.Integer> caretPositionProperty()
- See Also:
getCaretPosition()
-
getCurrentParagraph
default int getCurrentParagraph()
Index of the current paragraph, i.e. the paragraph with the caret.
-
currentParagraphProperty
default javafx.beans.value.ObservableValue<java.lang.Integer> currentParagraphProperty()
- See Also:
getCurrentParagraph()
-
getCaretColumn
default int getCaretColumn()
The caret position within the current paragraph.
-
caretColumnProperty
default javafx.beans.value.ObservableValue<java.lang.Integer> caretColumnProperty()
- See Also:
getCaretColumn()
-
getCaretBounds
default java.util.Optional<javafx.geometry.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 javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.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 javafx.beans.value.ObservableValue<java.lang.Integer> anchorProperty()
- See Also:
getAnchor()
-
getSelection
default javafx.scene.control.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 javafx.beans.value.ObservableValue<javafx.scene.control.IndexRange> selectionProperty()
- See Also:
getSelection()
-
getSelectedText
default java.lang.String getSelectedText()
The selected text.
-
selectedTextProperty
default javafx.beans.value.ObservableValue<java.lang.String> selectedTextProperty()
- See Also:
getSelectedText()
-
getSelectionBounds
default java.util.Optional<javafx.geometry.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 javafx.beans.value.ObservableValue<java.util.Optional<javafx.geometry.Bounds>> selectionBoundsProperty()
- See Also:
getSelectionBounds()
-
getParagraphs
javafx.collections.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<java.util.List<PlainTextChange>> multiPlainChanges()
-
plainTextChanges
EventStream<PlainTextChange> plainTextChanges()
-
multiRichChanges
EventStream<java.util.List<RichTextChange<PS,SEG,S>>> multiRichChanges()
-
richChanges
EventStream<RichTextChange<PS,SEG,S>> richChanges()
-
getText
java.lang.String getText(int paragraphIndex)
Returns text content of the given paragraph.
-
getText
java.lang.String getText(int start, int end)
Returns text content of the given character range.
-
getText
java.lang.String getText(javafx.scene.control.IndexRange range)
Returns text content of the given character range.
-
getText
default java.lang.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(javafx.scene.control.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 javafx.scene.control.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
javafx.scene.control.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, java.lang.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, java.lang.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(javafx.scene.control.IndexRange range, java.lang.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(javafx.scene.control.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(javafx.scene.control.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.
-
-