Summary
Introduces a tabStopPolicy
property in the TextFlow
class which, when set, overrides the existing tabSize
value and provides consistent way of setting tab stops at the paragraph level, regardless of the individual text
segments font [0].
Problem
The existing TextFlow APIs (tabSize) are inadequate for rich text or when the flow contains text segments with different font sizes. In addition to that, it is impossible to specify non-uniform tab stop interval(s), or have the intervals decoupled from the font size.
Solution
The proposed solution adds the 'tabStopPolicy' property to the TextFlow class, which allows to specify the list of tab stops and the default interval for stops beyond those explicitly specified, or to disable the default interval.
Specification
javafx.scene.text.TextFlow
+ /**
+ * Determines the tab stop positions within this {@code TextFlow}.
+ * <p>
+ * A non-null {@code TabStopPolicy} overrides values set by {@link #setTabSize(int)},
+ * as well as any values set by {@link Text#setTabSize(int)} in individual {@code Text} instances within
+ * this {@code TextFlow}.
+ *
+ * @defaultValue null
+ *
+ * @since 25
+ */
+ public final ObjectProperty<TabStopPolicy> tabStopPolicyProperty()
+
+ public final TabStopPolicy getTabStopPolicy()
+
+ public final void setTabStopPolicy(TabStopPolicy policy)
/**
* The size of a tab stop in spaces.
* Values less than 1 are treated as 1. This value overrides the
* {@code tabSize} of contained {@link Text} nodes.
+ * <p>
+ * Note that this method should not be used to control the tab placement when multiple {@code Text} nodes
+ * with different fonts are contained within this {@code TextFlow}.
+ * In this case, {@link #setTabStopPolicy(TabStopPolicy)} should be used instead.
*
* @defaultValue 8
*
* @since 14
*/
public final IntegerProperty tabSizeProperty()
javafx.scene.text.TabStopPolicy
+/**
+ * The TabStopPolicy determines the tab stop positions within the text layout.
+ *
+ * @since 25
+ */
+public final class TabStopPolicy {
+
+ /**
+ * Constructs a new {@code TabStopPolicy} instance, with an empty list of stops.
+ */
+ public TabStopPolicy()
+
+ /**
+ * The list of tab stops.
+ *
+ * @return the non-null list of tab stops
+ */
+ public final ObservableList<TabStop> tabStops()
+
+ /**
+ * Specifies the default tab stop interval for tabs beyond the last stop provided
+ * by {@link #tabStops()}. This is a fixed repeating distance (in pixels) to the
+ * next tab stop computed at regular intervals relative to the leading edge
+ * of the {@code TextFlow} node.
+ * <p>
+ * A value of less than or equal 0 disables the default interval.
+ *
+ * @return the default tab interval property
+ * @defaultValue 0
+ */
+ public final DoubleProperty defaultIntervalProperty()
+
+ public final double getDefaultInterval()
+
+ public final void setDefaultInterval(double value)
javafx.scene.text.TabStop
+/**
+ * This class encapsulates an immutable single tab stop within the {@link TabStopPolicy}.
+ *
+ * @since 25
+ */
+public final class TabStop {
+
+ /**
+ * Constructs a new tab stop with the specified position.
+ *
+ * @param position the position in pixels
+ */
+ public TabStop(double position) {
+ this.position = position;
+ }
+
+ /**
+ * Returns the position, in pixels, of the tab.
+ * @return the position of the tab
+ */
+ public final double getPosition()
- csr of
-
JDK-8314482 TextFlow: TabStopPolicy
-
- In Progress
-