Top Description Inners Fields Constructors Methods
org.jabref.htmltonode.internal

public final Class TextSelection

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List, .Optional, javafx.geometry.Bounds, .Point2D, javafx.scene.Node, .Parent, javafx.scene.input.MouseButton, .MouseEvent, javafx.scene.layout.Region, javafx.scene.text.HitInfo, org.jspecify.annotations.Nullable

Mouse-driven text selection across all HighlightTextFlows of a rendered document.

A drag selects from the anchor to the current position in document order (the order in which the flows appear in the scene graph). Each affected flow paints its part of the selection; the selected string joins the per-flow parts with line breaks.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private @Nullable TextSelection.FlowPosition
private @Nullable TextSelection.FlowPosition
private final List<HighlightTextFlow>
private boolean
private final Region

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private Bounds
public void
private void
private void
private static int
private static double
distanceOutside(double value, double min, double max)

public Optional<String>
getSelectedText()

Returns: the selected text, joined with line breaks at block boundaries; empty if nothing is selected

private boolean
public boolean
isPressOnSelection()

Returns: whether the current mouse press started on an existing selection (the consumer may start a drag-and-drop of the selected content then)

private static TextSelection.FlowPosition
private static TextSelection.FlowPosition
private @Nullable TextSelection.FlowPosition
positionAt(double x, double y)

Maps a point (in root coordinates) to the nearest flow and character index.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

anchorback to summary
private @Nullable TextSelection.FlowPosition anchor
extentback to summary
private @Nullable TextSelection.FlowPosition extent
flowsback to summary
private final List<HighlightTextFlow> flows
pressOnSelectionback to summary
private boolean pressOnSelection
rootback to summary
private final Region root

Constructor Detail

TextSelectionback to summary
public TextSelection(Region root)

Method Detail

applySelectionback to summary
private void applySelection()
boundsInRootback to summary
private Bounds boundsInRoot(HighlightTextFlow flow)
clearback to summary
public void clear()
collectFlowsback to summary
private void collectFlows()
collectFlowsback to summary
private void collectFlows(Parent parent)
compareback to summary
private static int compare(TextSelection.FlowPosition a, TextSelection.FlowPosition b)
distanceOutsideback to summary
private static double distanceOutside(double value, double min, double max)
getSelectedTextback to summary
public Optional<String> getSelectedText()
Returns:Optional<String>

the selected text, joined with line breaks at block boundaries; empty if nothing is selected

isInsideSelectionback to summary
private boolean isInsideSelection(@Nullable TextSelection.FlowPosition position)
isPressOnSelectionback to summary
public boolean isPressOnSelection()
Returns:boolean

whether the current mouse press started on an existing selection (the consumer may start a drag-and-drop of the selected content then)

maxback to summary
private static TextSelection.FlowPosition max(TextSelection.FlowPosition a, TextSelection.FlowPosition b)
minback to summary
private static TextSelection.FlowPosition min(TextSelection.FlowPosition a, TextSelection.FlowPosition b)
positionAtback to summary
private @Nullable TextSelection.FlowPosition positionAt(double x, double y)

Maps a point (in root coordinates) to the nearest flow and character index.

org.jabref.htmltonode.internal back to summary

private final Record TextSelection.FlowPosition

extends Record
Class Inheritance
Record Components
flowIndex:int 
charIndex:int 

Field Summary

Modifier and TypeField and Description
private final int
charIndex

Record Component accessed by charIndex().

private final int
flowIndex

Record Component accessed by flowIndex().

Constructor Summary

AccessConstructor and Description
private
FlowPosition(int flowIndex, int charIndex)

Method Summary

Modifier and TypeMethod and Description
public int
charIndex()

Record Component getter of charIndex.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public int
flowIndex()

Record Component getter of flowIndex.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

charIndexback to summary
private final int charIndex

Record Component accessed by charIndex().

flowIndexback to summary
private final int flowIndex

Record Component accessed by flowIndex().

Constructor Detail

FlowPositionback to summary
private FlowPosition(int flowIndex, int charIndex)

Method Detail

charIndexback to summary
public int charIndex()

Record Component getter of charIndex.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
flowIndexback to summary
public int flowIndex()

Record Component getter of flowIndex.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.