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

de.jensd.fx.glyphs.control.skin.GlyphCheckBoxSkin Maven / Gradle / Ivy

package de.jensd.fx.glyphs.control.skin;

import com.sun.javafx.scene.control.skin.CheckBoxSkin;
import de.jensd.fx.glyphs.GlyphIcon;
import de.jensd.fx.glyphs.control.GlyphCheckBox;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.SetChangeListener;
import javafx.css.PseudoClass;
import javafx.scene.layout.StackPane;

/**
 *
 * @author Jens Deters ([email protected])
 */
public class GlyphCheckBoxSkin extends CheckBoxSkin {

    private final StackPane box;

    public GlyphCheckBoxSkin(GlyphCheckBox checkbox) {
        super(checkbox);
        box = (StackPane) getChildren().get(getChildren().size() - 1);
        box.getStyleClass().clear();
        box.getChildren().addAll(checkbox.getNotSelectedIcon());
        checkbox.armedProperty().addListener((ObservableValue observable, Boolean oldValue, Boolean newValue) -> {
            handleState();
        });
        checkbox.selectedProperty().addListener((ObservableValue observable, Boolean oldValue, Boolean newValue) -> {
            handleState();
        });
        handleState();
    }

    private void handleState(){
        if (getSkinnable().isSelected()) {
            box.getChildren().setAll(((GlyphCheckBox)getSkinnable()).getSelectedIcon());
        } else {
            box.getChildren().setAll(((GlyphCheckBox)getSkinnable()).getNotSelectedIcon());
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy