-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathStyleClassedTextArea.java
51 lines (44 loc) · 1.85 KB
/
StyleClassedTextArea.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
package org.fxmisc.richtext;
import java.util.Collection;
import java.util.Collections;
import javafx.beans.NamedArg;
import org.fxmisc.richtext.model.Codec;
import org.fxmisc.richtext.model.EditableStyledDocument;
import org.fxmisc.richtext.model.SimpleEditableStyledDocument;
import org.fxmisc.richtext.model.StyledText;
/**
* Text area that uses style classes to define style of text segments and paragraph segments.
*/
public class StyleClassedTextArea extends StyledTextArea<Collection<String>, Collection<String>> {
public StyleClassedTextArea(@NamedArg("document") EditableStyledDocument<Collection<String>, StyledText<Collection<String>>, Collection<String>> document,
@NamedArg("preserveStyle") boolean preserveStyle) {
super(Collections.<String>emptyList(),
(paragraph, styleClasses) -> paragraph.getStyleClass().addAll(styleClasses),
Collections.<String>emptyList(),
(text, styleClasses) -> text.getStyleClass().addAll(styleClasses),
document, preserveStyle
);
setStyleCodecs(
Codec.collectionCodec(Codec.STRING_CODEC),
StyledText.codec(Codec.collectionCodec(Codec.STRING_CODEC))
);
}
public StyleClassedTextArea(@NamedArg("preserveStyle") boolean preserveStyle) {
this(
new SimpleEditableStyledDocument<>(
Collections.<String>emptyList(), Collections.<String>emptyList()
), preserveStyle);
}
/**
* Creates a text area with empty text content.
*/
public StyleClassedTextArea() {
this(true);
}
/**
* Convenient method to assign a single style class.
*/
public void setStyleClass(int from, int to, String styleClass) {
setStyle(from, to, Collections.singletonList(styleClass));
}
}