Top Description Inners Methods
org.fxmisc.richtext

public Interface Selection<PS, SEG, S>

Known Direct Subinterfaces
org.fxmisc.richtext.CaretSelectionBind
Known Direct Implementers
org.fxmisc.richtext.SelectionImpl
Type Parameters
<PS>
type for StyledDocument's paragraph style; only necessary when using the "selectedDocument" getter or property
<SEG>
type for StyledDocument's segment type; only necessary when using the "selectedDocument" getter or property
<S>
type for StyledDocument's segment style; only necessary when using the "selectedDocument" getter or property
Imports
javafx.beans.value.ObservableValue, javafx.geometry.Bounds, javafx.scene.control.IndexRange, org.fxmisc.richtext.model.StyledDocument, java.text.BreakIterator, java.util.Optional

An object for encapsulating a selection in a given area.

"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:

  1. getStartPosition()/getEndPosition(), which refers to a position somewhere in the entire area's content. It's bounds are 0 <= x <= area.getLength().
  2. getStartColumnPosition()/getEndColumnPosition(), which refers to a position somewhere in the current paragraph. It's bounds are 0 <= x <= area.getParagraphLength(index).
Note: when parameter names are "position" without the "column" prefix, they refer to the position in the entire area.

For type safety, getSelectedDocument() requires the same generic types from StyledDocument. This means that one must write a lot of boilerplate for the generics: Selection<Collection<String>, StyledText<Collection<String>>, Collection<String>> selection. However, this is only necessary if one is using getSelectedDocument() or selectedDocumentProperty(). If you are not going to use the "selectedDocument" getter or property, then just write the much simpler Selection<?, ?, ?> selection.

See Also
CaretSelectionBind, Caret

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Selection.Direction

Specifies whether to update the start/end value of a selection to the left (towards 0) or right (away from 0)

Method Summary

Modifier and TypeMethod and Description
public ObservableValue<Boolean>
public void
configureSelectionPath(SelectionPath path)

Configures a SelectionPath that will be used to render a portion or all of this selection on a single paragraph.

public default void
deselect()

Clears the selection via selectRange(getStartPosition(), getStartPosition()).

public void
dispose()

Disposes the selection and prevents memory leaks

public ObservableValue<Integer>
public ObservableValue<Integer>
public ObservableValue<Integer>
public GenericStyledArea<PS, SEG, S>
getArea()

Gets the area with which this selection is associated

public int
public int
public int
public int
public int
public IndexRange
public StyledDocument<PS, SEG, S>
public String
public Optional<Bounds>
public String
getSelectionName()

Gets the name of this selection.

public int
public int
public int
public boolean
public ObservableValue<Integer>
lengthProperty()

The length of the selection

public ObservableValue<Integer>
paragraphSpanProperty()

The number of paragraphs the selection spans

public ObservableValue<IndexRange>
rangeProperty()

The start and end positions in the area as an IndexRange.

public void
public ObservableValue<StyledDocument<PS, SEG, S>>
public ObservableValue<String>
public ObservableValue<Optional<Bounds>>
selectionBoundsProperty()

The selectionBoundsProperty of the selection in the Screen's coordinate system if something is selected and visible in the viewport, or Optional#empty() if selection is not visible in the viewport.

public void
selectParagraph(int paragraphIndex)

public void
selectRange(int startParagraphIndex, int startColPosition, int endParagraphIndex, int endColPosition)

Selects the given range.

public void
selectRange(int startPosition, int endPosition)

Selects the given range.

public void
selectWord(int wordPositionInArea)

public ObservableValue<Integer>
public ObservableValue<Integer>
public ObservableValue<Integer>
public void
updateEndBy(int amount, Selection.Direction direction)

public void
updateEndByBreaksBackward(int numOfBreaks, BreakIterator breakIterator)

public void
updateEndByBreaksForward(int numOfBreaks, BreakIterator breakIterator)

public void
updateEndTo(int position)

public void
updateEndTo(int paragraphIndex, int columnPosition)

public void
updateStartBy(int amount, Selection.Direction direction)

public void
updateStartByBreaksBackward(int numOfBreaks, BreakIterator breakIterator)

public void
updateStartByBreaksForward(int numOfBreaks, BreakIterator breakIterator)

public void
updateStartTo(int position)

public void
updateStartTo(int paragraphIndex, int columnPosition)

Method Detail

beingUpdatedPropertyback to summary
public ObservableValue<Boolean> beingUpdatedProperty()
configureSelectionPathback to summary
public void configureSelectionPath(SelectionPath path)

Configures a SelectionPath that will be used to render a portion or all of this selection on a single paragraph. When the selection is a multi-paragraph selection, one path will be used to render that portion of the selection on a paragraph.

deselectback to summary
public default void deselect()

Clears the selection via selectRange(getStartPosition(), getStartPosition()).

disposeback to summary
public void dispose()

Disposes the selection and prevents memory leaks

