/* * Copyright (c) 2013 by Gerrit Grunwald * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package eu.hansolo.enzo.experimental.pbutton; import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanPropertyBase; import javafx.css.PseudoClass; import javafx.scene.control.Control; public class PushButton extends Control { private static final PseudoClass SELECTED_PSEUDO_CLASS = PseudoClass.getPseudoClass("selected"); private boolean keepAspect; private BooleanProperty selected; // ******************** Constructors ************************************** public PushButton() { getStyleClass().add("push-button"); keepAspect = true; } // ******************** Methods ******************************************* public final boolean isKeepAspect() { return keepAspect; } public final void setKeepAspect(final boolean KEEP_ASPECT) { keepAspect = KEEP_ASPECT; } public final boolean isSelected() { return null == selected ? false : selected.get(); } public final void setSelected(final boolean SELECTED) { selectedProperty().set(SELECTED); } public final BooleanProperty selectedProperty() { if (null == selected) { selected = new BooleanPropertyBase(false) { @Override protected void invalidated() { pseudoClassStateChanged(SELECTED_PSEUDO_CLASS, get()); } @Override public Object getBean() { return this; } @Override public String getName() { return "selected"; } }; } return selected; } @Override public boolean isResizable() { return true; } // ******************** Style related ************************************* @Override protected String getUserAgentStylesheet() { return getClass().getResource(getClass().getSimpleName().toLowerCase() + ".css").toExternalForm(); } }