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

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

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

import javafx.beans.property.SimpleBooleanProperty;
import javafx.css.CssMetaData;
import javafx.css.PseudoClass;
import javafx.css.StyleConverter;
import javafx.css.Styleable;
import javafx.css.StyleableObjectProperty;
import javafx.scene.layout.Region;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;


/**
 * CSS stuff related to {@link StyledTextArea}.
 */
class CssProperties {

    static final PseudoClass PSEUDO_CLASS_READONLY
            = PseudoClass.getPseudoClass("readonly");

    static class EditableProperty extends SimpleBooleanProperty {
        public EditableProperty(R region) {
            super(region, "editable", true);
        }

        @Override protected void invalidated() {
            ((Region) getBean()).pseudoClassStateChanged(PSEUDO_CLASS_READONLY, !get());
        }
    }

    static class FontProperty extends StyleableObjectProperty {
        private final S textArea;
        private final CssMetaData cssMetaData;

        public FontProperty(S textArea) {
            this.textArea = textArea;
            this.cssMetaData = new PropertyCssMetaData(
                    this, "-fx-font", StyleConverter.getFontConverter(),
                    Font.getDefault());
        }

        @Override
        public Object getBean() { return textArea; }

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

        @Override
        public CssMetaData getCssMetaData() {
            return cssMetaData;
        }
    }

    static class HighlightFillProperty extends StyleableObjectProperty {
        private final Object bean;

        private final CssMetaData cssMetaData;

        public HighlightFillProperty(Object bean, Paint initialValue) {
            super(initialValue);
            this.bean = bean;
            cssMetaData = new PropertyCssMetaData<>(
                    this, "-fx-highlight-fill",
                    StyleConverter.getPaintConverter(), initialValue);
        }

        @Override
        public Object getBean() {
            return bean;
        }

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

        @Override
        public CssMetaData getCssMetaData() {
            return cssMetaData;
        }
    }

    static class HighlightTextFillProperty extends StyleableObjectProperty {
        private final Object bean;

        private final CssMetaData cssMetaData;

        public HighlightTextFillProperty(Object bean, Paint initialValue) {
            super(initialValue);
            this.bean = bean;
            cssMetaData = new PropertyCssMetaData<>(
                    this, "-fx-highlight-text-fill",
                    StyleConverter.getPaintConverter(), initialValue);
        }

        @Override
        public Object getBean() {
            return bean;
        }

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

        @Override
        public CssMetaData getCssMetaData() {
            return cssMetaData;
        }
    }

    static class CaretBlinkRateProperty extends StyleableObjectProperty {
        private final Object bean;

        private final CssMetaData cssMetaData;

        public CaretBlinkRateProperty(Object bean, javafx.util.Duration initialValue) {
            super(initialValue);
            this.bean = bean;
            cssMetaData = new PropertyCssMetaData<>(
                    this, "-fx-caret-blink-rate",
                    StyleConverter.getDurationConverter(), initialValue);
        }

        @Override
        public Object getBean() {
            return bean;
        }

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

        @Override
        public CssMetaData getCssMetaData() {
            return cssMetaData;
        }
    }
}