Example usage for javafx.scene.input KeyCode ENTER

List of usage examples for javafx.scene.input KeyCode ENTER

Introduction

In this page you can find the example usage for javafx.scene.input KeyCode ENTER.

Prototype

KeyCode ENTER

To view the source code for javafx.scene.input KeyCode ENTER.

Click Source Link

Document

Constant for the Enter key.

Usage

From source file:com.loyalty.controllers.CheckInController.java

@Override
public void windowShown() {
    schedule(() -> closeWindow());/*from  w w  w . j a v a2  s  .co m*/
    rect_panel.getScene().setOnKeyPressed(event -> {
        if (event.getCode() == KeyCode.ENTER) {
            if (hiddenCardField.getText().length() == 0) {
                getDialogManager().showInformation("Card number should have at least 1 symbol");
                closeWindow();
                return;
            }
            try {
                stopTimer();
                final CardDTO cardDTO = getService().checkIn(hiddenCardField.getText());
                FXMLBean existingCustomer = getContext().getBean("existingcustomer", FXMLBean.class);
                existingCustomer.getController().setModel(cardDTO);
                existingCustomer.getRegion().showAndWait();
            } catch (KioskException ke) {
                getDialogManager().showInformation(ke.getMessage());
            } catch (IOException ioe) {
                getDialogManager().showInformation("No Connection with server.");
            } finally {
                closeWindow();
            }
        } else if (event.getCode().isDigitKey() || event.getCode().isLetterKey()) {
            hiddenCardField.setText(hiddenCardField.getText() + event.getText());
        }
    });
}

From source file:account.management.controller.SalaryVoucherController.java

/**
 * Initializes the controller class./*from  ww w . ja  va 2  s .  c  o m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.amount_words.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit deposit voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        try {
                            onSubmitButtonClick(null);
                        } catch (ParseException ex) {
                            Logger.getLogger(SalaryVoucherController.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        }
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();
}

From source file:com.playonlinux.javafx.mainwindow.console.ConsoleTab.java

public ConsoleTab(CommandLineInterpreterFactory commandLineInterpreterFactory) {
    final VBox content = new VBox();

    commandInterpreter = commandLineInterpreterFactory.createInstance();

    this.setText(translate("Console"));
    this.setContent(content);

    final TextField command = new TextField();
    command.getStyleClass().add("consoleCommandType");
    final TextFlow console = new TextFlow();
    final ScrollPane consolePane = new ScrollPane(console);
    content.getStyleClass().add("rightPane");

    consolePane.getStyleClass().add("console");
    consolePane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    content.getChildren().addAll(consolePane, command);

    command.requestFocus();//from  ww  w.  java2 s  .  c o m

    command.setOnKeyPressed(event -> {
        if (event.getCode() == KeyCode.ENTER) {
            final String commandToSend = command.getText();
            final int cursorPosition = command.getCaretPosition();
            command.setDisable(true);
            commandHistory.add(new CommandHistory.Item(commandToSend, cursorPosition));
            Text commandText = new Text(nextSymbol + commandToSend + "\n");
            commandText.getStyleClass().add("commandText");
            console.getChildren().add(commandText);
            command.setText("");

            if (commandInterpreter.sendLine(commandToSend, message -> {
                Platform.runLater(() -> {
                    if (!StringUtils.isBlank(message)) {
                        Text resultText = new Text(message);
                        resultText.getStyleClass().add("resultText");
                        console.getChildren().add(resultText);
                    }
                    command.setDisable(false);
                    command.requestFocus();
                    consolePane.setVvalue(consolePane.getVmax());
                });
            })) {
                nextSymbol = NOT_INSIDE_BLOCK;
            } else {
                nextSymbol = INSIDE_BLOCK;
            }
        }
    });

    command.setOnKeyReleased(event -> {
        if (event.getCode() == KeyCode.UP) {
            CommandHistory.Item historyItem = commandHistory.up();
            command.setText(historyItem.getCommand());
            command.positionCaret(historyItem.getCursorPosition());
        } else if (event.getCode() == KeyCode.DOWN) {
            CommandHistory.Item historyItem = commandHistory.down();
            command.setText(historyItem.getCommand());
            command.positionCaret(historyItem.getCursorPosition());
        }
    });

    this.setOnCloseRequest(event -> commandInterpreter.close());
}

From source file:account.management.controller.POVoucherController.java

/**
 * Initializes the controller class./*from w  ww.  j  ava2 s . c o m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    balance.focusedProperty().addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue) {
                    Platform.runLater(new Runnable() {

                        @Override
                        public void run() {
                            balance.requestFocus();
                            balance.selectAll();
                        }
                    });

                }
            });
    this.container.getChildren().remove(0);
    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.total_price.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit deposit voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        try {
                            onSubmitButtonClick(null);
                        } catch (ParseException ex) {
                            Logger.getLogger(SalaryVoucherController.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        }
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();
}

From source file:account.management.controller.expenseVoucherController.java

@Override
public void initialize(URL location, ResourceBundle resources) {

    new AutoCompleteComboBoxListener<>(this.location);
    this.location.setOnHiding((e) -> {
        Location a = this.location.getSelectionModel().getSelectedItem();
        this.location.setEditable(false);
        this.location.getSelectionModel().select(a);
    });//from ww  w.  j  av  a2  s.c  o m
    this.location.setOnShowing((e) -> {
        this.location.setEditable(true);
    });

    try {
        HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/locations").asJson();
        JSONArray array = res.getBody().getArray();
        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            this.location.getItems()
                    .add(new Location(obj.getInt("id"), obj.getString("name"), obj.getString("details")));
        }
        this.amount.setOnKeyReleased((e) -> {
            calculateTotal();
        });
    } catch (Exception e) {
    }

    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.save.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit expense voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        onSaveButtonClick(null);
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();

}

From source file:cz.afrosoft.whattoeat.cookbook.recipe.gui.dialog.RecipeViewDialog.java

private void setupServingsField() {
    servingsField.setOnKeyPressed(event -> {
        if (event.getCode() == KeyCode.ENTER) {
            float servings = servingsField.getFloatOrZero();
            if (servings > 0) {
                ingredientQuantityTable.setRecipeIngredientsQuantities(servings, recipeIngredients);
                updatePriceLabel();/*from w w w  . j  a v a  2  s  .  com*/
            }
            event.consume();
        }
    });
}

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  www . j  a  v  a 2s  .  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);
}

From source file:ca.wumbo.doommanager.client.controller.ConsoleController.java

@FXML
private void initialize() {
    textField.setOnKeyPressed(event -> {
        // Submit any text on enter.
        if (event.getCode().equals(KeyCode.ENTER))
            submitLineToConsole();// www  .ja  v  a 2  s. co  m

        // If we press up/down, look for lines we stored.
        if (event.getCode().equals(KeyCode.UP) || event.getCode().equals(KeyCode.DOWN)) {
            if (commandBuffer.size() > 0) {
                commandBufferIndex += (event.getCode().equals(KeyCode.UP) ? -1 : 1);
                commandBufferIndex = Math.min(Math.max(0, commandBufferIndex), commandBuffer.size());
                textField.setText(commandBufferIndex == commandBuffer.size() ? ""
                        : commandBuffer.get(commandBufferIndex));
                textField.end();
                event.consume(); // Has to be consumed or else it will mess up the end() caret setting.
            } else {
                textField.setText("");
            }
        }
    });
}

From source file:org.beryx.viewreka.fxapp.codearea.SimpleCodeArea.java

public SimpleCodeArea(String text) {
    super(text);//from   w w  w .j  a v a  2 s .  com

    putStyleGroup("KEYWORD", "keyword", NEVER_MATCHING);
    putStyleGroup("PAREN", "paren", PAREN_PATTERN);
    putStyleGroup("BRACE", "brace", BRACE_PATTERN);
    putStyleGroup("BRACKET", "bracket", BRACKET_PATTERN);
    putStyleGroup("SEMICOLON", "semicolon", SEMICOLON_PATTERN);
    putStyleGroup("STRING", "string", STRING_PATTERN);
    putStyleGroup("STRING2", "string", STRING2_PATTERN);
    putStyleGroup("COMMENT", "comment", COMMENT_PATTERN);

    String cssName = SimpleCodeArea.class.getSimpleName() + ".css";
    getStylesheets().add(SimpleCodeArea.class.getResource(cssName).toExternalForm());

    setParagraphGraphicFactory(LineNumberFactory.get(this));
    richChanges().subscribe(change -> {
        setStyleSpans(0, computeHighlighting(getText()));
    });
    EventHandler<? super KeyEvent> tabHandler = EventHandlerHelper.on(EventPattern.keyPressed(KeyCode.ENTER))
            .act(event -> applyEnter()).on(EventPattern.keyPressed(KeyCode.TAB)).act(event -> applyTab())
            .on(EventPattern.keyPressed(KeyCode.TAB, KeyCombination.SHIFT_DOWN)).act(event -> applyShiftTab())
            .create();
    EventHandlerHelper.install(onKeyPressedProperty(), tabHandler);
}

From source file:com.hengyi.japp.print.client.controller.MdController.java

@FXML
private void autoCompleteSapMara(KeyEvent ev) {
    try {/*w  w w.  jav a2  s.c  o m*/
        if (KeyCode.RIGHT.equals(ev.getCode())) {
            List<SapMara> sapMaras = md.getSapT001().autoCompleteSapMara(matnrField.getText());
            sapMaraListView.setItems(observableArrayList(sapMaras));
            sapMaraListView.setVisible(true);
            sapMaraListView.getSelectionModel().selectFirst();
        } else if (KeyCode.UP.equals(ev.getCode()) || KeyCode.DOWN.equals(ev.getCode())) {
            sapMaraListView.fireEvent(new KeyEvent(null, sapMaraListView, KeyEvent.KEY_PRESSED,
                    ev.getCharacter(), ev.getText(), ev.getCode(), false, false, false, false));
        } else if (KeyCode.ENTER.equals(ev.getCode())) {
            selectSapMara(sapMaraListView.getSelectionModel().getSelectedItem());
            sapMaraListView.setVisible(false);
        }
    } catch (Exception ex) {
        Util.alertDialog(ex);
    }
}