Example usage for javafx.scene.input InputEvent ANY

List of usage examples for javafx.scene.input InputEvent ANY

Introduction

In this page you can find the example usage for javafx.scene.input InputEvent ANY.

Prototype

EventType ANY

To view the source code for javafx.scene.input InputEvent ANY.

Click Source Link

Document

Common supertype for all input event types.

Usage

From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java

public LookupFieldSkin(LookupField<T> control) {
    super(control, new LookupFieldBehavior<>(control));
    this.lookupField = control;
    // move focus in to the textfield
    lookupField.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override//from  ww  w  .  j  a va  2  s .  co  m
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) {
            if (hasFocus) {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        textField.requestFocus();
                    }
                });
            }

        }
    });
    initialize();

    textField.focusedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) {
            if (!hasFocus) {
                validate();
            }
        }
    });

    lookupField.addEventFilter(InputEvent.ANY, new EventHandler<InputEvent>() {
        @Override
        public void handle(InputEvent t) {
            if (textField == null) {
                return;
            }

            // When the user hits the enter or F4 keys, we respond before 
            // ever giving the event to the TextField.
            if (t instanceof KeyEvent) {
                KeyEvent ke = (KeyEvent) t;

                if ((ke.getCode() == KeyCode.F10 || ke.getCode() == KeyCode.ESCAPE
                        || ke.getCode() == KeyCode.ENTER) && !ke.isControlDown()) {

                    // RT-23275: The TextField fires F10 and ESCAPE key events
                    // up to the parent, which are then fired back at the 
                    // TextField, and this ends up in an infinite loop until
                    // the stack overflows. So, here we consume these two
                    // events and stop them from going any further.
                    t.consume();
                    return;
                }
            }
        }
    });

    textField.promptTextProperty().bind(lookupField.promptTextProperty());
    getSkinnable().requestLayout();

    registerChangeListener(control.showingSuggestionProperty(), PROP_SHOWING_SUGGESTION);
    registerChangeListener(control.showingLookupDialogProperty(), PROP_SHOWING_LOOKUP_WINDOW);
    registerChangeListener(control.resettingDisplayTextProperty(), PROP_RESETTING_DISPLAY_TEXT);
}