Search in sources :

Example 11 with KeyEvent

use of javafx.scene.input.KeyEvent in project jabref by JabRef.

the class KeyBindingsDialogViewModelTest method testInvalidKeyBindingIsNotSaved.

@Test
public void testInvalidKeyBindingIsNotSaved() {
    setKeyBindingViewModel(KeyBinding.COPY);
    KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_RELEASED, "Q", "Q", KeyCode.Q, false, false, false, false);
    assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.COPY, shortcutKeyEvent));
    model.setNewBindingForCurrent(shortcutKeyEvent);
    KeyCombination combination = KeyCombination.keyCombination(keyBindingRepository.get(KeyBinding.COPY).get());
    assertFalse(keyBindingRepository.checkKeyCombinationEquality(combination, shortcutKeyEvent));
    model.saveKeyBindings();
    assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.COPY, shortcutKeyEvent));
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) KeyCombination(javafx.scene.input.KeyCombination) Test(org.junit.Test)

Example 12 with KeyEvent

use of javafx.scene.input.KeyEvent in project jabref by JabRef.

the class KeyBindingsDialogViewModelTest method testKeyBindingCategory.

@Test
public void testKeyBindingCategory() {
    KeyBindingViewModel bindViewModel = new KeyBindingViewModel(keyBindingRepository, KeyBindingCategory.FILE);
    model.selectedKeyBindingProperty().set(bindViewModel);
    KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "M", "M", KeyCode.M, true, true, true, false);
    assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.CLEANUP, shortcutKeyEvent));
    model.setNewBindingForCurrent(shortcutKeyEvent);
    assertNull(model.selectedKeyBindingProperty().get().getKeyBinding());
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) Test(org.junit.Test)

Example 13 with KeyEvent

use of javafx.scene.input.KeyEvent in project Minesweeper3D by SethDamiani.

the class Main method createCube.

private void createCube(Group cubeGroup, Group gX, Group gY, Scene scene, Stage stage) {
    cubeGroup.setTranslateZ(-200);
    sideB.setTranslateX(200);
    sideB.setTranslateZ(200);
    sideB.setRotationAxis(new Point3D(0, 1, 0));
    sideB.setRotate(90);
    sideC.setTranslateZ(200);
    sideC.setTranslateX(-200);
    sideC.setRotationAxis(new Point3D(0, 1, 0));
    sideC.setRotate(90);
    sideD.setTranslateZ(400);
    sideE.setRotationAxis(new Point3D(1, 0, 0));
    sideE.setRotate(90);
    sideE.setTranslateY(200);
    sideE.setTranslateZ(200);
    sideF.setRotationAxis(new Point3D(1, 0, 0));
    sideF.setRotate(90);
    sideF.setTranslateY(-200);
    sideF.setTranslateZ(200);
    RotateTransition rightRotate = new RotateTransition(Duration.millis(10000), gY);
    rightRotate.setAxis(Rotate.Y_AXIS);
    rightRotate.setByAngle(-1000);
    rightRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition leftRotate = new RotateTransition(Duration.millis(10000), gY);
    leftRotate.setAxis(Rotate.Y_AXIS);
    leftRotate.setByAngle(1000);
    leftRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition upRotate = new RotateTransition(Duration.millis(10000), gX);
    upRotate.setAxis(Rotate.X_AXIS);
    upRotate.setByAngle(-1000);
    upRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition downRotate = new RotateTransition(Duration.millis(10000), gX);
    downRotate.setAxis(Rotate.X_AXIS);
    downRotate.setByAngle(1000);
    downRotate.setInterpolator(Interpolator.LINEAR);
    EventHandler<KeyEvent> KeyPressHandler = event -> {
        if (event.getCode() == KeyCode.ESCAPE) {
            timeTask.pause();
            stage.setScene(confirmExit);
        } else if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
            rightRotate.play();
        else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
            leftRotate.play();
        else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
            upRotate.play();
        else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
            downRotate.play();
    };
    scene.addEventHandler(KeyEvent.KEY_PRESSED, KeyPressHandler);
    EventHandler<KeyEvent> KeyReleaseHandler = event -> {
        if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
            rightRotate.stop();
        else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
            leftRotate.stop();
        else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
            upRotate.stop();
        else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
            downRotate.stop();
    };
    scene.addEventHandler(KeyEvent.KEY_RELEASED, KeyReleaseHandler);
}
Also used : EventHandler(javafx.event.EventHandler) FontWeight(javafx.scene.text.FontWeight) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) java.util(java.util) Point3D(javafx.geometry.Point3D) javafx.scene.control(javafx.scene.control) Rotate(javafx.scene.transform.Rotate) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Application(javafx.application.Application) TextAlignment(javafx.scene.text.TextAlignment) RotateTransition(javafx.animation.RotateTransition) PrintWriter(java.io.PrintWriter) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Font(javafx.scene.text.Font) FileWriter(java.io.FileWriter) Timeline(javafx.animation.Timeline) ImagePattern(javafx.scene.paint.ImagePattern) Rectangle(javafx.scene.shape.Rectangle) IOException(java.io.IOException) KeyEvent(javafx.scene.input.KeyEvent) Group(javafx.scene.Group) File(java.io.File) Text(javafx.scene.text.Text) Duration(javafx.util.Duration) Interpolator(javafx.animation.Interpolator) Stage(javafx.stage.Stage) ObservableList(javafx.collections.ObservableList) Image(javafx.scene.image.Image) KeyEvent(javafx.scene.input.KeyEvent) Point3D(javafx.geometry.Point3D) RotateTransition(javafx.animation.RotateTransition)

