Example usage for javafx.scene.input KeyCode LEFT

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

Introduction

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

Prototype

KeyCode LEFT

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

Click Source Link

Document

Constant for the non-numpad left arrow key.

Usage

From source file:at.ac.tuwien.qse.sepm.gui.FullscreenWindow.java

@FXML
private void initialize() {
    this.stage = new Stage();
    this.scene = new Scene(this);

    stage.setScene(scene);//from w  w w.j a  v  a2 s . c o m

    image.setPreserveRatio(true);
    getChildren().add(0, image);

    hideButton.setOnAction((e) -> menu.setOpacity(0.0));
    menu.setOnMouseEntered(e -> menu.setOpacity(1.0));

    root.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(final KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.RIGHT) {
                bt_nextPressed(null);
            }
            if (keyEvent.getCode() == KeyCode.LEFT) {
                bt_previousPressed(null);
            }
            if (keyEvent.getCode() == KeyCode.ESCAPE) {
                stage.close();
            }
            if (keyEvent.getCode() == KeyCode.DIGIT1) {
                ratingPicker.setRating(Rating.BAD);
            }
            if (keyEvent.getCode() == KeyCode.DIGIT2) {
                ratingPicker.setRating(Rating.NEUTRAL);
            }
            if (keyEvent.getCode() == KeyCode.DIGIT3) {
                ratingPicker.setRating(Rating.GOOD);
            }
        }
    });

    ratingPicker.setRatingChangeHandler(this::handleRatingChange);
}

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 ava2s  .  c om
            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:view.FXApplicationController.java

public void keyAction(KeyEvent ke) {
    if (ke.getCode() == KeyCode.RIGHT) {
        goToEpoch(currentEpoch + 1);/*from  w  w w  .  j  a  v  a  2s.c o  m*/
    }

    if (ke.getCode() == KeyCode.LEFT) {
        goToEpoch(currentEpoch - 1);
    }

    if (ke.getCode() == KeyCode.H) {
        hypnogramAction();
    }

    if (ke.getCode() == KeyCode.E) {
        showEvaluationWindowAction();
    }

    if (ke.getCode() == KeyCode.L) {
        help1OnAction();
    }

    if (ke.getCode() == KeyCode.K) {
        kComplexOnAction();

    }

    if (ke.getCode() == KeyCode.UP) {
        refreshZoom(+1);
    }

    if (ke.getCode() == KeyCode.DOWN) {
        refreshZoom(-1);
    }

    if (ke.getCode() == KeyCode.W) {
        awakeButtonOnAction();
        if (featureModel.getLabel(currentEpoch) == -1) {
            goToEpoch(currentEpoch + 1);
        }
    }

    if (ke.getCode() == KeyCode.R) {
        remButtonOnAction();
        if (featureModel.getLabel(currentEpoch) == -1) {
            goToEpoch(currentEpoch + 1);
        }
    }

    if (ke.getCode() == KeyCode.DIGIT1) {
        s1ButtonOnAction();
        if (featureModel.getLabel(currentEpoch) == -1) {
            goToEpoch(currentEpoch + 1);
        }
    }

    if (ke.getCode() == KeyCode.DIGIT2) {
        s2ButtonOnAction();
        if (featureModel.getLabel(currentEpoch) == -1) {
            goToEpoch(currentEpoch + 1);
        }
    }

    if (ke.getCode() == KeyCode.DIGIT3) {
        s3ButtonOnAction();
        if (featureModel.getLabel(currentEpoch) == -1) {
            goToEpoch(currentEpoch + 1);
        }
    }

    if (ke.getCode() == KeyCode.A) {
        artefactButtonOnAction();
    }

    if (ke.getCode() == KeyCode.M) {
        arousalButtonOnAction();
    }

    if (ke.getCode() == KeyCode.D) {
        stimulationButtonOnAction();
    }

    if (ke.getCode() == KeyCode.C) {
        clearButtonOnAction();
    }

    if (ke.getCode() == KeyCode.PAGE_DOWN) {
        goToEpoch(currentEpoch - 10);
    }

    if (ke.getCode() == KeyCode.PAGE_UP) {
        goToEpoch(currentEpoch + 10);
    }

    if (ke.getCode() == KeyCode.END) {
        goToEpoch(dataModel.getNumberOf30sEpochs() - 1);
    }

    if (ke.getCode() == KeyCode.HOME) {
        goToEpoch(0);
    }

    if (ke.getCode() == KeyCode.F6) {
        visualizeButtonAction();
    }
    if (ke.getCode() == KeyCode.F7) {
        filterButtonAction();
    }
    if (ke.getCode() == KeyCode.F8) {
        dcRemoveButtonAction();
    }
    if (ke.getCode() == KeyCode.F9) {
        kcMarkersButtonAction();
    }
    if (ke.getCode() == KeyCode.F12) {
        electrodeConfiguratorButtonAction();
    }
}