Skip to content

Commit b59a1a8

Browse files
Cleanup javadoc; use "-rtfx" CSS prefix for caret blink rate
1 parent f46f3f8 commit b59a1a8

6 files changed

Lines changed: 72 additions & 15 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/Caret.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
public interface Caret {
3737

3838
/**
39-
* Determines whether the caret is visible. Those who wish to use the default configuartion should use
39+
* Determines whether the caret is visible. Those who wish to use the default configuration should use
4040
* {@link #AUTO} while those who want a more custom configuration should make a caret's {@code CaretVisibility}
41-
* value oscilate between {@link #ON} and {@link #OFF}.
41+
* value oscillate between {@link #ON} and {@link #OFF}.
4242
*/
4343
public static enum CaretVisibility {
4444
/** Caret is displayed. */
@@ -209,7 +209,14 @@ default void moveSentenceBreaksBackwards(int numOfSentenceBreaks) {
209209
*/
210210
public void dispose();
211211

212+
/**
213+
* Gets the area with which this caret is associated.
214+
*/
212215
public GenericStyledArea<?, ?, ?> getArea();
213216

217+
/**
218+
* Gets the name of this caret. Each caret that is added to an area must have a unique name since it is used
219+
* to distinguish it from others in a Set.
220+
*/
214221
public String getCaretName();
215222
}

richtextfx/src/main/java/org/fxmisc/richtext/CaretNode.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@
3333
import static org.reactfx.EventStreams.invalidationsOf;
3434
import static org.reactfx.EventStreams.merge;
3535

36+
/**
37+
* Default implementation for a {@link Caret}. Since only one {@link Path} object is used per caret, the model
38+
* and view were combined into one item to grant easier access to and modification of CSS-related
39+
* properties. Caution must be exercised when depending on Path-related properties in any way (e.g.
40+
* {@link #boundsInLocalProperty()}, {@link #parentProperty()}, etc.). Also, {@link #caretBoundsProperty()}
41+
* is distinguishable from {@link #boundsInLocalProperty()}.
42+
*
43+
* <p>
44+
* This class adds the css property "-rtfx-blink-rate" ({@link #blinkRateProperty()}}
45+
* </p>
46+
*/
3647
public class CaretNode extends Path implements Caret, Comparable<CaretNode> {
3748

3849
private static final javafx.util.Duration HALF_A_SECOND = javafx.util.Duration.millis(500);
@@ -57,6 +68,11 @@ public class CaretNode extends Path implements Caret, Comparable<CaretNode> {
5768
private final StyleableObjectProperty<javafx.util.Duration> blinkRate
5869
= new CustomStyleableProperty<>(HALF_A_SECOND, "blinkRate", this, BLINK_RATE);
5970

71+
/**
72+
* The blink rate of the caret.
73+
*
74+
* Can be styled from CSS using the "-rtfx-blink-rate" property.
75+
*/
6076
@Override public ObjectProperty<javafx.util.Duration> blinkRateProperty() { return blinkRate; }
6177
@Override public javafx.util.Duration getBlinkRate() { return blinkRate.getValue(); }
6278
@Override public void setBlinkRate(javafx.util.Duration rate) { blinkRate.set(rate); }
@@ -359,7 +375,7 @@ private void moveContentBreaks(int numOfBreaks, BreakIterator breakIterator, boo
359375
* ********************************************************************** */
360376

361377
private static final CssMetaData<CaretNode, javafx.util.Duration> BLINK_RATE
362-
= new CustomCssMetaData<>("-fx-blink-rate", StyleConverter.getDurationConverter(),
378+
= new CustomCssMetaData<>("-rtfx-blink-rate", StyleConverter.getDurationConverter(),
363379
javafx.util.Duration.millis(500), s -> s.blinkRate
364380
);
365381

richtextfx/src/main/java/org/fxmisc/richtext/Selection.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ default void deselect() {
177177
}
178178

179179
/**
180-
* Configures a {@link javafx.scene.shape.Path} that will be used to render a portion or all of this selection
181-
* on a given paragraph.
180+
* Configures a {@link SelectionPath} that will be used to render a portion or all of this selection
181+
* on a single paragraph. When the selection is a multi-paragraph selection, one path will be used
182+
* to render that portion of the selection on a paragraph.
182183
*/
183184
void configureSelectionPath(SelectionPath path);
184185

@@ -192,6 +193,9 @@ default void deselect() {
192193
*/
193194
String getSelectionName();
194195

196+
/**
197+
* Gets the area with which this selection is associated
198+
*/
195199
GenericStyledArea<PS, SEG, S> getArea();
196200

197201
}

richtextfx/src/main/java/org/fxmisc/richtext/SelectionImpl.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import static org.reactfx.EventStreams.invalidationsOf;
2727
import static org.reactfx.EventStreams.merge;
2828

29+
/**
30+
* Default implementation for {@link Selection}.
31+
*/
2932
public class SelectionImpl<PS, SEG, S> implements Selection<PS, SEG, S>, Comparable<SelectionImpl<PS, SEG, S>> {
3033

3134
/* ********************************************************************** *
@@ -110,34 +113,58 @@ public class SelectionImpl<PS, SEG, S> implements Selection<PS, SEG, S>, Compara
110113

111114
private Subscription subscription = () -> {};
112115

116+
/**
117+
* Creates a selection with both the start and end position at 0.
118+
*/
113119
public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area) {
114120
this(name, area, 0, 0);
115121
}
116122

123+
/**
124+
* Creates a selection with customized configuration via {@code configurePath}
125+
* with both the start and end position at 0.
126+
*/
117127
public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, Consumer<SelectionPath> configurePath) {
118128
this(name, area, 0, 0, area.beingUpdatedProperty(), configurePath);
119129
}
120130

131+
/**
132+
* Creates a selection
133+
*/
121134
public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, int startPosition, int endPosition) {
122135
this(name, area, new IndexRange(startPosition, endPosition), area.beingUpdatedProperty());
123136
}
124137

125-
public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, int startPosition, int endPosition,
138+
/**
139+
* Creates a selection that is to be used in a {@link CaretSelectionBind}.
140+
*/
141+
SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, int startPosition, int endPosition,
126142
SuspendableNo dependentBeingUpdated) {
127143
this(name, area, new IndexRange(startPosition, endPosition), dependentBeingUpdated);
128144
}
129145

130-
public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, int startPosition, int endPosition,
146+
/**
147+
* Creates a selection that is to be used in a {@link CaretSelectionBind} with customized configuration.
148+
*/
149+
SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, int startPosition, int endPosition,
131150
SuspendableNo dependentBeingUpdated, Consumer<SelectionPath> configurePath) {
132151
this(name, area, new IndexRange(startPosition, endPosition), dependentBeingUpdated, configurePath);
133152
}
134153

135-
public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, IndexRange range,
154+
/**
155+
* Creates a selection that is to be used in a {@link CaretSelectionBind}. It adds the style class
156+
* {@code selection} to any {@link SelectionPath} used to render this selection.
157+
*/
158+
SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, IndexRange range,
136159
SuspendableNo dependentBeingUpdated) {
137160
this(name, area, range, dependentBeingUpdated, path -> path.getStyleClass().add("selection"));
138161
}
139162

140-
public SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, IndexRange range,
163+
/**
164+
* Creates a selection that is to be used in a {@link CaretSelectionBind}
165+
* with customized configuration and starting at the given range.
166+
*/
167+
SelectionImpl(String name, GenericStyledArea<PS, SEG, S> area, IndexRange range,
141168
SuspendableNo dependentBeingUpdated, Consumer<SelectionPath> configurePath) {
142169
this.name = name;
143170
this.area = area;

richtextfx/src/main/java/org/fxmisc/richtext/SelectionPath.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.fxmisc.richtext;
22

3+
import javafx.beans.property.ObjectProperty;
34
import javafx.css.CssMetaData;
45
import javafx.css.StyleConverter;
56
import javafx.css.Styleable;
@@ -15,16 +16,18 @@
1516
import java.util.List;
1617

1718
/**
18-
* A class for a path which describes a selection shape in the Scene graph; it does not have a style class
19-
* associated with it.
19+
* A Path used to render a portion of a mulit-paragraph selection or all of a single-paragraph selection
20+
* with additional CSS styling; it does not have a style class associated with it.
2021
*/
2122
public class SelectionPath extends Path {
2223

23-
/**
24-
* Background fill for highlighted text.
25-
*/
2624
private final StyleableObjectProperty<Paint> highlightFill
2725
= new CustomStyleableProperty<>(Color.DODGERBLUE, "highlightFill", this, HIGHLIGHT_FILL);
26+
27+
/**
28+
* Background fill for highlighted/selected text. Can be styled using "-fx-highlight-fill".
29+
*/
30+
public final ObjectProperty<Paint> highlightFillProperty() { return highlightFill; }
2831
public final Paint getHighlightFill() { return highlightFill.get(); }
2932
public final void setHighlightFill(Paint paint) { highlightFill.set(paint); }
3033

richtextfx/src/main/resources/org/fxmisc/richtext/styled-text-area.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88

99
.styled-text-area .caret {
10-
-fx-blink-rate: 500ms;
10+
-rtfx-blink-rate: 500ms;
1111
-fx-stroke-width: 1.0;
1212
}
1313

0 commit comments

Comments
 (0)