org.fxmisc.richtext.StyleClassedTextArea Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
Rich-text area for JavaFX
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;
/**
* Text area that uses style classes to define style of text segments and paragraph segments.
*/
public class StyleClassedTextArea extends StyledTextArea, Collection> {
public StyleClassedTextArea(@NamedArg("document") EditableStyledDocument, String, Collection> document,
@NamedArg("preserveStyle") boolean preserveStyle) {
super(Collections.emptyList(),
(paragraph, styleClasses) -> paragraph.getStyleClass().addAll(styleClasses),
Collections.emptyList(),
(text, styleClasses) -> text.getStyleClass().addAll(styleClasses),
document, preserveStyle
);
setStyleCodecs(
Codec.collectionCodec(Codec.STRING_CODEC),
Codec.styledTextCodec(Codec.collectionCodec(Codec.STRING_CODEC))
);
}
public StyleClassedTextArea(@NamedArg("preserveStyle") boolean preserveStyle) {
this(
new SimpleEditableStyledDocument<>(
Collections.emptyList(), Collections.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));
}
}