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

impl.jfxtras.styles.jmetro8.FluentToggleButtonSkin Maven / Gradle / Ivy

Go to download

A theme / look and feel for JavaFX inspired (but not a copy) by Microsoft's Fluent Design

There is a newer version: 11.6.16
Show newest version
package impl.jfxtras.styles.jmetro8;

import com.sun.javafx.css.converters.BooleanConverter;
import com.sun.javafx.scene.control.skin.ToggleButtonSkin;
import javafx.beans.property.BooleanProperty;
import javafx.css.CssMetaData;
import javafx.css.SimpleStyleableBooleanProperty;
import javafx.css.Styleable;
import javafx.css.StyleableProperty;
import javafx.scene.control.SkinBase;
import javafx.scene.control.ToggleButton;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class FluentToggleButtonSkin extends ToggleButtonSkin {

    public FluentToggleButtonSkin(ToggleButton button) {
        super(button);

        ButtonAnimationHelper.setupButton(button, shrinkAnimateOnPressProperty());
    }

    /********** CSS Properties ****************/

    private static final CssMetaData SHRINK_ANIMATE_ON_PRESS_META_DATA =
            new CssMetaData(ButtonAnimationHelper.SHRINK_ANIMATE_ON_PRESS_PROPERTY_NAME,
                    BooleanConverter.getInstance(), true) {

                @Override
                public boolean isSettable(ToggleButton button) {
                    final FluentToggleButtonSkin skin = (FluentToggleButtonSkin) button.getSkin();
                    return !skin.shrinkAnimateOnPress.isBound();
                }

                @Override
                public StyleableProperty getStyleableProperty(ToggleButton button) {
                    final FluentToggleButtonSkin skin = (FluentToggleButtonSkin) button.getSkin();
                    return (StyleableProperty) skin.shrinkAnimateOnPressProperty();
                }
            };

    private BooleanProperty shrinkAnimateOnPress = new SimpleStyleableBooleanProperty(SHRINK_ANIMATE_ON_PRESS_META_DATA, true);

    private BooleanProperty shrinkAnimateOnPressProperty() { return shrinkAnimateOnPress; }

    private boolean isShrinkAnimateOnPress() { return shrinkAnimateOnPress.get(); }


    /* Setup styleables for this Skin */
    private static final List> STYLEABLES;

    static {
        final List> styleables =
                new ArrayList<>(SkinBase.getClassCssMetaData());
        styleables.add(SHRINK_ANIMATE_ON_PRESS_META_DATA);
        STYLEABLES = Collections.unmodifiableList(styleables);
    }

    /**
     * @return The CssMetaData associated with this class, which may include the
     * CssMetaData of its super classes.
     */
    public static List> getClassCssMetaData() {
        return STYLEABLES;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List> getCssMetaData() {
        return getClassCssMetaData();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy