List of usage examples for javafx.scene.input KeyCode ESCAPE
KeyCode ESCAPE
To view the source code for javafx.scene.input KeyCode ESCAPE.
Click Source Link
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 ava2 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: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 ww .j av a 2s.co m 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); }
From source file:net.sf.anathema.framework.presenter.action.about.AnathemaAboutAction.java
private void initCloseOnEscape(final Stage aboutStage) { aboutStage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.ESCAPE), new Runnable() { @Override/*from w ww .j a v a 2s. c o m*/ public void run() { closeDialog(aboutStage); } }); }
From source file:com.bekwam.mavenpomupdater.Main.java
@Override public void start(Stage primaryStage) throws Exception { ////from w w w .j a v a 2s . com // handle command line options // Application.Parameters params = getParameters(); List<String> unnamedList = params.getUnnamed(); Options options = new Options(); options.addOption("help", false, "Print this message"); options.addOption("hidpi", false, "Use high-DPI scaling"); CommandLineParser p = new BasicParser(); CommandLine cmd = p.parse(options, unnamedList.toArray(new String[0])); HelpFormatter formatter = new HelpFormatter(); if (cmd.hasOption("help")) { if (log.isDebugEnabled()) { log.debug("[START] running as help command"); } formatter.printHelp("Main", options); return; } AbstractModule module = null; if (runningAsJNLP()) { if (log.isInfoEnabled()) { log.info("using jnlp module and jnlp favorites store"); } module = new MPUJNLPModule(); } else { if (log.isInfoEnabled()) { log.info("using standalone module and in-memory favorites store"); } module = new MPUStandaloneModule(); } // // setup google guice // final Injector injector = Guice.createInjector(module); BuilderFactory builderFactory = new JavaFXBuilderFactory(); Callback<Class<?>, Object> guiceControllerFactory = clazz -> injector.getInstance(clazz); // // setup icons // primaryStage.getIcons().add(new Image("images/mpu_icon_64.png")); // // load fxml and wire controllers // FXMLLoader mainViewLoader = new FXMLLoader(getClass().getResource("mavenpomupdater.fxml"), null, builderFactory, guiceControllerFactory); Parent mainView = mainViewLoader.load(); MainViewController mainViewController = mainViewLoader.getController(); FXMLLoader alertViewLoader = new FXMLLoader(getClass().getResource("alert.fxml"), null, builderFactory, guiceControllerFactory); Parent alertView = alertViewLoader.load(); // // i'm continuing this manual wiring to 1) accommodate a potential // bi-directional reference problem and 2) to make sure that guice // doesn't return different object for the main -> alert and alert -> // main dependency injections // final AlertController alertController = alertViewLoader.getController(); mainViewController.alertController = alertController; alertController.mainViewControllerRef = new WeakReference<MainViewController>(mainViewController); // // add FlowPane, StackPane objects (defined in program and outside of // FXML) // final FlowPane fp = new FlowPane(); fp.setAlignment(Pos.CENTER); fp.getChildren().add(alertView); fp.getStyleClass().add("alert-background-pane"); final StackPane sp = new StackPane(); sp.getChildren().add(fp); // initially hide the alert sp.getChildren().add(mainView); // // setup scene // Scene scene = new Scene(sp); scene.getStylesheets().add("com/bekwam/mavenpomupdater/mpu.css"); scene.setOnKeyPressed(keyEvent -> { KeyCode key = keyEvent.getCode(); if (key == KeyCode.ESCAPE && (sp.getChildren().get(1) == fp)) { if (log.isDebugEnabled()) { log.debug("[ESCAPE]"); } alertController.action(); } }); // // setup stage // primaryStage.setTitle("Maven POM Version Updater"); primaryStage.setScene(scene); if (cmd.hasOption("hidpi")) { if (log.isInfoEnabled()) { log.info("running in Hi-DPI display mode"); } primaryStage.setWidth(2560.0); primaryStage.setHeight(1440.0); primaryStage.setMinWidth(1920.0); primaryStage.setMinHeight(1080.0); mainViewController.adjustForHiDPI(); } else { if (log.isInfoEnabled()) { log.info("running in normal display mode"); } primaryStage.setWidth(1280.0); primaryStage.setHeight(800.0); primaryStage.setMinWidth(1024.0); primaryStage.setMinHeight(768.0); } primaryStage.show(); }
From source file:com.anavationllc.o2jb.ConfigurationApp.java
private EventHandler<KeyEvent> getKeyEventHandler() { if (keyEventHandler == null) { keyEventHandler = new EventHandler<KeyEvent>() { @Override/*ww w . j av a 2 s. c om*/ 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:de.ks.text.AsciiDocEditor.java
@Override public void initialize(URL location, ResourceBundle resources) { initializePreview();//from w w w . j av a 2 s .c o m initializePopupPreview(); renderGroup = new LastExecutionGroup<>("adocrender", 500, controller.getExecutorService()); text.bindBidirectional(editor.textProperty()); editor.textProperty().addListener((p, o, n) -> { if (n != null) { renderGroup.schedule(() -> n)// .thenApplyAsync(s -> { storeBack(s); return s; }, controller.getExecutorService())// .thenAcceptAsync(s -> { if (previewTab.isSelected()) { preview.clear(); preview.showDirect(s); } else { preview.preload( Collections.singletonList(new AsciiDocContent(AsciiDocViewer.DEFAULT, s))); } if (previewPopupStage != null) { popupPreview.clear(); popupPreview.showDirect(s); } }, controller.getJavaFXExecutor()); } }); tabPane.focusedProperty().addListener((p, o, n) -> { if (n) { if (tabPane.getSelectionModel().getSelectedIndex() == 0) { if (focusOnEditor) { editor.requestFocus(); } } } else { focusOnEditor = true; } }); tabPane.getSelectionModel().selectedIndexProperty().addListener((p, o, n) -> { if (n != null && n.intValue() == 1) { controller.getJavaFXExecutor().submit(() -> preview.requestFocus()); preview.show(new AsciiDocContent(AsciiDocViewer.DEFAULT, editor.getText())); } if (o == null || n == null) { return; } if (o.intValue() != 0 && n.intValue() == 0) { controller.getJavaFXExecutor().submit(() -> editor.requestFocus()); } }); addCommands(); editor.setOnKeyPressed(e -> { KeyCode code = e.getCode(); if (code == KeyCode.S && e.isControlDown()) { saveToFile(); e.consume(); } if (e.getCode() == KeyCode.P && e.isControlDown()) { showPreviewPopup(); e.consume(); } if (e.getCode() == KeyCode.F && e.isControlDown()) { showSearchField(); e.consume(); } }); searchField.setVisible(false); searchField.setOnKeyPressed(e -> { if (e.getCode() == KeyCode.ENTER) { searchForText(); e.consume(); } }); searchField.setOnKeyReleased(e -> { if (e.getCode() == KeyCode.ESCAPE) { if (searchField.textProperty().getValueSafe().trim().isEmpty()) { searchField.setVisible(false); editor.requestFocus(); } else { searchField.setText(""); } } }); }
From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java
private void createPopup() { popup = new PopupControl() { {/*from ww w . java 2 s . c o m*/ setSkin(new Skin() { @Override public Skinnable getSkinnable() { return LookupFieldSkin.this.lookupField; } @Override public Node getNode() { return listView; } @Override public void dispose() { } }); } }; popup.setAutoHide(true); popup.setAutoFix(true); popup.setHideOnEscape(true); popup.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { popup.hide(); } }); listView.setCellFactory(new Callback() { @Override public Object call(Object p) { return new PropertyListCell(lookupField.getPropertyName()); } }); /** * Taken from * {@link com.sun.javafx.scene.control.skin.ComboBoxListViewSkin} */ listView.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { // RT-18672: Without checking if the user is clicking in the // scrollbar area of the ListView, the comboBox will hide. Therefore, // we add the check below to prevent this from happening. EventTarget target = t.getTarget(); if (target instanceof Parent) { List<String> s = ((Parent) target).getStyleClass(); if (s.contains("thumb") || s.contains("track") || s.contains("decrement-arrow") || s.contains("increment-arrow")) { return; } } needValidation = false; lookupField.setValue(listView.getSelectionModel().getSelectedItem()); popup.hide(); } }); listView.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent t) { if (t.getCode() == KeyCode.ENTER) { needValidation = false; lookupField.setValue(listView.getSelectionModel().getSelectedItem()); popup.hide(); } else if (t.getCode() == KeyCode.ESCAPE) { popup.hide(); } } }); }
From source file:com.panemu.tiwulfx.table.TableControl.java
public TableControl(Class<R> recordClass) { this.recordClass = recordClass; initControls();//from ww w. j ava 2 s . co m tblView.getSortOrder().addListener(new ListChangeListener<TableColumn<R, ?>>() { @Override public void onChanged(ListChangeListener.Change<? extends TableColumn<R, ?>> change) { reload(); } }); btnAdd.disableProperty().bind(mode.isEqualTo(Mode.EDIT)); btnEdit.disableProperty().bind(mode.isNotEqualTo(Mode.READ)); btnSave.disableProperty().bind(mode.isEqualTo(Mode.READ)); btnDelete.disableProperty().bind(new BooleanBinding() { { super.bind(mode, tblView.getSelectionModel().selectedItemProperty(), lstChangedRow); } @Override protected boolean computeValue() { if ((mode.get() == Mode.INSERT && lstChangedRow.size() < 2) || tblView.getSelectionModel().selectedItemProperty().get() == null || mode.get() == Mode.EDIT) { return true; } return false; } }); tblView.editableProperty().bind(mode.isNotEqualTo(Mode.READ)); tblView.getSelectionModel().cellSelectionEnabledProperty().bind(tblView.editableProperty()); mode.addListener(new ChangeListener<Mode>() { @Override public void changed(ObservableValue<? extends Mode> ov, Mode t, Mode t1) { if (t1 == Mode.READ) { directEdit = false; } } }); tblView.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) { lblRowIndex .setText(TiwulFXUtil.getLiteral("row.param", (page * maxResult.get() + t1.intValue() + 1))); } }); tblView.getFocusModel().focusedCellProperty().addListener(new ChangeListener<TablePosition>() { @Override public void changed(ObservableValue<? extends TablePosition> observable, TablePosition oldValue, TablePosition newValue) { if (tblView.isEditable() && directEdit && agileEditing.get()) { tblView.edit(newValue.getRow(), newValue.getTableColumn()); } } }); tblView.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.ESCAPE) { directEdit = false; } else if (event.getCode() == KeyCode.ENTER && mode.get() == Mode.READ) { getController().doubleClick(getSelectionModel().getSelectedItem()); } } }); /** * Define policy for TAB key press */ tblView.addEventFilter(KeyEvent.KEY_PRESSED, tableKeyListener); /** * In INSERT mode, only inserted row that is focusable */ tblView.getFocusModel().focusedCellProperty().addListener(tableFocusListener); tblView.setOnMouseReleased(tableRightClickListener); if (Platform.isFxApplicationThread()) { cm = new ContextMenu(); cm.setAutoHide(true); setToolTips(); /** * create custom row factory that can intercept double click on grid row */ tblView.setRowFactory(new Callback<TableView<R>, TableRow<R>>() { @Override public TableRow<R> call(TableView<R> param) { return new TableRowControl(TableControl.this); } }); } columns.addListener(new ListChangeListener<TableColumn<R, ?>>() { @Override public void onChanged(ListChangeListener.Change<? extends TableColumn<R, ?>> change) { while (change.next()) { if (change.wasAdded()) { for (TableColumn<R, ?> column : change.getAddedSubList()) { initColumn(column); } } lastColumnIndex = getLeafColumns().size() - 1; } } }); attachWindowVisibilityListener(); }
From source file:de.ks.text.AsciiDocEditor.java
@FXML void showPreviewPopup() { if (previewPopupStage == null) { String title = Localized.get("adoc.preview"); previewPopupStage = new Stage(); previewPopupStage.setTitle(title); Scene scene = new Scene(new StackPane(popupPreviewNode)); scene.setOnKeyReleased(e -> { if (e.getCode() == KeyCode.ESCAPE) { previewPopupStage.close(); }//from w ww .j a v a 2s. c om }); previewPopupStage.setScene(scene); Rectangle2D bounds = new ScreenResolver().getScreenToShow().getBounds(); previewPopupStage.setX(bounds.getMinX()); previewPopupStage.setY(bounds.getMinY()); previewPopupStage.setWidth(bounds.getWidth()); previewPopupStage.setHeight(bounds.getHeight()); previewPopupStage.initModality(Modality.NONE); previewPopupStage.setOnShowing(e -> { popupPreview.showDirect(getText()); }); previewPopupStage.setOnCloseRequest(e -> this.previewPopupStage = null); previewPopupStage.show(); } }
From source file:io.bitsquare.gui.main.overlays.Overlay.java
protected void setupKeyHandler(Scene scene) { if (!hideCloseButton) { scene.setOnKeyPressed(e -> {//from w w w. j av a 2 s . c om if (e.getCode() == KeyCode.ESCAPE || e.getCode() == KeyCode.ENTER) { e.consume(); doClose(); } }); } }