All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fxmisc.richtext.StyleClassedTextArea Maven / Gradle / Ivy

There is a newer version: 0.11.3
Show newest version
package org.fxmisc.richtext;

import java.util.Collection;
import java.util.Collections;

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(EditableStyledDocument, Collection> document, 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.collectionCodec(Codec.STRING_CODEC)
        );
    }
    public StyleClassedTextArea(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));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy