Example usage for javafx.scene.input KeyEvent KEY_RELEASED

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

Introduction

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

Prototype

EventType KEY_RELEASED

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

Click Source Link

Document

This event occurs when a key has been released.

Usage

From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java

public ClassTree(JEVisDataSource ds) {
    super();//from   www  . j  ava  2s .  c  o  m
    try {
        _ds = ds;

        _itemCache = new HashMap<>();
        _graphicCache = new HashMap<>();
        _itemChildren = new HashMap<>();

        JEVisClass root = new JEVisRootClass(ds);
        TreeItem<JEVisClass> rootItem = buildItem(root);

        setShowRoot(true);
        rootItem.setExpanded(true);

        getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        _editor.setTreeView(this);

        setCellFactory(new Callback<TreeView<JEVisClass>, TreeCell<JEVisClass>>() {

            //                @Override
            //                public TreeCell<JEVisClass> call(TreeView<JEVisClass> p) {
            //                    return new ClassCell();
            //                }
            @Override
            public TreeCell<JEVisClass> call(TreeView<JEVisClass> param) {
                return new TreeCell<JEVisClass>() {
                    //                        private ImageView imageView = new ImageView();

                    @Override
                    protected void updateItem(JEVisClass item, boolean empty) {
                        super.updateItem(item, empty);

                        if (!empty) {
                            ClassGraphic gc = getClassGraphic(item);

                            setContextMenu(gc.getContexMenu());
                            //                                setText(item);
                            setGraphic(gc.getGraphic());
                        } else {
                            setText(null);
                            setGraphic(null);
                        }
                    }
                };
            }
        });

        getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<JEVisClass>>() {

            @Override
            public void changed(ObservableValue<? extends TreeItem<JEVisClass>> ov, TreeItem<JEVisClass> t,
                    TreeItem<JEVisClass> t1) {
                try {
                    if (t1 != null) {
                        _editor.setJEVisClass(t1.getValue());
                    }
                } catch (Exception ex) {
                    System.out.println("Error while changing editor: " + ex);
                }

            }
        });

        addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {

            @Override
            public void handle(KeyEvent t) {
                if (t.getCode() == KeyCode.F2) {
                    System.out.println("F2 rename event");
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            fireEventRename();
                        }
                    });

                } else if (t.getCode() == KeyCode.DELETE) {

                    fireDelete(getSelectionModel().getSelectedItem().getValue());
                }
            }

        });

        setId("objecttree");

        getStylesheets().add("/styles/Styles.css");
        setPrefWidth(500);

        setRoot(rootItem);
        setEditable(true);

    } catch (Exception ex) {
        //            Logger.getLogger(ObjectTree.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }

}

From source file:org.openbase.display.DisplayView.java

private void init(final Stage primaryStage) throws InterruptedException, InitializationException {

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override//w  ww  .j  a v  a2  s .co m
        public void run() {
            Platform.exit();
        }
    });

    try {
        // platform configuration
        Platform.setImplicitExit(false);
        primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
        this.primaryStage = primaryStage;

        Scene scene = new Scene(cardsPane);

        // configure hide key combination
        final KeyCombination escapeKey = new KeyCodeCombination(KeyCode.ESCAPE);
        scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {

            @Override
            public void handle(KeyEvent event) {
                if (escapeKey.match(event)) {
                    try {
                        setVisible(false);
                    } catch (CouldNotPerformException ex) {
                        ExceptionPrinter.printHistory(
                                new CouldNotPerformException("Could not execute key event!", ex), logger);
                    }
                }
            }
        });

        primaryStage.setScene(scene);

        try {
            broadcastServer = new DisplayServer(this);
            broadcastServer.init(JPService.getProperty(JPBroadcastDisplayScope.class).getValue());
            broadcastServer.activate();
        } catch (JPServiceException | CouldNotPerformException ex) {
            throw new CouldNotPerformException("Could not load display server!", ex);
        }

        try {
            displayServer = new DisplayServer(this);
            displayServer.init(JPService.getProperty(JPDisplayScope.class).getValue());
            displayServer.activate();
        } catch (JPServiceException | CouldNotPerformException ex) {
            throw new CouldNotPerformException("Could not load display server!", ex);
        }
        this.htmlLoader.init(getScreen());
    } catch (CouldNotPerformException ex) {
        throw new InitializationException(this, ex);
    }
}