Example usage for javafx.scene.input KeyEvent getCode

List of usage examples for javafx.scene.input KeyEvent getCode

Introduction

In this page you can find the example usage for javafx.scene.input KeyEvent getCode.

Prototype

public final KeyCode getCode() 

Source Link

Document

The key code associated with the key in this key pressed or key released event.

Usage

From source file:app.order.OrderController.java

@FXML
void validateCash(KeyEvent event) {
    Order order = getSelectedObject();//from  ww w.j  a  v a 2s.c o m
    if (event.getCode() == KeyCode.ENTER) {
        ((IOrderMetier) metier).validateCash(order);
        cash.setDisable(true);
    }
}

From source file:com.anavationllc.o2jb.ConfigurationApp.java

private EventHandler<KeyEvent> getKeyEventHandler() {
    if (keyEventHandler == null) {
        keyEventHandler = new EventHandler<KeyEvent>() {
            @Override//from   ww  w.  j  av  a  2s  . c  o m
            public void handle(KeyEvent keyEvent) {
                if (keyEvent.getCode() == KeyCode.ENTER) {
                    if (canSubmit()) {
                        keyEvent.consume();
                        okBtn.fire();
                    }
                } else if (keyEvent.getCode() == KeyCode.ESCAPE) {
                    keyEvent.consume();
                    cancelBtn.fire();
                } else {
                    okBtn.setDisable(!canSubmit());
                }
            }
        };

    }
    return keyEventHandler;
}

From source file:Jigs_Desktop_Client.GUI.FXMLDocumentController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    this.alert("resources/app_launch.mp3");
    this.user_name.requestFocus();
    this.btn_logout.setDisable(true);
    this.jc.setStatus(from_user, "online");
    this.my_circle_list.setCellFactory(new Callback<ListView<UserStatus>, ListCell<UserStatus>>() {
        @Override// w  w  w .  ja  v a2s .c om
        public ListCell<UserStatus> call(ListView<UserStatus> userObj) {
            ListCell<UserStatus> cell = new ListCell<UserStatus>() {
                @Override
                protected void updateItem(UserStatus usrObj, boolean btnl) {
                    super.updateItem(usrObj, btnl);
                    if (usrObj != null) {
                        String filename = usrObj.getStatus();
                        if (filename == null || filename.equals("") || filename.equals("null"))
                            filename = "offline";
                        else
                            System.out.println(filename);
                        Image img = new Image(
                                getClass().getResource("resources/" + filename + ".png").toExternalForm());
                        ImageView imv = new ImageView(img);
                        setGraphic(imv);
                        setText(usrObj.getUsername());
                    }
                }
            };
            return cell;
        }
    });
    this.main_panel.setBackground(Background.EMPTY);
    this.text_message.setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.ENTER) {
                sendMessage(null);
                keyEvent.consume();
            }
        }
    });
}

From source file:ambroafb.general.mapeditor.MapEditor.java

public MapEditor() {
    this.setEditable(true);
    itemsMap = new HashMap<>();
    delimiter = " : "; // default value of delimiter
    keyPattern = ""; // (?<![\\d-])\\d+
    valuePattern = ""; // [0-9]{1,13}(\\.[0-9]*)?
    keySpecChars = "";
    valueSpecChars = "";

    this.setCellFactory((ListView<MapEditorElement> param) -> new CustomCell());

    removeElement = (MapEditorElement elem) -> {
        if (itemsMap.containsKey(elem.getKey())) {
            itemsMap.remove(elem.getKey());
            if (getValue() != null && getValue().compare(elem) == 0) {
                getEditor().setText(delimiter);
            }/*w  w w .j  a  v a2 s  .c o  m*/
            getItems().remove(elem);
        }
    };

    editElement = (MapEditorElement elem) -> {
        getSelectionModel().select(-1);
        getEditor().setText(elem.getKey() + delimiter + elem.getValue());
        itemsMap.remove(elem.getKey());
        getItems().remove(elem);
    };

    // Never hide comboBox items listView:
    this.setSkin(new ComboBoxListViewSkin(this) {
        @Override
        protected boolean isHideOnClickEnabled() {
            return false;
        }
    });

    // Control textField input.
    TextField editor = getEditor();
    editor.setText(delimiter);
    editor.textProperty()
            .addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
                if (newValue == null || newValue.isEmpty() || newValue.equals(delimiter)) {
                    editor.setText(delimiter);
                } else if (!newValue.contains(delimiter)) {
                    editor.setText(oldValue);
                } else {
                    String keyInput = StringUtils.substringBefore(newValue, delimiter).trim();
                    String valueInput = StringUtils.substringAfter(newValue, delimiter).trim();

                    if (!keyInput.isEmpty() && !Pattern.matches(keyPattern, keyInput)) {
                        keyInput = StringUtils.substringBefore(oldValue, delimiter).trim();
                    }
                    if (!valueInput.isEmpty() && !Pattern.matches(valuePattern, valueInput)) {
                        valueInput = StringUtils.substringAfter(oldValue, delimiter).trim();
                    }

                    editor.setText(keyInput + delimiter + valueInput);
                }
            });

    this.setConverter(new StringConverter<MapEditorElement>() {
        @Override
        public String toString(MapEditorElement object) {
            if (object == null) {
                return delimiter;
            }
            return object.getKey() + delimiter + object.getValue();
        }

        @Override
        public MapEditorElement fromString(String input) {
            MapEditorElement result = null;
            if (input != null && input.contains(delimiter)) {
                result = getNewInstance();
                if (result == null)
                    return null;
                String keyInput = StringUtils.substringBefore(input, delimiter).trim();
                String valueInput = StringUtils.substringAfter(input, delimiter).trim();
                if (!keyInput.isEmpty()) {
                    result.setKey(keyInput);
                }
                if (!valueInput.isEmpty()) {
                    result.setValue(valueInput);
                }
                boolean keyOutOfSpec = keySpecChars.isEmpty()
                        || !StringUtils.containsOnly(result.getKey(), keySpecChars);
                boolean valueOutOfSpec = valueSpecChars.isEmpty()
                        || !StringUtils.containsOnly(result.getValue(), valueSpecChars);
                if (!keyInput.isEmpty() && !valueInput.isEmpty() && !itemsMap.containsKey(keyInput)
                        && (keyOutOfSpec && valueOutOfSpec)) {
                    itemsMap.put(keyInput, result);
                    getItems().add(result);
                    return null;
                }
            }
            return result;
        }
    });

    // Control caret position in textField.
    editor.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
        int caretOldPos = editor.getCaretPosition();
        int delimiterIndex = editor.getText().indexOf(delimiter);
        if (event.getCode().equals(KeyCode.RIGHT)) {
            if (caretOldPos + 1 > delimiterIndex && caretOldPos + 1 <= delimiterIndex + delimiter.length()) {
                editor.positionCaret(delimiterIndex + delimiter.length());
                event.consume();
            }
        } else if (event.getCode().equals(KeyCode.LEFT)) {
            if (caretOldPos - 1 >= delimiterIndex && caretOldPos - 1 < delimiterIndex + delimiter.length()) {
                editor.positionCaret(delimiterIndex);
                event.consume();
            }
        }
    });
}

From source file:de.unibw.inf2.fishification.FishWorld.java

private void registerKeys() {
    getWorldCanvas().setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override/* w  w w  .  ja va 2s  .  co  m*/
        public void handle(KeyEvent keyEvent) {

            if (keyEvent.getCode().equals(KeyCode.DIGIT1)) {
                toggleFps();
            } else if (keyEvent.getCode().equals(KeyCode.DIGIT2)) {
                toggleBackground();
            } else if (keyEvent.getCode().equals(KeyCode.DIGIT3)) {
                toggleWaveEffect();
            } else if (keyEvent.getCode().equals(KeyCode.DIGIT0)) {
                asyncTakeScreenshot();
            } else if (keyEvent.getCode().equals(KeyCode.ENTER)) {
                feedFish("all");
            } else if (keyEvent.getCode().equals(KeyCode.SPACE)) {
                togglePause();
            }

        }
    });
}

From source file:com.properned.application.SystemController.java

public void loadFileList(File selectedFile) {
    Platform.runLater(new Runnable() {

        @Override/*from ww  w  . jav  a2  s. c  o m*/
        public void run() {
            logger.info("Load the file list associated to '" + selectedFile.getAbsolutePath() + "'");

            if (MultiLanguageProperties.getInstance().getIsDirty()) {
                ButtonType result = askForSave();
                if (result.getButtonData() == ButtonData.CANCEL_CLOSE) {
                    // The file must not be loaded
                    return;
                }
            }
            Preferences.getInstance().setLastPathUsed(selectedFile.getAbsolutePath());
            String fileName = selectedFile.getName();
            String baseNameTemp = fileName.substring(0, fileName.lastIndexOf("."));

            if (fileName.contains("_")) {
                baseNameTemp = fileName.substring(0, fileName.indexOf("_"));
            }
            final String baseName = baseNameTemp;

            List<PropertiesFile> fileList = Arrays
                    .asList(selectedFile.getParentFile().listFiles(new FileFilter() {
                        @Override
                        public boolean accept(File pathname) {
                            return pathname.isFile() && pathname.getName().startsWith(baseName)
                                    && pathname.getName().endsWith(".properties");
                        }
                    })).stream().map(new Function<File, PropertiesFile>() {
                        @Override
                        public PropertiesFile apply(File t) {
                            String language = "";
                            if (t.getName().contains("_")) {
                                language = t.getName().substring(t.getName().indexOf("_") + 1,
                                        t.getName().lastIndexOf("."));
                            }
                            return new PropertiesFile(t.getAbsolutePath(), baseName, new Locale(language));
                        }
                    }).collect(Collectors.<PropertiesFile>toList());

            try {
                multiLanguageProperties.loadFileList(baseName, fileList);
                Preferences.getInstance().addFileToRecentFileList(selectedFile.getAbsolutePath());
                Properned.getInstance().getPrimaryStage().getScene()
                        .setOnKeyReleased(new EventHandler<KeyEvent>() {
                            @Override
                            public void handle(KeyEvent event) {
                                if (event.getCode() == KeyCode.S && event.isControlDown()) {
                                    logger.info("CTRL-S detected");
                                    save();
                                    event.consume();
                                }
                            }
                        });
            } catch (IOException e) {
                Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.load"), e);
            }
        }
    });
}

From source file:com.properned.application.SystemController.java

public void initialize() {
    logger.info("Initialize System controller");
    localeButton.disableProperty().bind(multiLanguageProperties.isLoadedProperty().not());
    saveButton.disableProperty().bind(multiLanguageProperties.isDirtyProperty().not()
            .or(multiLanguageProperties.isLoadedProperty().not()));
    Stage primaryStage = Properned.getInstance().getPrimaryStage();
    primaryStage.titleProperty()/* ww w  .ja  v  a 2  s. c  o  m*/
            .bind(multiLanguageProperties.baseNameProperty()
                    .concat(Bindings.when(multiLanguageProperties.isLoadedProperty())
                            .then(new SimpleStringProperty(" (")
                                    .concat(multiLanguageProperties.parentDirectoryPathProperty()).concat(")"))
                            .otherwise(""))
                    .concat(Bindings.when(multiLanguageProperties.isDirtyProperty()).then(" *").otherwise("")));

    FilteredList<String> filteredList = new FilteredList<>(multiLanguageProperties.getListMessageKey(),
            new Predicate<String>() {
                @Override
                public boolean test(String t) {
                    String filter = filterText.getText();
                    if (filter == null || filter.equals("")) {
                        return true;
                    }
                    return t.contains(filter);
                }
            });
    SortedList<String> sortedList = new SortedList<>(filteredList, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    });
    messageKeyList.setItems(sortedList);
    filterText.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            // Filter the list
            filteredList.setPredicate(new Predicate<String>() {
                @Override
                public boolean test(String t) {
                    String filter = filterText.getText();
                    if (filter == null || filter.equals("")) {
                        return true;
                    }
                    return t.contains(filter);
                }
            });

            // check the add button disabled status
            if (isKeyCanBeAdded(newValue)) {
                addButton.setDisable(false);
            } else {
                addButton.setDisable(true);
            }

        }

    });
    ChangeListener<String> changeMessageListener = new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            logger.info("Message key selection changed : " + newValue);
            valueList.setItems(FXCollections.observableArrayList());

            valueList.setItems(FXCollections
                    .observableArrayList(multiLanguageProperties.getMapPropertiesByLocale().keySet()));
        }
    };
    messageKeyList.getSelectionModel().selectedItemProperty().addListener(changeMessageListener);
    messageKeyList.setCellFactory(c -> new MessageKeyListCell(multiLanguageProperties));

    valueList.setCellFactory(c -> new ValueListCell(multiLanguageProperties, messageKeyList));

    filterText.setOnKeyReleased(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.DOWN) {
                messageKeyList.requestFocus();
                event.consume();
            } else if (event.getCode() == KeyCode.ENTER) {
                addKey();
                event.consume();
            }
        }
    });
}

From source file:jobhunter.gui.FXMLController.java

@FXML
void subscriptionTableKey(KeyEvent e) {
    if (e.getCode() == KeyCode.UP || e.getCode() == KeyCode.DOWN)
        subscriptionTableClick(null);
}

From source file:jobhunter.gui.FXMLController.java

@FXML
void jobsListKey(KeyEvent e) {
    if (e.getCode() == KeyCode.UP || e.getCode() == KeyCode.DOWN)
        jobsListClick(null);
}

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 w  w  w  .j a  v  a2s  .  c  om*/
        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);
}