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

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

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

import javafx.beans.property.ObjectProperty;
import javafx.css.CssMetaData;
import javafx.css.StyleConverter;
import javafx.css.Styleable;
import javafx.css.StyleableObjectProperty;
import javafx.scene.control.IndexRange;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Path;
import org.reactfx.value.Val;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * A Path used to render a portion of a mulit-paragraph selection or all of a single-paragraph selection
 * with additional CSS styling; it does not have a style class associated with it.
 */
public class SelectionPath extends Path {

    private final StyleableObjectProperty highlightFill
            = new CustomStyleableProperty<>(Color.DODGERBLUE, "highlightFill", this, HIGHLIGHT_FILL);

    /**
     * Background fill for highlighted/selected text. Can be styled using "-fx-highlight-fill".
     */
    public final ObjectProperty highlightFillProperty() { return highlightFill; }
    public final Paint getHighlightFill() { return highlightFill.get(); }
    public final void setHighlightFill(Paint paint) { highlightFill.set(paint); }

    private final Val range;
    final Val rangeProperty() { return range; }

    SelectionPath(Val range) {
        setManaged(false);
        this.range = range;
    }

    @Override
    public String toString() {
        return String.format(
                "SelectionPath(styleclass=%s path=%s", getStyleClass(), super.toString()
        );
    }

    private static final CssMetaData HIGHLIGHT_FILL = new CustomCssMetaData<>(
            "-fx-highlight-fill", StyleConverter.getPaintConverter(), Color.DODGERBLUE, s -> s.highlightFill
    );

    private static final List> CSS_META_DATA_LIST;

    static {
        List> styleables = new ArrayList<>(Path.getClassCssMetaData());

        styleables.add(HIGHLIGHT_FILL);

        CSS_META_DATA_LIST = Collections.unmodifiableList(styleables);
    }

    @Override
    public List> getCssMetaData() {
        return CSS_META_DATA_LIST;
    }

    public static List> getClassCssMetaData() {
        return CSS_META_DATA_LIST;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy