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

org.fxmisc.richtext.skin.TextExt Maven / Gradle / Ivy

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

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

import javafx.beans.property.ObjectProperty;
import javafx.css.CssMetaData;
import javafx.css.StyleConverter;
import javafx.css.Styleable;
import javafx.css.StyleableObjectProperty;
import javafx.css.StyleableProperty;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;

public class TextExt extends Text {

    private final StyleableObjectProperty backgroundFill = new StyleableObjectProperty(null) {
        @Override
        public Object getBean() {
            return TextExt.this;
        }

        @Override
        public String getName() {
            return "backgroundFill";
        }

        @Override
        public CssMetaData getCssMetaData() {
            return StyleableProperties.BACKGROUND_FILL;
        }
    };

    TextExt(String text) {
        super(text);
    }

    @Override
    public List> getCssMetaData() {
        // Get list value and make it modifiable
        List> styleables = new ArrayList<>(super.getCssMetaData());

        // Add new properties
        styleables.add(StyleableProperties.BACKGROUND_FILL);

        // Return list value
        return styleables;
    }

    public Paint getBackgroundFill() {
        return backgroundFill.get();
    }

    public void setBackgroundFill(Paint fill) {
        backgroundFill.set(fill);
    }

    public ObjectProperty backgroundFillProperty() {
        return backgroundFill;
    }

    private static class StyleableProperties {

        private static final CssMetaData BACKGROUND_FILL = new CssMetaData(
                "-fx-background-fill",
                StyleConverter.getPaintConverter(),
                Color.TRANSPARENT) {
            @Override
            public boolean isSettable(TextExt node) {
                return !node.backgroundFill.isBound();
            }

            @Override
            public StyleableProperty getStyleableProperty(TextExt node) {
                return node.backgroundFill;
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy