List of usage examples for javafx.scene.input KeyEvent KEY_TYPED
EventType KEY_TYPED
To view the source code for javafx.scene.input KeyEvent KEY_TYPED.
Click Source Link
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; }//from w ww . ja va2 s . com 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.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.jav 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:org.cryptomator.ui.controllers.SettingsController.java
@Override public void initialize() { checkForUpdatesCheckbox.setDisable(areUpdatesManagedExternally()); checkForUpdatesCheckbox.setSelected(settings.isCheckForUpdatesEnabled() && !areUpdatesManagedExternally()); portField.setText(String.valueOf(settings.getPort())); portField.addEventFilter(KeyEvent.KEY_TYPED, this::filterNumericKeyEvents); useIpv6Label.setVisible(SystemUtils.IS_OS_WINDOWS); useIpv6Checkbox.setVisible(SystemUtils.IS_OS_WINDOWS); useIpv6Checkbox.setSelected(SystemUtils.IS_OS_WINDOWS && settings.shouldUseIpv6()); versionLabel.setText(String.format(localization.getString("settings.version.label"), applicationVersion().orElse("SNAPSHOT"))); prefGvfsSchemeLabel.setVisible(SystemUtils.IS_OS_LINUX); prefGvfsScheme.setVisible(SystemUtils.IS_OS_LINUX); prefGvfsScheme.getItems().add("dav"); prefGvfsScheme.getItems().add("webdav"); prefGvfsScheme.setValue(settings.getPreferredGvfsScheme()); debugModeCheckbox.setSelected(settings.getDebugMode()); EasyBind.subscribe(checkForUpdatesCheckbox.selectedProperty(), this::checkForUpdateDidChange); EasyBind.subscribe(portField.textProperty(), this::portDidChange); EasyBind.subscribe(useIpv6Checkbox.selectedProperty(), this::useIpv6DidChange); EasyBind.subscribe(prefGvfsScheme.valueProperty(), this::prefGvfsSchemeDidChange); EasyBind.subscribe(debugModeCheckbox.selectedProperty(), this::debugModeDidChange); }
From source file:org.cryptomator.ui.controllers.UnlockController.java
@Override public void initialize() { advancedOptions.managedProperty().bind(advancedOptions.visibleProperty()); unlockButton.disableProperty().bind(passwordField.textProperty().isEmpty()); mountName.addEventFilter(KeyEvent.KEY_TYPED, this::filterAlphanumericKeyEvents); mountName.textProperty().addListener(this::mountNameDidChange); savePassword.setDisable(!keychainAccess.isPresent()); if (SystemUtils.IS_OS_WINDOWS) { winDriveLetter.setConverter(new WinDriveLetterLabelConverter()); } else {//from ww w . j av a 2 s . c o m winDriveLetterLabel.setVisible(false); winDriveLetterLabel.setManaged(false); winDriveLetter.setVisible(false); winDriveLetter.setManaged(false); } }
From source file:org.cryptomator.ui.InitializeController.java
@Override public void initialize(URL url, ResourceBundle rb) { this.localization = rb; usernameField.addEventFilter(KeyEvent.KEY_TYPED, this::filterAlphanumericKeyEvents); usernameField.textProperty().addListener(this::usernameFieldDidChange); passwordField.textProperty().addListener(this::passwordFieldDidChange); retypePasswordField.textProperty().addListener(this::retypePasswordFieldDidChange); retypePasswordField.disableProperty().addListener(new ClearOnDisableListener(retypePasswordField)); }
From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java
/** * {@inheritDoc} <br>/*from w w w .j a va 2s.co m*/ * <b>* Currently delegates the key type to the Robot </b> */ public void type(final Object graphicsComponent, char c) throws RobotException { Validate.notNull(graphicsComponent, "The graphic component must not be null"); //$NON-NLS-1$ final KeyEvent event = new KeyEvent(KeyEvent.KEY_TYPED, String.valueOf(c), StringUtils.EMPTY, null, false, false, false, false); InterceptorOptions options = new InterceptorOptions(new long[] { AWTEvent.KEY_EVENT_MASK }); IRobotEventConfirmer confirmer = m_interceptor.intercept(options); m_queuer.invokeLater("Type character", new Runnable() { //$NON-NLS-1$ @Override public void run() { final Scene scene; if (graphicsComponent instanceof Stage) { scene = ((Stage) graphicsComponent).getScene(); } else { scene = ((Node) graphicsComponent).getScene(); } Node focusOwner = scene.getFocusOwner(); EventTarget eventTarget = focusOwner != null ? focusOwner : scene; Event.fireEvent(eventTarget, event); } }); confirmer.waitToConfirm(graphicsComponent, new KeyJavaFXEventMatcher(KeyEvent.KEY_TYPED)); }