Interface CaretSelectionBind<PS,SEG,S>
-
- Type Parameters:
PS
- type forStyledDocument
's paragraph style; only necessary when using the "selectedDocument" getter or propertySEG
- type forStyledDocument
's segment type; only necessary when using the "selectedDocument" getter or propertyS
- type forStyledDocument
's segment style; only necessary when using the "selectedDocument" getter or property
public interface CaretSelectionBind<PS,SEG,S> extends Selection<PS,SEG,S>, Caret
An object for encapsulating a caret and a selection in a given area where the caret and selection are bound to one another. In other words, selecting some range in the area (viaselectRangeExpl(int, int)
,selectRange(int, int, int, int)
) will move the caret in the same call, except if one usesdisplaceSelection(int, int)
. Updating the selection via any method with an "update" prefix fromSelection
will also move the caret if it has beendisplaced
or the anchor is not the boundary (i.e. the selection's the start or end position) that is being updated. Likewise, moving the caret via the "move" prefix methods fromCaret
will clear the selection in the same call, except if one usesdisplaceCaret(int)
."Position" refers to the place in-between characters. In other words, every
"|"
in"|t|e|x|t|"
is a valid position. There are two kinds of positions used here:-
Selection.getStartPosition()
/Selection.getEndPosition()
, which refers to a position somewhere in the entire area's content. It's bounds are0 <= x <= area.getLength()
. -
Selection.getStartColumnPosition()
/Selection.getEndColumnPosition()
, which refers to a position somewhere in the current paragraph. It's bounds are0 <= x <= area.getParagraphLength(index)
.
The selection is typically made using the
anchor's position
and the underlyingcaret's position
. Hence,selectRangeExpl(int, int)
is the typical method to use, althoughselectRange(int, int)
can also be used.For type safety,
Selection.getSelectedDocument()
requires the same generic types fromStyledDocument
. This means that one must write a lot of boilerplate for the generics:CaretSelectionBind<Collection<String>, StyledText<Collection<String>>, Collection<String>> selection
. However, this is only necessary if one is usingSelection.getSelectedDocument()
orSelection.selectedDocumentProperty()
. If you are not going to use the "selectedDocument" getter or property, then just write the much simplerCaretSelectionBind<?, ?, ?> selection
.
-
-
Property Summary
Properties Type Property Description javafx.beans.value.ObservableValue<java.lang.Integer>
anchorColPosition
javafx.beans.value.ObservableValue<java.lang.Integer>
anchorParIndex
javafx.beans.value.ObservableValue<java.lang.Integer>
anchorPosition
-
Properties inherited from interface org.fxmisc.richtext.Caret
beingUpdated, blinkRate, caretBounds, columnPosition, lineIndex, paragraphIndex, position, showCaret, visible
-
Properties inherited from interface org.fxmisc.richtext.Selection
beingUpdated, endColumnPosition, endParagraphIndex, endPosition, length, paragraphSpan, range, selectedDocument, selectedText, selectionBounds, startColumnPosition, startParagraphIndex, startPosition
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.fxmisc.richtext.Caret
Caret.CaretVisibility
-
Nested classes/interfaces inherited from interface org.fxmisc.richtext.Selection
Selection.Direction
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description javafx.beans.value.ObservableValue<java.lang.Integer>
anchorColPositionProperty()
javafx.beans.value.ObservableValue<java.lang.Integer>
anchorParIndexProperty()
javafx.beans.value.ObservableValue<java.lang.Integer>
anchorPositionProperty()
void
deselect()
Clears the selection while keeping the caret position the same.void
displaceCaret(int position)
Displaces the caret from the selection by positioning only the caret to the new location without also affecting the selection'sgetAnchorPosition()
anchor} or theSelection.getRange()
selection}.void
displaceSelection(int startPosition, int endPosition)
Displaces the caret from the selection by positioning only the selection to the new location without also affecting thecaret's position
.int
getAnchorColPosition()
Gets the value of the property anchorColPosition.int
getAnchorParIndex()
Gets the value of the property anchorParIndex.int
getAnchorPosition()
Gets the value of the property anchorPosition.CaretNode
getUnderlyingCaret()
Selection<PS,SEG,S>
getUnderlyingSelection()
void
moveBreaksBackwards(int numOfBreaks, java.text.BreakIterator breakIterator)
Moves the caret backwards by the number of breaks and clears any selectionvoid
moveBreaksForwards(int numOfBreaks, java.text.BreakIterator breakIterator)
Moves the caret forwards by the number of breaks and clears any selectiondefault void
moveTo(int position)
Moves the caret to the given position in the text and clears any selection.default void
moveTo(int paragraphIndex, int columnPosition)
Moves the caret to the position returned fromTextEditingArea.getAbsolutePosition(int, int)
and clears any selection.void
moveTo(int paragraphIndex, int columnIndex, NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret to the position returned fromTextEditingArea.getAbsolutePosition(int, int)
.default void
moveTo(int pos, NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret to the position indicated bypos
.default void
moveToAreaEnd()
Moves the caret to the end of the area and clears any selectionvoid
moveToAreaEnd(NavigationActions.SelectionPolicy selectionPolicy)
default void
moveToAreaStart()
Moves the caret to the beginning of the area and clears any selectionvoid
moveToAreaStart(NavigationActions.SelectionPolicy selectionPolicy)
default void
moveToNextChar()
Moves the caret forward one char in the text and clears any selectionvoid
moveToNextChar(NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret forward one char in the text.default void
moveToParEnd()
Moves the caret to the end of the current paragraph and clears any selectionvoid
moveToParEnd(NavigationActions.SelectionPolicy selectionPolicy)
default void
moveToParStart()
Moves the caret to the beginning of the current paragraph and clears any selectionvoid
moveToParStart(NavigationActions.SelectionPolicy selectionPolicy)
default void
moveToPrevChar()
Moves the caret backward one char in the text and clears any selectionvoid
moveToPrevChar(NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret backward one char in the text.void
selectAll()
Selects everything in the area and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original enddefault void
selectParagraph()
void
selectParagraph(int paragraphIndex)
Selects the given paragraph and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original endvoid
selectRange(int startPosition, int endPosition)
Selects the given range and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original endvoid
selectRange(int startParagraphIndex, int startColPosition, int endParagraphIndex, int endColPosition)
Selects the given range and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original endvoid
selectRangeExpl(int anchorPosition, int caretPosition)
Positions the anchor and caretPosition explicitly, effectively creating a selection.void
selectRangeExpl(int anchorParagraph, int anchorColumn, int caretParagraph, int caretColumn)
Positions the anchor and caretPosition explicitly, effectively creating a selection.default void
selectWord()
Selects the word closest to the caretvoid
selectWord(int wordPositionInArea)
Selects the closest word to the given position in the area and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original endvoid
updateEndBy(int amount, Selection.Direction direction)
void
updateEndByBreaksBackward(int numOfBreaks, java.text.BreakIterator breakIterator)
void
updateEndByBreaksForward(int numOfBreaks, java.text.BreakIterator breakIterator)
void
updateEndTo(int position)
void
updateEndTo(int paragraphIndex, int columnPosition)
void
updateStartBy(int amount, Selection.Direction direction)
void
updateStartByBreaksBackward(int numOfBreaks, java.text.BreakIterator breakIterator)
void
updateStartByBreaksForward(int numOfBreaks, java.text.BreakIterator breakIterator)
void
updateStartTo(int position)
void
updateStartTo(int paragraphIndex, int columnPosition)
-
Methods inherited from interface org.fxmisc.richtext.Caret
beingUpdatedProperty, blinkRateProperty, caretBoundsProperty, clearTargetOffset, columnPositionProperty, dispose, getArea, getBlinkRate, getCaretBounds, getCaretName, getColumnPosition, getLineIndex, getParagraphIndex, getPosition, getShowCaret, getTargetOffset, isBeingUpdated, isVisible, lineIndexProperty, moveSentenceBreaksBackwards, moveSentenceBreaksForwards, moveWordBreaksBackwards, moveWordBreaksForwards, paragraphIndexProperty, positionProperty, setBlinkRate, setShowCaret, showCaretProperty, visibleProperty
-
Methods inherited from interface org.fxmisc.richtext.Selection
beingUpdatedProperty, configureSelectionPath, dispose, endColumnPositionProperty, endParagraphIndexProperty, endPositionProperty, getArea, getEndColumnPosition, getEndParagraphIndex, getEndPosition, getLength, getParagraphSpan, getRange, getSelectedDocument, getSelectedText, getSelectionBounds, getSelectionName, getStartColumnPosition, getStartParagraphIndex, getStartPosition, isBeingUpdated, lengthProperty, paragraphSpanProperty, rangeProperty, selectedDocumentProperty, selectedTextProperty, selectionBoundsProperty, startColumnPositionProperty, startParagraphIndexProperty, startPositionProperty
-
-
-
-
Property Detail
-
anchorPosition
javafx.beans.value.ObservableValue<java.lang.Integer> anchorPositionProperty
- See Also:
getAnchorPosition()
-
anchorParIndex
javafx.beans.value.ObservableValue<java.lang.Integer> anchorParIndexProperty
- See Also:
getAnchorParIndex()
-
anchorColPosition
javafx.beans.value.ObservableValue<java.lang.Integer> anchorColPositionProperty
- See Also:
getAnchorColPosition()
-
-
Method Detail
-
getUnderlyingCaret
CaretNode getUnderlyingCaret()
-
getAnchorPosition
int getAnchorPosition()
Gets the value of the property anchorPosition.- Property description:
-
anchorPositionProperty
javafx.beans.value.ObservableValue<java.lang.Integer> anchorPositionProperty()
- See Also:
getAnchorPosition()
-
getAnchorParIndex
int getAnchorParIndex()
Gets the value of the property anchorParIndex.- Property description:
-
anchorParIndexProperty
javafx.beans.value.ObservableValue<java.lang.Integer> anchorParIndexProperty()
- See Also:
getAnchorParIndex()
-
getAnchorColPosition
int getAnchorColPosition()
Gets the value of the property anchorColPosition.- Property description:
-
anchorColPositionProperty
javafx.beans.value.ObservableValue<java.lang.Integer> anchorColPositionProperty()
- See Also:
getAnchorColPosition()
-
moveTo
default void moveTo(int position)
Moves the caret to the given position in the text and clears any selection.
-
moveTo
default void moveTo(int paragraphIndex, int columnPosition)
Moves the caret to the position returned fromTextEditingArea.getAbsolutePosition(int, int)
and clears any selection.
-
moveToParStart
default void moveToParStart()
Moves the caret to the beginning of the current paragraph and clears any selection- Specified by:
moveToParStart
in interfaceCaret
-
moveToParEnd
default void moveToParEnd()
Moves the caret to the end of the current paragraph and clears any selection- Specified by:
moveToParEnd
in interfaceCaret
-
moveToAreaStart
default void moveToAreaStart()
Moves the caret to the beginning of the area and clears any selection- Specified by:
moveToAreaStart
in interfaceCaret
-
moveToAreaEnd
default void moveToAreaEnd()
Moves the caret to the end of the area and clears any selection- Specified by:
moveToAreaEnd
in interfaceCaret
-
moveToPrevChar
default void moveToPrevChar()
Moves the caret backward one char in the text and clears any selection- Specified by:
moveToPrevChar
in interfaceCaret
-
moveToNextChar
default void moveToNextChar()
Moves the caret forward one char in the text and clears any selection- Specified by:
moveToNextChar
in interfaceCaret
-
moveBreaksForwards
void moveBreaksForwards(int numOfBreaks, java.text.BreakIterator breakIterator)
Moves the caret forwards by the number of breaks and clears any selection- Specified by:
moveBreaksForwards
in interfaceCaret
-
moveBreaksBackwards
void moveBreaksBackwards(int numOfBreaks, java.text.BreakIterator breakIterator)
Moves the caret backwards by the number of breaks and clears any selection- Specified by:
moveBreaksBackwards
in interfaceCaret
-
selectRange
void selectRange(int startParagraphIndex, int startColPosition, int endParagraphIndex, int endColPosition)
Selects the given range and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original endCaution: see
TextEditingArea.getAbsolutePosition(int, int)
to know how the column index argument can affect the returned position.- Specified by:
selectRange
in interfaceSelection<PS,SEG,S>
-
selectRange
void selectRange(int startPosition, int endPosition)
Selects the given range and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end- Specified by:
selectRange
in interfaceSelection<PS,SEG,S>
-
updateStartBy
void updateStartBy(int amount, Selection.Direction direction)
- Specified by:
updateStartBy
in interfaceSelection<PS,SEG,S>
-
updateEndBy
void updateEndBy(int amount, Selection.Direction direction)
- Specified by:
updateEndBy
in interfaceSelection<PS,SEG,S>
-
updateStartTo
void updateStartTo(int position)
- Specified by:
updateStartTo
in interfaceSelection<PS,SEG,S>
-
updateStartTo
void updateStartTo(int paragraphIndex, int columnPosition)
- Specified by:
updateStartTo
in interfaceSelection<PS,SEG,S>
-
updateStartByBreaksForward
void updateStartByBreaksForward(int numOfBreaks, java.text.BreakIterator breakIterator)
- Specified by:
updateStartByBreaksForward
in interfaceSelection<PS,SEG,S>
-
updateStartByBreaksBackward
void updateStartByBreaksBackward(int numOfBreaks, java.text.BreakIterator breakIterator)
- Specified by:
updateStartByBreaksBackward
in interfaceSelection<PS,SEG,S>
-
updateEndTo
void updateEndTo(int position)
- Specified by:
updateEndTo
in interfaceSelection<PS,SEG,S>
-
updateEndTo
void updateEndTo(int paragraphIndex, int columnPosition)
- Specified by:
updateEndTo
in interfaceSelection<PS,SEG,S>
-
updateEndByBreaksForward
void updateEndByBreaksForward(int numOfBreaks, java.text.BreakIterator breakIterator)
- Specified by:
updateEndByBreaksForward
in interfaceSelection<PS,SEG,S>
-
updateEndByBreaksBackward
void updateEndByBreaksBackward(int numOfBreaks, java.text.BreakIterator breakIterator)
- Specified by:
updateEndByBreaksBackward
in interfaceSelection<PS,SEG,S>
-
selectAll
void selectAll()
Selects everything in the area and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end
-
selectParagraph
void selectParagraph(int paragraphIndex)
Selects the given paragraph and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end- Specified by:
selectParagraph
in interfaceSelection<PS,SEG,S>
-
selectWord
void selectWord(int wordPositionInArea)
Selects the closest word to the given position in the area and moves the caret to either the start of the new selection if the anchor was equal to the original start or the end if the anchor was equal to the original end- Specified by:
selectWord
in interfaceSelection<PS,SEG,S>
-
deselect
void deselect()
Clears the selection while keeping the caret position the same.
-
selectRangeExpl
void selectRangeExpl(int anchorParagraph, int anchorColumn, int caretParagraph, int caretColumn)
Positions the anchor and caretPosition explicitly, effectively creating a selection.
-
selectRangeExpl
void selectRangeExpl(int anchorPosition, int caretPosition)
Positions the anchor and caretPosition explicitly, effectively creating a selection.
-
moveTo
default void moveTo(int pos, NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret to the position indicated bypos
. Based on the selection policy, the selection is either cleared (i.e. anchor is set to the same position as caret), adjusted (i.e. anchor is not moved at all), or extended (i.e.pos
becomes the new caret and, ifpos
points outside the current selection, the far end of the current selection becomes the anchor.
-
moveTo
void moveTo(int paragraphIndex, int columnIndex, NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret to the position returned fromTextEditingArea.getAbsolutePosition(int, int)
.
-
moveToPrevChar
void moveToPrevChar(NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret backward one char in the text. Based on the given selection policy, anchor either moves with the caret, stays put, or moves to the former caret position.
-
moveToNextChar
void moveToNextChar(NavigationActions.SelectionPolicy selectionPolicy)
Moves the caret forward one char in the text. Based on the given selection policy, anchor either moves with the caret, stays put, or moves to the former caret position.
-
moveToParStart
void moveToParStart(NavigationActions.SelectionPolicy selectionPolicy)
-
moveToParEnd
void moveToParEnd(NavigationActions.SelectionPolicy selectionPolicy)
-
moveToAreaStart
void moveToAreaStart(NavigationActions.SelectionPolicy selectionPolicy)
-
moveToAreaEnd
void moveToAreaEnd(NavigationActions.SelectionPolicy selectionPolicy)
-
selectParagraph
default void selectParagraph()
-
selectWord
default void selectWord()
Selects the word closest to the caret
-
displaceCaret
void displaceCaret(int position)
Displaces the caret from the selection by positioning only the caret to the new location without also affecting the selection'sgetAnchorPosition()
anchor} or theSelection.getRange()
selection}. Do not confuse this method withmoveTo(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.
-
displaceSelection
void displaceSelection(int startPosition, int endPosition)
Displaces the caret from the selection by positioning only the selection to the new location without also affecting thecaret's position
. This method can be used to achieve the special case of selecting some range in the area without affecting the caret's position. Use with care.
-
-