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.control.Control;
import javafx.scene.text.Font;

import org.fxmisc.richtext.skin.PropertyCssMetaData;


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

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

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

        @Override protected void invalidated() {
            ((Control) 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;
        }
    }
}