|
17 | 17 | import javafx.scene.shape.StrokeLineCap; |
18 | 18 | import javafx.scene.text.Text; |
19 | 19 |
|
| 20 | +/** |
| 21 | + * A class which adds some more styleable properties to JavaFX's {@link Text} class. |
| 22 | + * |
| 23 | + * The extra items can be styled using the properties (and accessors/mutators) or via CSS. |
| 24 | + * Each property is documented with its CSS property. Each CSS property begins with the "-rtfx" |
| 25 | + * prefix. |
| 26 | + * |
| 27 | + * <p>Note that the underline properties specified here are orthogonal to the {@link #underlineProperty()} inherited |
| 28 | + * from {@link Text}. The underline properties defined here in {@link TextExt} will cause an underline to be |
| 29 | + * drawn if {@link #underlineWidthProperty()} is non-null and greater than zero, regardless of |
| 30 | + * the value of {@link #underlineProperty()}.</p> |
| 31 | + */ |
20 | 32 | public class TextExt extends Text { |
21 | 33 |
|
22 | 34 | private final StyleableObjectProperty<Paint> backgroundColor = new StyleableObjectProperty<Paint>(null) { |
@@ -133,28 +145,90 @@ public void setBackgroundColor(Paint fill) { |
133 | 145 | backgroundColor.set(fill); |
134 | 146 | } |
135 | 147 |
|
| 148 | + /** |
| 149 | + * The background color of the section of text. By default, JavaFX doesn't |
| 150 | + * support a background for Text (as it is a Shape item), but RichTextFX |
| 151 | + * does support drawing a different background for different sections of text. |
| 152 | + * |
| 153 | + * <p>Note that this is actually a Paint type, so you can specify gradient or image fills |
| 154 | + * rather than a flat colour. But due to line wrapping, it's possible that |
| 155 | + * the fill may be used multiple times on separate lines even for the same |
| 156 | + * segment of text.</p> |
| 157 | + * |
| 158 | + * Can be styled from CSS using the "-rtfx-background-color" property. |
| 159 | + */ |
136 | 160 | public ObjectProperty<Paint> backgroundColorProperty() { |
137 | 161 | return backgroundColor; |
138 | 162 | } |
139 | 163 |
|
140 | 164 | // Color of the text underline (-fx-underline is already defined by JavaFX) |
141 | 165 | public Paint getUnderlineColor() { return underlineColor.get(); } |
142 | 166 | public void setUnderlineColor(Paint fill) { underlineColor.set(fill); } |
| 167 | + |
| 168 | + /** |
| 169 | + * The underline color of the section of text. |
| 170 | + * |
| 171 | + * <p>Note that this is actually a Paint type, so you can specify gradient or image fills |
| 172 | + * rather than a flat colour. But due to line wrapping, it's possible that |
| 173 | + * the fill may be used multiple times on separate lines even for the |
| 174 | + * same segment of text.</p> |
| 175 | + * |
| 176 | + * Can be styled from CSS using the "-rtfx-underline-color" property |
| 177 | + * (not to be confused with JavaFX's separate "-fx-underline" property). |
| 178 | + * |
| 179 | + * <p>Note that the underline properties specified here are orthogonal to the {@link #underlineProperty()} inherited |
| 180 | + * from {@link Text}. The underline properties defined here in {@link TextExt} will cause an underline to be |
| 181 | + * drawn if {@link #underlineWidthProperty()} is non-null and greater than zero, regardless of |
| 182 | + * the value of {@link #underlineProperty()}.</p> |
| 183 | + */ |
143 | 184 | public ObjectProperty<Paint> underlineColorProperty() { return underlineColor; } |
144 | 185 |
|
145 | 186 | // Width of the text underline |
146 | 187 | public Number getUnderlineWidth() { return underlineWidth.get(); } |
147 | 188 | public void setUnderlineWidth(Number width) { underlineWidth.set(width); } |
| 189 | + |
| 190 | + /** |
| 191 | + * The width of the underline for a section of text. If null or zero, |
| 192 | + * the underline will not be drawn. |
| 193 | + * |
| 194 | + * Can be styled from CSS using the "-rtfx-underline-width" property. |
| 195 | + * |
| 196 | + * <p>Note that the underline properties specified here are orthogonal to the {@link #underlineProperty()} inherited |
| 197 | + * from {@link Text}. The underline properties defined here in {@link TextExt} will cause an underline to be |
| 198 | + * drawn if {@link #underlineWidthProperty()} is non-null and greater than zero, regardless of |
| 199 | + * the value of {@link #underlineProperty()}.</p> |
| 200 | + */ |
148 | 201 | public ObjectProperty<Number> underlineWidthProperty() { return underlineWidth; } |
149 | 202 |
|
150 | 203 | // Dash array for the text underline |
151 | 204 | public Number[] getUnderlineDashArray() { return underlineDashArray.get(); } |
152 | 205 | public void setUnderlineDashArray(Number[] dashArray) { underlineDashArray.set(dashArray); } |
| 206 | + |
| 207 | + /** |
| 208 | + * The dash array used for drawing the underline for a section of text. |
| 209 | + * |
| 210 | + * Can be styled from CSS using the "-rtfx-underline-dash-array" property. |
| 211 | + * |
| 212 | + * <p>Note that the underline properties specified here are orthogonal to the {@link #underlineProperty()} inherited |
| 213 | + * from {@link Text}. The underline properties defined here in {@link TextExt} will cause an underline to be |
| 214 | + * drawn if {@link #underlineWidthProperty()} is non-null and greater than zero, regardless of |
| 215 | + * the value of {@link #underlineProperty()}.</p> |
| 216 | + */ |
153 | 217 | public ObjectProperty<Number[]> underlineDashArrayProperty() { return underlineDashArray; } |
154 | 218 |
|
155 | 219 | // The end cap style of each dash in a dashed underline |
156 | 220 | public StrokeLineCap getUnderlineCap() { return underlineCap.get(); } |
157 | 221 | public void setUnderlineCap(StrokeLineCap cap) { underlineCap.set(cap); } |
| 222 | + /** |
| 223 | + * The end cap style used for drawing each dash in a dashed underline for a section of text. |
| 224 | + * |
| 225 | + * Can be styled from CSS using the "-rtfx-underline-cap" property. |
| 226 | + * |
| 227 | + * <p>Note that the underline properties specified here are orthogonal to the {@link #underlineProperty()} inherited |
| 228 | + * from {@link Text}. The underline properties defined here in {@link TextExt} will cause an underline to be |
| 229 | + * drawn if {@link #underlineWidthProperty()} is non-null and greater than zero, regardless of |
| 230 | + * the value of {@link #underlineProperty()}.</p> |
| 231 | + */ |
158 | 232 | public ObjectProperty<StrokeLineCap> underlineCapProperty() { return underlineCap; } |
159 | 233 |
|
160 | 234 | private static class StyleableProperties { |
|
0 commit comments