package be.iminds.ilabt.jfed.experimenter_gui.ui.ribbon;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.css.PseudoClass;
import javafx.scene.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: twalcari
 * Date: 11/6/13
 * Time: 9:48 AM
 */
public class RibbonToggleButton extends RibbonButton {
    private static final Logger LOG = LoggerFactory.getLogger(RibbonToggleButton.class);
    private static final PseudoClass
            SELECTED_PSEUDO_CLASS = PseudoClass.getPseudoClass("selected");

    private final BooleanProperty selected = new SimpleBooleanProperty(false);

    {
        selected.addListener(observable -> {
            LOG.info("selected set to {}", selected.get());
            pseudoClassStateChanged(SELECTED_PSEUDO_CLASS, selected.get());
        });

        setOnAction(event -> selected.set(!selected.get()));
    }


    public RibbonToggleButton() {
    }

    public RibbonToggleButton(String s) {
        super(s);
    }

    public RibbonToggleButton(String s, Node node) {
        super(s, node);
    }


    public boolean getSelected() {
        return selected.get();
    }

    public BooleanProperty selectedProperty() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected.set(selected);
    }
}
