Java Code Examples for javafx.scene.control.ButtonBase#isPressed()

The following examples show how to use javafx.scene.control.ButtonBase#isPressed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicIconSupport.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Adds support changing icons by pressed.
 *
 * @param button the button.
 */
@FxThread
public static void addSupport(@NotNull final ButtonBase button) {

    final EditorConfig editorConfig = EditorConfig.getInstance();
    final CssColorTheme theme = editorConfig.getEnum(PREF_UI_THEME, PREF_DEFAULT_THEME);

    if (!theme.needRepaintIcons()) {
        return;
    }

    final ImageView graphic = (ImageView) button.getGraphic();
    final Image image = graphic.getImage();
    final Image original = FILE_ICON_MANAGER.getOriginal(image);

    final ObservableMap<Object, Object> properties = button.getProperties();
    properties.put(NOT_PRESSED_IMAGE, image);
    properties.put(PRESSED_IMAGE, original);

    button.pressedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            graphic.setImage((Image) properties.get(PRESSED_IMAGE));
        } else {
            graphic.setImage((Image) properties.get(NOT_PRESSED_IMAGE));
        }
    });

    if (button.isPressed()) {
        graphic.setImage(original);
    } else {
        graphic.setImage(image);
    }
}
 
Example 2
Source File: SlideCheckBoxBehavior.java    From JFX8CustomControls with Apache License 2.0 5 votes vote down vote up
/**
 * This function is invoked when an appropriate keystroke occurs which
 * causes this button to be armed if it is not already armed by a mouse
 * press.
 */
private void keyPressed() {
    final ButtonBase button = getControl();
    if (!button.isPressed() && !button.isArmed()) {
        keyDown = true;
        button.arm();
    }
}
 
Example 3
Source File: SlideCheckBoxBehavior.java    From JFX8CustomControls with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked when the mouse enters the Button. If the Button had been armed
 * by a mouse press and the mouse is still pressed, then this will cause
 * the button to be rearmed.
 */
@Override public void mouseEntered(MouseEvent e) {
    // rearm if necessary
    final ButtonBase button = getControl();
    super.mouseEntered(e);
    if (! keyDown && button.isPressed()) {
        button.arm();
    }
}