Example 14 with KeyEvent

use of javafx.scene.input.KeyEvent in project trex-stateless-gui by cisco-system-traffic-generator.

the class TextFieldTableViewCell method call.

@Override
public TableCell call(TableColumn param) {
    return new TableCell<S, T>() {

        private TextField textField;

        {
            textField = new TextField();
            textField.setPrefSize(158, 22);
            textField.setOnKeyPressed((KeyEvent event) -> {
                if (event.getCode().equals(KeyCode.ENTER)) {
                    commitEdit((T) textField.getText());
                }
            });
            textField.focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (!newValue) {
                    commitEdit((T) textField.getText());
                }
            });
            textField.textProperty().bindBidirectional(textProperty());
        }

        @Override
        public void updateItem(final T item, final boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                setGraphic(textField);
                setText((String) getItem());
            }
        }

        @Override
        public void commitEdit(T item) {
            if (!isEditing() && !item.equals(getItem())) {
                TableView<S> table = getTableView();
                if (table != null) {
                    TableColumn<S, T> column = getTableColumn();
                    CellEditEvent<S, T> event = new CellEditEvent<>(table, new TablePosition<S, T>(table, getIndex(), column), TableColumn.editCommitEvent(), item);
                    Event.fireEvent(column, event);
                }
            }
            super.commitEdit(item);
        }
    };
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) TableCell(javafx.scene.control.TableCell) ObservableValue(javafx.beans.value.ObservableValue) TextField(javafx.scene.control.TextField) CellEditEvent(javafx.scene.control.TableColumn.CellEditEvent)

Example 15 with KeyEvent

use of javafx.scene.input.KeyEvent in project jgnash by ccavanaugh.

the class JasperViewerDialogController method initialize.

