Example usage for javafx.scene.input KeyEvent KEY_PRESSED

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

Introduction

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

Prototype

EventType KEY_PRESSED

To view the source code for javafx.scene.input KeyEvent KEY_PRESSED.

Click Source Link

Document

This event occurs when a key has been pressed.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");
    // Define an event filter
    EventHandler filter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Filtering out event " + event.getEventType());
            event.consume();/*  w  w w  . ja va  2  s. c  o m*/
        }
    };
    // Register the same filter for two different nodes
    scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter);

    // Register the filter for another event type
    scene.addEventFilter(KeyEvent.KEY_PRESSED, filter);

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");
    // Define an event filter
    EventHandler filter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Filtering out event " + event.getEventType());
            event.consume();/*w  w  w.  j av a 2 s . com*/
        }
    };
    // Register the same filter for two different nodes
    scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter);

    // Register the filter for another event type
    scene.addEventFilter(KeyEvent.KEY_PRESSED, filter);

    scene.removeEventFilter(MouseEvent.MOUSE_PRESSED, filter);

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

public static java.awt.event.KeyEvent toAwt(final KeyEvent event) {
    final EventType type = event.getEventType();
    if (null == type) {
        return null;
    }/* w  w w .j a  v a 2 s  .  co  m*/

    final int id;
    if (KeyEvent.KEY_TYPED.equals(type)) {
        id = java.awt.event.KeyEvent.KEY_TYPED;
    } else if (KeyEvent.KEY_PRESSED.equals(type)) {
        id = java.awt.event.KeyEvent.KEY_PRESSED;
    } else if (KeyEvent.KEY_RELEASED.equals(type)) {
        id = java.awt.event.KeyEvent.KEY_RELEASED;
    } else {
        return null;
    }

    final long when = -1;
    final int modifiers = modifiers(event);
    final int keyCode = keyCode(event);
    final String keyValue = event.getCharacter();
    final char keyChar = keyValue != null && !keyValue.isEmpty() ? keyValue.charAt(0) : ' ';
    return new java.awt.event.KeyEvent(empty, id, when, modifiers, keyCode, keyChar);
}

From source file:com.bekwam.examples.javafx.oldscores.ScoresDialogController.java

@FXML
public void initialize() {

    EventHandler<KeyEvent> f1KeyHandler = (evt) -> {

        if (evt.getCode().equals(KeyCode.F1)) {
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("[OPEN HELP]");
                }/* w w  w  . ja  v  a  2s . co  m*/
                mainViewRef.get().openHelpDialog();
            } catch (IOException exc) {
                String msg = "error showing help dialog";
                logger.error(msg);
                Alert alert = new Alert(Alert.AlertType.ERROR, msg);
                alert.showAndWait();
            }
        }
    };

    txtVerbalScore1995.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtVerbalScoreRecentered.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtMathScore1995.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtMathScoreRecentered.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);

}

From source file:com.bekwam.examples.javafx.oldscores3.ScoresViewController.java

@FXML
public void initialize() {

    EventHandler<KeyEvent> f1KeyHandler = (evt) -> {

        if (evt.getCode().equals(KeyCode.F1)) {
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("[OPEN HELP]");
                }//from ww  w . j a  v  a  2 s .com
                navigationDelegate.openHelpDialog();
            } catch (Exception exc) {
                String msg = "error showing help dialog";
                logger.error(msg);
                Alert alert = new Alert(Alert.AlertType.ERROR, msg);
                alert.showAndWait();
            }
        }
    };

    txtVerbalScore1995.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtVerbalScoreRecentered.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtMathScore1995.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtMathScoreRecentered.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);

}

From source file:com.bekwam.examples.javafx.oldscores1.ScoresDialogController.java

@FXML
public void initialize() {

    EventHandler<KeyEvent> f1KeyHandler = (evt) -> {

        if (evt.getCode().equals(KeyCode.F1)) {
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("[OPEN HELP]");
                }/*from  w  w w.  java2 s.c om*/
                if (mainViewRef != null) {
                    if (mainViewRef.get() != null) {
                        mainViewRef.get().openHelpDialog();
                    }
                }
            } catch (IOException exc) {
                String msg = "error showing help dialog";
                logger.error(msg);
                Alert alert = new Alert(Alert.AlertType.ERROR, msg);
                alert.showAndWait();
            }
        }
    };

    txtVerbalScore1995.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtVerbalScoreRecentered.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtMathScore1995.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);
    txtMathScoreRecentered.addEventHandler(KeyEvent.KEY_PRESSED, f1KeyHandler);

}

From source file:Main.java

public static java.awt.event.KeyEvent toAwt(final ScrollEvent event) {
    final EventType type = event.getEventType();
    if (null == type) {
        return null;
    }//from   ww  w  . jav  a 2  s.c  o m

    final long when = -1;
    final int id = java.awt.event.KeyEvent.KEY_PRESSED;
    final int keyCode;
    if (event.getDeltaY() > 0) {
        keyCode = java.awt.event.KeyEvent.VK_PAGE_DOWN;
    } else {
        keyCode = java.awt.event.KeyEvent.VK_PAGE_UP;
    }
    final int modifiers = modifiers(event);
    final char keyChar = ' ';
    return new java.awt.event.KeyEvent(empty, id, when, modifiers, keyCode, keyChar);
}

From source file:by.zuyeu.deyestracker.reader.ui.readpane.ReadPaneController.java

private void addScrollTracker() throws DEyesTrackerException {
    LOG.info("addScrollTracker() - start;");
    if (!scrollExist) {
        application.getStage().addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent evt) -> {
            if (evt.getCode().equals(KeyCode.DOWN)) {
                Platform.runLater(() -> {
                    LOG.debug("down - vvalue = {}", spText.getVvalue());
                    spText.setVvalue(spText.getVvalue() + spText.getVmax() / 10);
                });// w w  w . j a v  a 2 s. c o  m
            }
            if (evt.getCode().equals(KeyCode.UP)) {
                Platform.runLater(() -> {
                    LOG.debug("up - vvalue = {}", spText.getVvalue());
                    spText.setVvalue(spText.getVvalue() - spText.getVmax() / 10);
                });
            }
        });
        final Thread t = new Thread() {
            @Override
            public void run() {
                runEyeTracker();
            }
        };
        t.setDaemon(true);
        t.start();

        scrollExist = true;
    }
    LOG.info("addScrollTracker() - end;");
}

From source file:com.bekwam.resignator.JarsignerConfigController.java

@FXML
public void initialize() {

    if (logger.isDebugEnabled()) {
        logger.debug("[INIT] instance={}, configurationDS={}", this.hashCode(), configurationDS.hashCode());
    }/*  w ww .  j  av  a 2 s.co  m*/

    cbVerbose.getItems().addAll(Boolean.TRUE, Boolean.FALSE);

    pfStorepass.textProperty().bindBidirectional(activeProfile.jarsignerConfigStorepassProperty());
    tfKeystore.textProperty().bindBidirectional(activeProfile.jarsignerConfigKeystoreProperty());
    pfKeypass.textProperty().bindBidirectional(activeProfile.jarsignerConfigKeypassProperty());
    cbVerbose.valueProperty().bindBidirectional(activeProfile.jarsignerConfigVerboseProperty());

    lblConfKeypass.setVisible(false);
    lblConfStorepass.setVisible(false);
    lblKeystoreNotFound.setVisible(false);

    //
    // Enables ChoiceBox controls to use the arrow keys without losing focus
    //
    vbox.addEventFilter(KeyEvent.KEY_PRESSED, (evt) -> {
        if (evt.getCode() == KeyCode.UP || evt.getCode() == KeyCode.DOWN) {
            evt.consume();
        }
    });

    //
    // #7 fire action event when tfs lose focus
    //
    InvalidationListener pfConfStorepassListener = (evt) -> {
        if (!pfConfStorepass.isFocused()) {
            verifyStorepass();
        }
    };

    pfConfStorepass.focusedProperty().addListener(new WeakInvalidationListener(pfConfStorepassListener));

    InvalidationListener pfConfKeypassListener = (evt) -> {
        if (!pfConfKeypass.isFocused()) {
            verifyKeypass();
        }
    };

    pfConfKeypass.focusedProperty().addListener(new WeakInvalidationListener(pfConfKeypassListener));

    tfKeystore.textProperty().addListener(new WeakInvalidationListener(needsSaveListener));
    pfStorepass.textProperty().addListener(new WeakInvalidationListener(needsSaveListener));
    pfKeypass.textProperty().addListener(new WeakInvalidationListener(needsSaveListener));
    cbAlias.valueProperty().addListener(new WeakInvalidationListener(needsSaveListener));
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.GridViewImpl.java

@FXML
private void initialize() {
    LOGGER.debug("initializing");

    this.grid = new PaginatedImageGrid(menu);
    content.setCenter(grid);//from   w  ww. j a  v a2s  .  c  om
    menu.addListener(new MenuListener());
    organizer.setFilterChangeAction(this::handleFilterChange);

    // Selected photos are shown in the inspector.
    grid.setSelectionChangeAction(inspector::setEntities);

    // CTRL+A select all photos.
    root.setOnMouseClicked((event) -> root.requestFocus());
    root.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
        if (event.isControlDown() && event.getCode() == KeyCode.A) {
            grid.selectAll();
        }
    });

    // Updated photos that no longer match the filter are removed from the grid.
    inspector.setUpdateHandler(() -> {
        Collection<Photo> photos = inspector.getEntities();

        List<Photo> toRemove = new ArrayList<>(photos.size());
        List<Photo> toUpdate = new ArrayList<>(photos.size());

        photos.forEach(p -> {
            if (!organizer.accept(p)) {
                organizer.remove(p);
                toRemove.add(p);
            } else {
                toUpdate.add(p);
            }
        });

        grid.removePhotos(toRemove);
        grid.updatePhotos(toUpdate);
    });

    // Apply the initial filter.
    handleFilterChange();

    // subscribe to photo events
    photoService.subscribeCreate(this::handlePhotoCreated);
    photoService.subscribeUpdate(this::handlePhotoUpdated);
    photoService.subscribeDelete(this::handlePhotoDeleted);

    root.setOnDragEntered(this::handleDragEntered);
    root.setOnDragOver(this::handleDragOver);
    root.setOnDragDropped(this::handleDragDropped);
    root.setOnDragExited(this::handleDragExited);

    try {
        if (workspaceService.getDirectories().isEmpty()) {
            folderDropTarget.setVisible(true);
        }
    } catch (ServiceException ex) {
        ErrorDialog.show(root, "Fehler beim Laden der Bildordner", "");
    }
}