-
Notifications
You must be signed in to change notification settings - Fork 236
/
StyledTextArea.java
101 lines (89 loc) · 5.09 KB
/
StyledTextArea.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package org.fxmisc.richtext;
import java.util.function.BiConsumer;
import javafx.beans.NamedArg;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.text.TextFlow;
import org.fxmisc.richtext.model.EditableStyledDocument;
import org.fxmisc.richtext.model.SegmentOps;
import org.fxmisc.richtext.model.SimpleEditableStyledDocument;
import org.fxmisc.richtext.model.StyledSegment;
import org.fxmisc.richtext.model.TextOps;
/**
* A {@link GenericStyledArea} whose segment generic has been specified to be a {@link String}. How the text
* will be styled is not yet specified in this class, but use {@link StyleClassedTextArea} for a style class
* approach to styling the text and {@link InlineCssTextArea} for an inline css approach to styling the text.
*
* @param <PS> type of paragraph style
* @param <S> type of style that can be applied to text.
*/
public class StyledTextArea<PS, S> extends GenericStyledArea<PS, String, S> {
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("document") EditableStyledDocument<PS, String, S> document,
@NamedArg("segmentOps") TextOps<String, S> segmentOps,
@NamedArg("preserveStyle") boolean preserveStyle) {
super(initialParagraphStyle, applyParagraphStyle,
initialTextStyle, document, segmentOps, preserveStyle,
seg -> createStyledTextNode(seg, applyStyle)
);
}
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("document") EditableStyledDocument<PS, String, S> document,
@NamedArg("preserveStyle") boolean preserveStyle) {
this(initialParagraphStyle, applyParagraphStyle,
initialTextStyle, applyStyle,
document, SegmentOps.styledTextOps(), preserveStyle);
}
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("document") EditableStyledDocument<PS, String, S> document) {
this(initialParagraphStyle, applyParagraphStyle,
initialTextStyle, applyStyle, document, true);
}
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("preserveStyle") boolean preserveStyle) {
this(
initialParagraphStyle,
applyParagraphStyle,
initialTextStyle,
applyStyle,
new SimpleEditableStyledDocument<>(initialParagraphStyle, initialTextStyle),
preserveStyle);
}
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle) {
this(initialParagraphStyle, applyParagraphStyle,
initialTextStyle, applyStyle, true);
}
/**
* Creates a {@link TextExt} node using the given styled text.
*/
public static <S> Node createStyledTextNode(StyledSegment<String, S> seg,
BiConsumer<? super TextExt, S> applyStyle) {
return createStyledTextNode(seg.getSegment(), seg.getStyle(), applyStyle);
}
/**
* Creates a {@link TextExt} node using the given styled text.
*/
public static <S> Node createStyledTextNode(String text, S style,
BiConsumer<? super TextExt, S> applyStyle) {
TextExt t = new TextExt(text);
t.setTextOrigin(VPos.TOP);
t.getStyleClass().add("text");
applyStyle.accept(t, style);
return t;
}
}