@FXML
private void initialize() {
    busyPane = new BusyPane();
    stackPane.getChildren().add(busyPane);
    screenResolution = Screen.getPrimary().getDpi();
    saveButton.disableProperty().bind(jasperPrint.isNull());
    printButton.disableProperty().bind(jasperPrint.isNull());
    reportFormatButton.disableProperty().bind(jasperPrint.isNull());
    fontSizeSpinner.disableProperty().bind(jasperPrint.isNull());
    firstButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
    previousButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
    nextButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
    lastButton.disableProperty().bind(jasperPrint.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
    fitPageButton.disableProperty().bind(jasperPrint.isNull());
    fitHeightButton.disableProperty().bind(jasperPrint.isNull());
    fitWidthButton.disableProperty().bind(jasperPrint.isNull());
    zoomComboBox.disableProperty().bind(jasperPrint.isNull());
    zoomInButton.disableProperty().bind(jasperPrint.isNull().or(zoomProperty.greaterThanOrEqualTo(DEFAULT_ZOOMS[DEFAULT_ZOOMS.length - 1] / 100)));
    zoomOutButton.disableProperty().bind(jasperPrint.isNull().or(zoomProperty.lessThanOrEqualTo(DEFAULT_ZOOMS[0] / 100)));
    fitPageButton.setSelected(true);
    firstButton.prefHeightProperty().bind(saveButton.heightProperty());
    previousButton.prefHeightProperty().bind(saveButton.heightProperty());
    nextButton.prefHeightProperty().bind(saveButton.heightProperty());
    lastButton.prefHeightProperty().bind(saveButton.heightProperty());
    zoomInButton.prefHeightProperty().bind(saveButton.heightProperty());
    zoomOutButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitHeightButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitWidthButton.prefHeightProperty().bind(saveButton.heightProperty());
    fitPageButton.prefHeightProperty().bind(saveButton.heightProperty());
    fontSizeSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(5, 15, 7));
    report.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            jasperPrint.set(newValue.createJasperPrint(false));
            fontSizeSpinner.valueFactoryProperty().get().setValue(newValue.getBaseFontSize());
            newValue.refreshCallBackProperty().set(() -> createJasperPrint(newValue));
        } else {
            jasperPrint.set(null);
        }
    });
    jasperPrint.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            pageCount.set(newValue.getPages().size());
        } else {
            pageCount.set(0);
        }
        Platform.runLater(this::refresh);
    });
    reportControllerPaneProperty.addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            reportControllerPane.getChildren().addAll(newValue);
        }
    });
    fontSizeSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
        report.get().setBaseFontSize(newValue);
        Platform.runLater(() -> createJasperPrint(report.get()));
    });
    pagePane.setSpacing(PAGE_BORDER);
    pagePane.setPadding(new Insets(PAGE_BORDER));
    pagePane.setAlignment(Pos.CENTER);
    scrollPane.viewportBoundsProperty().addListener((observable, oldValue, newValue) -> {
        if (fitWidthButton.isSelected()) {
            handleFitPageWidthAction();
        }
        scrollPane.setFitToWidth(pagePane.prefWidth(-1) < newValue.getWidth());
        scrollPane.setFitToHeight(pagePane.prefHeight(-1) < newValue.getHeight());
    });
    scrollPane.vvalueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
        final double interval = 1d / (double) pageCount.get();
        double low = pageIndex.get() * interval;
        double hi = low + interval;
        int newPageIndex = pageIndex.get();
        if (hi < newValue.doubleValue() && pageIndex.get() < pageCount.get()) {
            while (hi < newValue.doubleValue()) {
                newPageIndex++;
                hi += interval;
            }
            // increase the page index to match the scroll position
            setPageIndex(newPageIndex);
        } else if (low > newValue.doubleValue() && pageIndex.get() > 0) {
            while (low > newValue.doubleValue()) {
                newPageIndex--;
                low -= interval;
            }
            // decrease the page index to match the scroll position
            setPageIndex(newPageIndex);
        }
    });
    for (int zoom : DEFAULT_ZOOMS) {
        zoomComboBox.getItems().add(zoom + "%");
    }
    zoomComboBox.getSelectionModel().select(DEFAULT_ZOOM_INDEX);
    zoomComboBox.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent e) -> {
        if (e.getCode() == KeyCode.ENTER) {
            handleZoomChangedAction();
        }
    });
    setZoomRatio(1);
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) BusyPane(jgnash.uifx.control.BusyPane) Insets(javafx.geometry.Insets) ObservableValue(javafx.beans.value.ObservableValue) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) FXML(javafx.fxml.FXML) InjectFXML(jgnash.uifx.util.InjectFXML)

Aggregations

KeyEvent (javafx.scene.input.KeyEvent)15 Test (org.junit.Test)8 KeyCombination (javafx.scene.input.KeyCombination)4 IOException (java.io.IOException)3 EventHandler (javafx.event.EventHandler)3 Scene (javafx.scene.Scene)3 TextField (javafx.scene.control.TextField)3 Image (javafx.scene.image.Image)3 KeyCode (javafx.scene.input.KeyCode)3 Ignore (org.junit.Ignore)3 List (java.util.List)2 Platform (javafx.application.Platform)2 ObservableValue (javafx.beans.value.ObservableValue)2 Parent (javafx.scene.Parent)2 KeyCodeCombination (javafx.scene.input.KeyCodeCombination)2 Stage (javafx.stage.Stage)2 LoggerFactory (org.slf4j.LoggerFactory)2 Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 Guice (com.google.inject.Guice)1