List of usage examples for javafx.scene.input KeyEvent KEY_PRESSED
EventType KEY_PRESSED
To view the source code for javafx.scene.input KeyEvent KEY_PRESSED.
Click Source Link
From source file:ijfx.ui.filter.DefaultNumberFilter.java
public DefaultNumberFilter() { try {/*from ww w . j a v a 2 s . com*/ FXUtilities.injectFXML(this); borderPane.setTop(rangeSlider); // areaChart.setCategoryGap(0); rangeSlider.setShowTickLabels(true); areaChart.setOnMouseClicked(event -> update()); rangeSlider.lowValueChangingProperty().addListener(this::onLowHighValueChanged); rangeSlider.highValueChangingProperty().addListener(this::onLowHighValueChanged); rangeSlider.lowValueProperty().addListener(this::onLowHighValueChanged); rangeSlider.highValueProperty().addListener(this::onLowHighValueChanged); categoryAxis.upperBoundProperty().bind(rangeSlider.maxProperty()); categoryAxis.lowerBoundProperty().bind(rangeSlider.minProperty()); categoryAxis.minorTickCountProperty().bind(rangeSlider.minorTickCountProperty()); categoryAxis.tickUnitProperty().bind(rangeSlider.majorTickUnitProperty()); converter.setFloatingPoint(true); converter.floatingPointNumberProperty().bind(Bindings.createIntegerBinding( this::getDisplayedFloatingPoint, rangeSlider.minProperty(), rangeSlider.maxProperty())); new TextToNumberBinding(lowTextField, rangeSlider.lowValueProperty()); new TextToNumberBinding(highTextField, rangeSlider.highValueProperty()); //Bindings.bindBidirectional(lowTextField.textProperty(), rangeSlider.lowValueProperty(), converter); //Bindings.bindBidirectional(highTextField.textProperty(), rangeSlider.highValueProperty(), converter); lowTextField.addEventFilter(KeyEvent.KEY_RELEASED, this::updatePredicate); highTextField.addEventHandler(KeyEvent.KEY_PRESSED, this::updatePredicate); rangeSlider.getStyleClass().add("range-slider"); } catch (IOException ex) { Logger.getLogger(DefaultNumberFilter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.hengyi.japp.print.client.controller.MdController.java
@FXML private void autoCompleteSapMara(KeyEvent ev) { try {//from ww w .ja va 2 s .c o m if (KeyCode.RIGHT.equals(ev.getCode())) { List<SapMara> sapMaras = md.getSapT001().autoCompleteSapMara(matnrField.getText()); sapMaraListView.setItems(observableArrayList(sapMaras)); sapMaraListView.setVisible(true); sapMaraListView.getSelectionModel().selectFirst(); } else if (KeyCode.UP.equals(ev.getCode()) || KeyCode.DOWN.equals(ev.getCode())) { sapMaraListView.fireEvent(new KeyEvent(null, sapMaraListView, KeyEvent.KEY_PRESSED, ev.getCharacter(), ev.getText(), ev.getCode(), false, false, false, false)); } else if (KeyCode.ENTER.equals(ev.getCode())) { selectSapMara(sapMaraListView.getSelectionModel().getSelectedItem()); sapMaraListView.setVisible(false); } } catch (Exception ex) { Util.alertDialog(ex); } }
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); }// ww w . j a v a 2s .co m 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:investiagenofx2.view.InvestiaGenOFXController.java
/** * Initializes the controller class.// w w w . ja v a 2 s.co m * * @param url * @param rb */ @Override public void initialize(URL url, ResourceBundle rb) { txt_investiaURL.setText(PropertiesInit.getInvestiaURL()); dtp_lastDate.setValue(LocalDate.parse(PropertiesInit.getLastGenUsedDate())); String[] clientNums = PropertiesInit.getClientNumList().split(","); for (String clientNum : clientNums) { if (!clientNum.trim().isEmpty()) { cbo_clientNum.getItems().add(clientNum.trim()); } } Arrays.fill(linkAccountToLocalAccountIndex, -1); resetControls(); cbo_clientNum.getEditor().addEventFilter(KeyEvent.KEY_PRESSED, event -> { if (event.getCode() == KeyCode.DELETE) { cbo_clientNum.getItems().remove(cbo_clientNum.getValue()); event.consume(); } }); dtp_lastDate.setConverter(new StringConverter<LocalDate>() { final String pattern = "yyyy-MM-dd"; final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern); { dtp_lastDate.setPromptText(pattern.toLowerCase()); } @Override public String toString(LocalDate date) { if (date != null) { return dateFormatter.format(date); } else { return ""; } } @Override public LocalDate fromString(String string) { if (string != null && !string.isEmpty()) { return LocalDate.parse(string, dateFormatter); } else { return null; } } }); //This deals with the bug located here where the datepicker value is not updated on focus lost //https://bugs.openjdk.java.net/browse/JDK-8092295?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel dtp_lastDate.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!newValue) { dtp_lastDate .setValue(dtp_lastDate.getConverter().fromString(dtp_lastDate.getEditor().getText())); } } }); }
From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java
@FXML public void initialize() { this.rootItem = new TreeItem<>(new TreeNode("[root]")); this.root.setRoot(this.rootItem); this.root.setCellFactory(new TreeCellFactory<>(node -> { if (node.getParent() == null) { ContextMenu export = new ContextMenu(); MenuItem exportItem = new MenuItem("Export"); export.setOnAction(e -> { File file = messageHandler.chooseFile().withInitialDirectory(new File(".")) .withTitle(Message.GENERIC_CHOOSE_EXPORT_LOCATION_JAR.format()) .withExtensionFilter(new FileFilter(Message.FILETYPE_JAVA_ARCHIVE.format(), "*.jar"), true)//from w w w. j av a 2 s .c om .promptSave(); OpenedFile openedFile = (OpenedFile) node.getMetadata().get(OpenedFile.OPENED_FILE); Map<String, byte[]> clone = new HashMap<>(openedFile.getContents()); backgroundTaskHelper.submit( new BackgroundTask(Message.TASK_SAVING_FILE.format(node.getDisplayName()), true, () -> { try { if (!file.exists()) { if (!file.createNewFile()) { throw new IOException("Could not create export file"); } } try (ZipOutputStream zipOutputStream = new ZipOutputStream( new FileOutputStream(file))) { for (Map.Entry<String, byte[]> ent : clone.entrySet()) { ZipEntry zipEntry = new ZipEntry(ent.getKey()); zipOutputStream.putNextEntry(zipEntry); zipOutputStream.write(ent.getValue()); zipOutputStream.closeEntry(); } } messageHandler.handleMessage(Message.GENERIC_EXPORTED.format()); } catch (IOException ex) { messageHandler.handleException(Message.ERROR_IOEXCEPTION_OCCURRED.format(), ex); } })); }); export.getItems().add(exportItem); return export; } return null; })); root.addEventHandler(KeyEvent.KEY_RELEASED, event -> { if (event.getCode() == KeyCode.ENTER) { TreeItem<TreeNode> selected = this.root.getSelectionModel().getSelectedItem(); if (selected != null) { if (selected.getChildren().size() != 0) { selected.setExpanded(!selected.isExpanded()); } else { getParentController().getAllFilesViewerController().handleClick(selected.getValue()); } } } }); Tooltip tooltip = new Tooltip(); StringBuilder search = new StringBuilder(); List<TreeItem<TreeNode>> searchContext = new ArrayList<>(); AtomicInteger searchIndex = new AtomicInteger(); root.focusedProperty().addListener((observable, oldValue, newValue) -> { if (!newValue) { tooltip.hide(); search.setLength(0); } }); root.boundsInLocalProperty().addListener((observable, oldValue, newValue) -> { Bounds bounds = root.localToScreen(newValue); tooltip.setAnchorX(bounds.getMinX()); tooltip.setAnchorY(bounds.getMinY()); }); root.addEventHandler(KeyEvent.KEY_PRESSED, event -> { if (tooltip.isShowing() && event.getCode() == KeyCode.UP) { if (searchIndex.decrementAndGet() < 0) { searchIndex.set(searchContext.size() - 1); } } else if (tooltip.isShowing() && event.getCode() == KeyCode.DOWN) { if (searchIndex.incrementAndGet() >= searchContext.size()) { searchIndex.set(0); } } else { return; } event.consume(); root.scrollTo(root.getRow(searchContext.get(searchIndex.get()))); root.getSelectionModel().select(searchContext.get(searchIndex.get())); }); root.addEventHandler(KeyEvent.KEY_TYPED, event -> { if (event.getCharacter().charAt(0) == '\b') { if (search.length() > 0) { search.setLength(search.length() - 1); } } else if (event.getCharacter().charAt(0) == '\u001B') { //esc tooltip.hide(); search.setLength(0); return; } else if (search.length() > 0 || (search.length() == 0 && StringUtils.isAlphanumeric(event.getCharacter()))) { search.append(event.getCharacter()); if (!tooltip.isShowing()) { tooltip.show(root.getScene().getWindow()); } } if (!tooltip.isShowing()) return; String str = search.toString(); tooltip.setText("Search for: " + str); searchContext.clear(); ArrayDeque<TreeItem<TreeNode>> deque = new ArrayDeque<>(); deque.addAll(rootItem.getChildren()); while (!deque.isEmpty()) { TreeItem<TreeNode> item = deque.poll(); if (item.getValue().getDisplayName().contains(str)) { searchContext.add(item); } if (item.isExpanded() && item.getChildren().size() > 0) deque.addAll(item.getChildren()); } searchIndex.set(0); if (searchContext.size() > 0) { root.scrollTo(root.getRow(searchContext.get(0))); root.getSelectionModel().select(searchContext.get(0)); } }); openedFileController.loadedFiles().addListener((MapChangeListener<String, OpenedFile>) change -> { if (change.getValueAdded() != null) { updateTree(change.getValueAdded()); } if (change.getValueRemoved() != null) { this.rootItem.getChildren() .removeIf(ti -> ti.getValue().equals(change.getValueRemoved().getRoot())); } }); }
From source file:boundary.GraphPane.java
private Node addThresholdSlider(float min, float max) { HBox hBox = new HBox(); hBox.setPadding(new Insets(15, 12, 15, 12)); hBox.setStyle("-fx-background-color: #66FFFF;"); Label lblThreshold = new Label("Threshold: "); lblThreshold.setPrefSize(100, 20);//from w ww.j av a 2 s . c o m Label lblValue = new Label("Value: "); lblValue.setPrefSize(50, 20); TextField tfValue = new TextField(String.valueOf(min)); Slider thresholdSlider = new Slider(); thresholdSlider.setMin(Math.floor(min)); thresholdSlider.setMax(Math.ceil(max)); thresholdSlider.setMajorTickUnit(Math.ceil((max - min) / 5)); thresholdSlider.setMinorTickCount(1); thresholdSlider.setBlockIncrement(1); thresholdSlider.setSnapToTicks(true); thresholdSlider.setShowTickMarks(true); thresholdSlider.valueProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { edgePredicate.setThreshold(newValue.floatValue()); vertexPredicate.setThreshold(newValue.floatValue()); vv.repaint(); tfValue.setText(String.format(Locale.US, "%.2f", newValue.floatValue())); } }); tfValue.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { float value; try { value = Float.parseFloat(tfValue.getText()); } catch (Exception ex) { value = 0; } edgePredicate.setThreshold(value); vertexPredicate.setThreshold(value); vv.repaint(); thresholdSlider.setValue(value); } }); Label lblSearch = new Label("Search: "); lblSearch.setPrefSize(70, 20); TextField tf = new TextField(); tf.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { String toFind = tf.getText().toLowerCase(); for (NodeInfo nodeInfo : nodesHighlighted) nodeInfo.setHighlighted(false); if (nodesHighlighted.size() > 0) { nodesHighlighted.clear(); vv.repaint(); } if (toFind.length() > 2) { for (NodeInfo nodeInfo : nodes.values()) { if (nodeInfo.getUserData().toLowerCase().contains((toFind))) { nodeInfo.setHighlighted(true); nodesHighlighted.add(nodeInfo); } } if (nodesHighlighted.size() == 1) { Layout<String, String> layout = vv.getGraphLayout(); Point2D q = layout.transform(nodesHighlighted.get(0).id); Point2D lvc = vv.getRenderContext().getMultiLayerTransformer() .inverseTransform(vv.getCenter()); final double dx = (lvc.getX() - q.getX()) / 10; final double dy = (lvc.getY() - q.getY()) / 10; Runnable animator = new Runnable() { public void run() { for (int i = 0; i < 10; i++) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT) .translate(dx, dy); try { Thread.sleep(100); } catch (InterruptedException ex) { } } } }; Thread thread = new Thread(animator); thread.start(); } vv.repaint(); } } }); hBox.getChildren().addAll(lblThreshold, thresholdSlider, lblValue, tfValue, lblSearch, tf); return hBox; }
From source file:com.panemu.tiwulfx.table.TableControl.java
public TableControl(Class<R> recordClass) { this.recordClass = recordClass; initControls();/* www . 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:acmi.l2.clientmod.l2smr.Controller.java
private void initializeKeyCombinations() { Map<KeyCombination, Runnable> keyCombinations = new HashMap<>(); keyCombinations.put(keyCombination("F1"), this::showHelp); keyCombinations.put(keyCombination("CTRL+O"), this::chooseL2Folder); keyCombinations.put(keyCombination("CTRL+M"), this::modify); keyCombinations.put(keyCombination("CTRL+E"), this::exportSM); keyCombinations.put(keyCombination("CTRL+I"), this::importSM); keyCombinations.put(keyCombination("CTRL+T"), this::exportSMT3d); getStage().getScene().addEventFilter(KeyEvent.KEY_PRESSED, event -> keyCombinations.entrySet().stream() .filter(e -> e.getKey().match(event)).findAny().ifPresent(e -> { e.getValue().run();/* w ww.j ava 2s. co m*/ event.consume(); })); }
From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java
private void initialiseAutoCompletion() { EventStream<Integer> changesEventStream = xpathExpressionArea.plainTextChanges().map(characterChanges -> { if (characterChanges.getRemoved().length() > 0) { return characterChanges.getRemovalEnd() - 1; }//from w ww . j a v a2 s. c om return characterChanges.getInsertionEnd(); }); EventStream<Integer> keyCombo = EventStreams.eventsOf(xpathExpressionArea, KeyEvent.KEY_PRESSED) .filter(key -> key.isControlDown() && key.getCode().equals(KeyCode.SPACE)) .map(searchPoint -> xpathExpressionArea.getCaretPosition()); // captured in the closure final ContextMenu autoCompletePopup = new ContextMenuWithNoArrows(); autoCompletePopup.setId("xpathAutocomplete"); autoCompletePopup.setHideOnEscape(true); EventStreams.merge(keyCombo, changesEventStream).map(searchPoint -> { int indexOfSlash = xpathExpressionArea.getText().lastIndexOf("/", searchPoint - 1) + 1; String input = xpathExpressionArea.getText(); if (searchPoint > input.length()) { searchPoint = input.length(); } input = input.substring(indexOfSlash, searchPoint); return Tuples.t(indexOfSlash, input); }).filter(t -> StringUtils.isAlpha(t._2)).subscribe(s -> autoComplete(s._1, s._2, autoCompletePopup)); }
From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java
/** * Implements the key press or release.//from w ww .j a v a 2s .com * * @param graphicsComponent * The component, may be <code>null</code> * @param keyCode * The key code * @param press * If <code>true</code>, the key is pressed, otherwise released */ private void keyPressReleaseImpl(Object graphicsComponent, int keyCode, boolean press) { InterceptorOptions options = new InterceptorOptions(new long[] { AWTEvent.KEY_EVENT_MASK }); IRobotEventConfirmer confirmer = m_interceptor.intercept(options); if (press) { m_robot.keyPress(keyCode); } else { m_robot.keyRelease(keyCode); } confirmer.waitToConfirm(graphicsComponent, new KeyJavaFXEventMatcher(press ? KeyEvent.KEY_PRESSED : KeyEvent.KEY_RELEASED)); }