endColumnPositionPropertyback to summary
public ObservableValue<Integer> endColumnPositionProperty()
endParagraphIndexPropertyback to summary
public ObservableValue<Integer> endParagraphIndexProperty()
endPositionPropertyback to summary
public ObservableValue<Integer> endPositionProperty()
getAreaback to summary
public GenericStyledArea<PS, SEG, S> getArea()

Gets the area with which this selection is associated

getEndColumnPositionback to summary
public int getEndColumnPosition()
getEndParagraphIndexback to summary
public int getEndParagraphIndex()
getEndPositionback to summary
public int getEndPosition()
getLengthback to summary
public int getLength()
getParagraphSpanback to summary
public int getParagraphSpan()
getRangeback to summary
public IndexRange getRange()
getSelectedDocumentback to summary
public StyledDocument<PS, SEG, S> getSelectedDocument()
getSelectedTextback to summary
public String getSelectedText()
getSelectionBoundsback to summary
public Optional<Bounds> getSelectionBounds()
getSelectionNameback to summary
public String getSelectionName()

Gets the name of this selection. Each selection in an area must have a unique name.
The name is also used as a StyleClass, so the Selection can be styled using CSS selectors from Path, Shape, and Node eg:
.styled-text-area .my-selection { -fx-fill: lime; }

getStartColumnPositionback to summary
public int getStartColumnPosition()
getStartParagraphIndexback to summary
public int getStartParagraphIndex()
getStartPositionback to summary
public int getStartPosition()
isBeingUpdatedback to summary
public boolean isBeingUpdated()
lengthPropertyback to summary
public ObservableValue<Integer> lengthProperty()

The length of the selection

paragraphSpanPropertyback to summary
public ObservableValue<Integer> paragraphSpanProperty()

The number of paragraphs the selection spans

rangePropertyback to summary
public ObservableValue<IndexRange> rangeProperty()

The start and end positions in the area as an IndexRange.

selectAllback to summary
public void selectAll()
selectedDocumentPropertyback to summary
public ObservableValue<StyledDocument<PS, SEG, S>> selectedDocumentProperty()
selectedTextPropertyback to summary
public ObservableValue<String> selectedTextProperty()
selectionBoundsPropertyback to summary
public ObservableValue<Optional<Bounds>> selectionBoundsProperty()

The selectionBoundsProperty of the selection in the Screen's coordinate system if something is selected and visible in the viewport, or Optional#empty() if selection is not visible in the viewport.

selectParagraphback to summary
public void selectParagraph(int paragraphIndex)
selectRangeback to summary
public void selectRange(int startParagraphIndex, int startColPosition, int endParagraphIndex, int endColPosition)

Selects the given range.

Caution

see TextEditingArea#getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

selectRangeback to summary
public void selectRange(int startPosition, int endPosition)

Selects the given range.

selectWordback to summary
public void selectWord(int wordPositionInArea)
startColumnPositionPropertyback to summary
public ObservableValue<Integer> startColumnPositionProperty()
startParagraphIndexPropertyback to summary
public ObservableValue<Integer> startParagraphIndexProperty()
startPositionPropertyback to summary
public ObservableValue<Integer> startPositionProperty()
updateEndByback to summary
public void updateEndBy(int amount, Selection.Direction direction)
updateEndByBreaksBackwardback to summary
public void updateEndByBreaksBackward(int numOfBreaks, BreakIterator breakIterator)
updateEndByBreaksForwardback to summary
public void updateEndByBreaksForward(int numOfBreaks, BreakIterator breakIterator)
updateEndToback to summary
public void updateEndTo(int position)
updateEndToback to summary
public void updateEndTo(int paragraphIndex, int columnPosition)
updateStartByback to summary
public void updateStartBy(int amount, Selection.Direction direction)
updateStartByBreaksBackwardback to summary
public void updateStartByBreaksBackward(int numOfBreaks, BreakIterator breakIterator)
updateStartByBreaksForwardback to summary
public void updateStartByBreaksForward(int numOfBreaks, BreakIterator breakIterator)
updateStartToback to summary
public void updateStartTo(int position)
updateStartToback to summary
public void updateStartTo(int paragraphIndex, int columnPosition)
org.fxmisc.richtext back to summary

public final Enum Selection.Direction

extends Enum<Selection.Direction>
Class Inheritance

Specifies whether to update the start/end value of a selection to the left (towards 0) or right (away from 0)

Field Summary

Modifier and TypeField and Description
public static final Selection.Direction
public static final Selection.Direction

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Selection.Direction
public static Selection.Direction[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LEFTback to summary
public static final Selection.Direction LEFT
RIGHTback to summary
public static final Selection.Direction RIGHT

Constructor Detail

Directionback to summary
private Direction()

Method Detail

valueOfback to summary
public static Selection.Direction valueOf(String name)
valuesback to summary
public static Selection.Direction[] values()