List of usage examples for javafx.scene.input KeyCode UP
KeyCode UP
To view the source code for javafx.scene.input KeyCode UP.
Click Source Link
From source file:com.playonlinux.javafx.mainwindow.console.ConsoleTab.java
public ConsoleTab(CommandLineInterpreterFactory commandLineInterpreterFactory) { final VBox content = new VBox(); commandInterpreter = commandLineInterpreterFactory.createInstance(); this.setText(translate("Console")); this.setContent(content); final TextField command = new TextField(); command.getStyleClass().add("consoleCommandType"); final TextFlow console = new TextFlow(); final ScrollPane consolePane = new ScrollPane(console); content.getStyleClass().add("rightPane"); consolePane.getStyleClass().add("console"); consolePane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); content.getChildren().addAll(consolePane, command); command.requestFocus();/*from w w w . jav a 2 s .c o m*/ command.setOnKeyPressed(event -> { if (event.getCode() == KeyCode.ENTER) { final String commandToSend = command.getText(); final int cursorPosition = command.getCaretPosition(); command.setDisable(true); commandHistory.add(new CommandHistory.Item(commandToSend, cursorPosition)); Text commandText = new Text(nextSymbol + commandToSend + "\n"); commandText.getStyleClass().add("commandText"); console.getChildren().add(commandText); command.setText(""); if (commandInterpreter.sendLine(commandToSend, message -> { Platform.runLater(() -> { if (!StringUtils.isBlank(message)) { Text resultText = new Text(message); resultText.getStyleClass().add("resultText"); console.getChildren().add(resultText); } command.setDisable(false); command.requestFocus(); consolePane.setVvalue(consolePane.getVmax()); }); })) { nextSymbol = NOT_INSIDE_BLOCK; } else { nextSymbol = INSIDE_BLOCK; } } }); command.setOnKeyReleased(event -> { if (event.getCode() == KeyCode.UP) { CommandHistory.Item historyItem = commandHistory.up(); command.setText(historyItem.getCommand()); command.positionCaret(historyItem.getCursorPosition()); } else if (event.getCode() == KeyCode.DOWN) { CommandHistory.Item historyItem = commandHistory.down(); command.setText(historyItem.getCommand()); command.positionCaret(historyItem.getCursorPosition()); } }); this.setOnCloseRequest(event -> commandInterpreter.close()); }
From source file:ca.wumbo.doommanager.client.controller.ConsoleController.java
@FXML private void initialize() { textField.setOnKeyPressed(event -> { // Submit any text on enter. if (event.getCode().equals(KeyCode.ENTER)) submitLineToConsole();/*from w w w.ja v a 2 s .com*/ // If we press up/down, look for lines we stored. if (event.getCode().equals(KeyCode.UP) || event.getCode().equals(KeyCode.DOWN)) { if (commandBuffer.size() > 0) { commandBufferIndex += (event.getCode().equals(KeyCode.UP) ? -1 : 1); commandBufferIndex = Math.min(Math.max(0, commandBufferIndex), commandBuffer.size()); textField.setText(commandBufferIndex == commandBuffer.size() ? "" : commandBuffer.get(commandBufferIndex)); textField.end(); event.consume(); // Has to be consumed or else it will mess up the end() caret setting. } else { textField.setText(""); } } }); }
From source file:com.bekwam.resignator.JarsignerConfigController.java
@FXML public void initialize() { if (logger.isDebugEnabled()) { logger.debug("[INIT] instance={}, configurationDS={}", this.hashCode(), configurationDS.hashCode()); }//from w ww . ja v a 2 s . c om 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: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); });//www . ja 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.hengyi.japp.print.client.controller.MdController.java
@FXML private void autoCompleteSapMara(KeyEvent ev) { try {/*from ww w . j a v a 2s . co 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: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 ava 2 s . co m .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:jobhunter.gui.FXMLController.java
@FXML void subscriptionTableKey(KeyEvent e) { if (e.getCode() == KeyCode.UP || e.getCode() == KeyCode.DOWN) subscriptionTableClick(null); }
From source file:jobhunter.gui.FXMLController.java
@FXML void jobsListKey(KeyEvent e) { if (e.getCode() == KeyCode.UP || e.getCode() == KeyCode.DOWN) jobsListClick(null); }
From source file:com.cdd.bao.editor.EditSchema.java
private void createMenuItems() { final KeyCombination.Modifier cmd = KeyCombination.SHORTCUT_DOWN, shift = KeyCombination.SHIFT_DOWN, alt = KeyCombination.ALT_DOWN; addMenu(menuFile, "_New", new KeyCharacterCombination("N", cmd)).setOnAction(event -> actionFileNew()); addMenu(menuFile, "_Open", new KeyCharacterCombination("O", cmd)).setOnAction(event -> actionFileOpen()); addMenu(menuFile, "_Save", new KeyCharacterCombination("S", cmd)) .setOnAction(event -> actionFileSave(false)); addMenu(menuFile, "Save _As", new KeyCharacterCombination("S", cmd, shift)) .setOnAction(event -> actionFileSave(true)); addMenu(menuFile, "_Export Dump", new KeyCharacterCombination("E", cmd)) .setOnAction(event -> actionFileExportDump()); addMenu(menuFile, "_Merge", null).setOnAction(event -> actionFileMerge()); menuFile.getItems().add(new SeparatorMenuItem()); addMenu(menuFile, "Confi_gure", new KeyCharacterCombination(",", cmd)) .setOnAction(event -> actionFileConfigure()); addMenu(menuFile, "_Browse Endpoint", new KeyCharacterCombination("B", cmd, shift)) .setOnAction(event -> actionFileBrowse()); if (false) {//from w w w . j a va2 s. c om addMenu(menuFile, "_Upload Endpoint", new KeyCharacterCombination("U", cmd, shift)) .setOnAction(event -> actionFileUpload()); } Menu menuFileGraphics = new Menu("Graphics"); addMenu(menuFileGraphics, "_Template", null).setOnAction(event -> actionFileGraphicsTemplate()); addMenu(menuFileGraphics, "_Assay", null).setOnAction(event -> actionFileGraphicsAssay()); addMenu(menuFileGraphics, "_Properties", null).setOnAction(event -> actionFileGraphicsProperties()); addMenu(menuFileGraphics, "_Values", null).setOnAction(event -> actionFileGraphicsValues()); menuFile.getItems().add(menuFileGraphics); addMenu(menuFile, "Assay Stats", null).setOnAction(event -> actionFileAssayStats()); menuFile.getItems().add(new SeparatorMenuItem()); addMenu(menuFile, "_Close", new KeyCharacterCombination("W", cmd)).setOnAction(event -> actionFileClose()); addMenu(menuFile, "_Quit", new KeyCharacterCombination("Q", cmd)).setOnAction(event -> actionFileQuit()); addMenu(menuEdit, "Add _Group", new KeyCharacterCombination("G", cmd, shift)) .setOnAction(event -> actionGroupAdd()); addMenu(menuEdit, "Add _Assignment", new KeyCharacterCombination("A", cmd, shift)) .setOnAction(event -> actionAssignmentAdd()); addMenu(menuEdit, "Add Assa_y", new KeyCharacterCombination("Y", cmd, shift)) .setOnAction(event -> actionAssayAdd()); menuEdit.getItems().add(new SeparatorMenuItem()); addMenu(menuEdit, "Cu_t", new KeyCharacterCombination("X", cmd)).setOnAction(event -> actionEditCopy(true)); addMenu(menuEdit, "_Copy", new KeyCharacterCombination("C", cmd)) .setOnAction(event -> actionEditCopy(false)); Menu menuCopyAs = new Menu("Copy As"); menuEdit.getItems().add(menuCopyAs); addMenu(menuEdit, "_Paste", new KeyCharacterCombination("V", cmd)).setOnAction(event -> actionEditPaste()); menuEdit.getItems().add(new SeparatorMenuItem()); addMenu(menuEdit, "_Delete", new KeyCodeCombination(KeyCode.DELETE, cmd, shift)) .setOnAction(event -> actionEditDelete()); addMenu(menuEdit, "_Undo", new KeyCharacterCombination("Z", cmd, shift)) .setOnAction(event -> actionEditUndo()); addMenu(menuEdit, "_Redo", new KeyCharacterCombination("Z", cmd, shift, alt)) .setOnAction(event -> actionEditRedo()); menuEdit.getItems().add(new SeparatorMenuItem()); addMenu(menuEdit, "Move _Up", new KeyCharacterCombination("[", cmd)) .setOnAction(event -> actionEditMove(-1)); addMenu(menuEdit, "Move _Down", new KeyCharacterCombination("]", cmd)) .setOnAction(event -> actionEditMove(1)); addMenu(menuCopyAs, "Layout Tab-Separated", null).setOnAction(event -> actionEditCopyLayoutTSV()); addMenu(menuValue, "_Add Value", new KeyCharacterCombination("V", cmd, shift)) .setOnAction(event -> detail.actionValueAdd()); addMenu(menuValue, "Add _Multiple Values", new KeyCharacterCombination("M", cmd, shift)) .setOnAction(event -> detail.actionValueMultiAdd()); addMenu(menuValue, "_Delete Value", new KeyCodeCombination(KeyCode.DELETE, cmd)) .setOnAction(event -> detail.actionValueDelete()); addMenu(menuValue, "Move _Up", new KeyCodeCombination(KeyCode.UP, cmd)) .setOnAction(event -> detail.actionValueMove(-1)); addMenu(menuValue, "Move _Down", new KeyCodeCombination(KeyCode.DOWN, cmd)) .setOnAction(event -> detail.actionValueMove(1)); menuValue.getItems().add(new SeparatorMenuItem()); addMenu(menuValue, "_Lookup URI", new KeyCharacterCombination("U", cmd)) .setOnAction(event -> detail.actionLookupURI()); addMenu(menuValue, "Lookup _Name", new KeyCharacterCombination("L", cmd)) .setOnAction(event -> detail.actionLookupName()); menuValue.getItems().add(new SeparatorMenuItem()); addMenu(menuValue, "_Sort Values", null).setOnAction(event -> actionValueSort()); addMenu(menuValue, "_Remove Duplicates", null).setOnAction(event -> actionValueDuplicates()); addMenu(menuValue, "Cleanup Values", null).setOnAction(event -> actionValueCleanup()); (menuViewSummary = addCheckMenu(menuView, "_Summary Values", new KeyCharacterCombination("-", cmd))) .setOnAction(event -> actionViewToggleSummary()); addMenu(menuView, "_Template", new KeyCharacterCombination("1", cmd)) .setOnAction(event -> actionViewTemplate()); addMenu(menuView, "_Assays", new KeyCharacterCombination("2", cmd)) .setOnAction(event -> actionViewAssays()); addMenu(menuView, "_Derived Tree", new KeyCharacterCombination("3", cmd)) .setOnAction(event -> detail.actionShowTree()); }
From source file:snpviewer.SnpViewer.java
@Override public void initialize(URL url, ResourceBundle rb) { labelSplitPane.setDividerPositions(); chromSplitPane.setDividerPositions(); Pane lpane = (Pane) horizontalSplit.getItems().get(0); SplitPane.setResizableWithParent(lpane, false); //mnemonics/shortcuts for menus mainMenu.useSystemMenuBarProperty().set(true); fileMenu.setMnemonicParsing(true);/*from www .ja v a 2 s . co m*/ sampleMenu.setMnemonicParsing(true); goMenu.setMnemonicParsing(true); helpMenu.setMnemonicParsing(true); newProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN)); loadProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.SHORTCUT_DOWN)); addAffSampleMenu.setAccelerator( new KeyCodeCombination(KeyCode.A, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); addUnSampleMenu.setAccelerator( new KeyCodeCombination(KeyCode.U, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); nextChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.EQUALS, KeyCombination.SHORTCUT_DOWN)); prevChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, KeyCombination.SHORTCUT_DOWN)); firstChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.SHORTCUT_DOWN)); lastChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT0, KeyCombination.SHORTCUT_DOWN)); redrawMenu.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN)); cacheChromsMenu.setAccelerator( new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); saveToPngMenu.setAccelerator( new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); autoFindRegions.setAccelerator(new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN)); //need to disable hideSavedRegionsMenu accelerator for linux - doesn't work for check menus hideSavedRegionsMenu.setAccelerator( new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); clearSavedRegionsMenu.setAccelerator( new KeyCodeCombination(KeyCode.X, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); displaySavedsRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.T, KeyCombination.SHORTCUT_DOWN)); outputSavedRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN)); removeSampleMenu.setAccelerator( new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); //set radio menu item toggle group ArrayList<RadioMenuItem> callQualityRadios = new ArrayList<>( Arrays.asList(noFilteringRadio, filter99, filter95, filter90, filter85)); ToggleGroup callQualityToggle = new ToggleGroup(); for (RadioMenuItem r : callQualityRadios) { r.setToggleGroup(callQualityToggle); } noFilteringRadio.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(null); } }); filter99.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.01); } }); filter95.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.05); } }); filter90.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.10); } }); filter85.setOnAction(new EventHandler() { @Override public void handle(Event ev) { setQualityFilter(0.15); } }); nextChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { selectNextChromosome(true); } }); prevChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { selectNextChromosome(false); } }); firstChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { if (!cancelButton.isDisabled()) { cancelButton.fire(); } if (!chromosomeSelector.isDisabled()) { chromosomeSelector.getSelectionModel().selectFirst(); } } }); lastChromMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { if (!cancelButton.isDisabled()) { cancelButton.fire(); } if (!chromosomeSelector.isDisabled()) { chromosomeSelector.getSelectionModel().selectLast(); } } }); hideSavedRegionsMenu.setOnAction(new EventHandler() { @Override public void handle(Event ev) { showHideSavedRegions(); } }); colorComp.addAll(Arrays.asList(colorComponants)); //selection context menu final ContextMenu scm = new ContextMenu(); final MenuItem scmItem1 = new MenuItem("Display Flanking SNP IDs"); scmItem1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * flanking snp ids and coordinates */ displayFlankingSnpIDs(dragSelectRectangle); } }); final MenuItem scmItem2 = new MenuItem("Write Selected Region to File"); scmItem2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and report back * write SNPs in region to file */ writeRegionToFile(dragSelectRectangle); } }); } }); final MenuItem scmItem3 = new MenuItem("Add To Saved Regions"); scmItem3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * write SNPs in region to file */ saveSelection(); } }); final MenuItem scmItem4 = new MenuItem("Show/Hide Saved Regions"); scmItem4.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * write SNPs in region to file */ hideSavedRegionsMenu.selectedProperty().setValue(!hideSavedRegionsMenu.isSelected()); hideSavedRegionsMenu.fire(); } }); final MenuItem scmItem5 = new MenuItem("Zoom Region"); scmItem5.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and report back * write SNPs in region to file */ zoomRegion(dragSelectRectangle); } }); } }); final MenuItem scmItem6 = new MenuItem("Write Saved Regions to File"); scmItem6.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and report back * write SNPs in region to file */ writeSavedRegionsToFile(); } }); } }); scm.getItems().add(scmItem1); scm.getItems().add(scmItem2); scm.getItems().add(scmItem3); scm.getItems().add(scmItem4); scm.getItems().add(scmItem5); scm.getItems().add(scmItem6); //overlayPane context menu ocm = new ContextMenu(); final MenuItem ocmItem1 = new MenuItem("Save Image to File"); ocmItem1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { drawPaneToPng(); } }); } }); ocm.getItems().add(ocmItem1); ocm.getItems().add(scmItem4); ocm.getItems().add(scmItem6); //color selections colorComponantSelector.getItems().clear(); colorComponantSelector.getItems().add("AA"); colorComponantSelector.getItems().add("BB"); colorComponantSelector.getItems().add("AB"); colorComponantSelector.getItems().add("Selection Outline"); colorComponantSelector.getItems().add("Selection Fill"); colorComponantSelector.getItems().add("Saved Region Outline"); colorComponantSelector.getItems().add("Saved Region Fill"); colorComponantSelector.getSelectionModel().selectFirst(); colorPicker.setValue(colorComponants[0]); colorComponantSelector.getSelectionModel().selectedIndexProperty() .addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue ov, Number value, Number new_value) { colorPicker.setValue(colorComp.get(new_value.intValue())); colorPicker.fireEvent(new ActionEvent()); } }); colorPicker.setOnAction(new EventHandler() { @Override public void handle(Event t) { if (!colorComp.get(colorComponantSelector.getSelectionModel().getSelectedIndex()) .equals(colorPicker.getValue())) { colorComp.set(colorComponantSelector.getSelectionModel().getSelectedIndex(), colorPicker.getValue()); saveProject(); //colorComponants[colorComponantSelector.getSelectionModel().getSelectedIndex()] = colorPicker.getValue(); if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.fill.value) { dragSelectRectangle.setFill(colorPicker.getValue()); } else if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.line.value) { dragSelectRectangle.setStroke(colorPicker.getValue()); } else if (colorComponantSelector.getSelectionModel() .getSelectedIndex() == Colors.saveLine.value) { for (Rectangle r : savedRegionsDisplay) { r.setStroke(colorPicker.getValue()); } } else if (colorComponantSelector.getSelectionModel() .getSelectedIndex() == Colors.saveFill.value) { for (Rectangle r : savedRegionsDisplay) { r.setFill(colorPicker.getValue()); } } else { removeSavedChromosomeImages(); if (redrawCheckBox.isSelected()) { refreshView(null, true); } } } } }); /*perform appropriate action when user selects a chromosome * from the chromosome choice box */ chromosomeSelector.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue ov, Number value, Number new_value) { chromosomeBoxList = chromosomeSelector.getItems().toArray(); if (new_value.intValue() > -1) { chromosomeSelected((String) chromosomeBoxList[new_value.intValue()]); } } }); chromosomeSelector.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode() == KeyCode.UP) { ke.consume(); chromosomeSelector.show(); } } }); selectionOverlayPane.heightProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) { windowResized(new ActionEvent()); } }); selectionOverlayPane.widthProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) { windowResized(new ActionEvent()); } }); /*upon addition of a new affected file adjust components accordingly * i.e. ensure appropriate chromosomes are in the choice box * adjust the split panes to fit all files and redisplay */ affObserve.addListener(new ListChangeListener() { @Override public void onChanged(ListChangeListener.Change change) { change.next();/*from the javadoc * 'Go to the next change. In initial state is invalid a require * a call to next() before calling other methods. The first * next() call will make this object represent the first change. */ if (change.getRemovedSize() > 0) { List<SnpFile> both = new ArrayList<>(unFiles); both.addAll(affFiles); recheckChromosomeSelector(both);//need to check all files again, not just affFiles } else if (change.getAddedSize() > 0) { addToChromosomeSelector(affFiles); } } }); /*as above * but for unaffected files */ unObserve.addListener(new ListChangeListener() { @Override public void onChanged(ListChangeListener.Change change) { change.next(); if (change.getRemovedSize() > 0) { List<SnpFile> both = new ArrayList<>(unFiles); both.addAll(affFiles); recheckChromosomeSelector(both);//need to check all files again, not just unFiles } else if (change.getAddedSize() > 0) { addToChromosomeSelector(unFiles); } } }); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1) { try { ChromosomeLength chromLength = new ChromosomeLength(genomeVersion); String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel() .getSelectedIndex()]; double coordinate = chromLength.getLength(currentChrom) / chromSplitPane.getWidth() * e.getX(); positionIndicator.setText(nf.format(coordinate)); } catch (Exception ex) { positionIndicator.setText("Build Error!"); } } } }); /*handle mouse dragging and effect on dragSelectRectangle * */ dragSelectRectangle.widthProperty().bind(dragSelectRectX.subtract(dragSelectRectInitX)); dragSelectRectangle.heightProperty().bind(selectionOverlayPane.heightProperty()); //dragSelectRectangle.strokeProperty().set(colorComponants[Colors.line.value]); dragSelectRectangle.setStrokeWidth(4.0); //dragSelectRectangle.setBlendMode(BlendMode.SCREEN); dragSelectRectangle.setOpacity(0.45); dragSelectRectangle.setVisible(false); selectionOverlayPane.getChildren().add(dragSelectRectangle); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (scm.isShowing()) { scm.hide(); } if (!e.isPrimaryButtonDown()) { if (e.isSecondaryButtonDown()) { //check we're not overlapping selection if (e.getX() >= dragSelectRectangle.getX() && e.getX() <= (dragSelectRectangle.getX() + dragSelectRectangle.getWidth())) { return; } //check we're not overlapping saved regions for (Rectangle r : savedRegionsDisplay) { if (r.isVisible() && e.getX() >= r.getX() && e.getX() <= r.getX() + r.getWidth()) { return; } } if (chromosomeSelector.getSelectionModel().isEmpty()) { ocmItem1.setDisable(true); } else { ocmItem1.setDisable(false); } ocm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY()); return; } } if (ocm.isShowing()) { ocm.hide(); } dragSelectRectangle.strokeProperty().set(colorComp.get(Colors.line.value)); dragSelectRectangle.fillProperty().set(colorComp.get(Colors.fill.value)); dragSelectRectX.set(0); dragSelectRectangle.setVisible(true); dragSelectRectangle.setX(e.getX()); dragSelectRectangle.setY(0); dragSelectRectInitX.set(e.getX()); anchorInitX.set(e.getX()); } }); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (!e.isPrimaryButtonDown()) { return; } dragSelectRectangle.setVisible(true); if (e.getX() > anchorInitX.doubleValue()) {//dragging to the right if (e.getX() <= selectionOverlayPane.getLayoutX() + selectionOverlayPane.getWidth()) { //mouse is before the edge of the pane dragSelectRectInitX.set(anchorInitX.doubleValue()); dragSelectRectX.set(e.getX()); } else { //mouse is over the edge dragSelectRectX.set(selectionOverlayPane.getWidth()); } } else { if (e.getX() > selectionOverlayPane.getLayoutX()) { dragSelectRectInitX.set(e.getX()); dragSelectRectangle.setX(e.getX()); dragSelectRectX.set(anchorInitX.doubleValue()); } else { dragSelectRectInitX.set(0); dragSelectRectangle.setX(0); /* the two lines below are just to trigger * dragSelectRectangle.widthProperty listener * so that start coordinate changes to 1 */ dragSelectRectX.set(anchorInitX.doubleValue() + 1); dragSelectRectX.set(anchorInitX.doubleValue() + 1); } } } }); selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { //dragSelectRectX.set(e.getX()); if (!e.isPrimaryButtonDown()) { return; } dragSelectRectangle.setVisible(true); if (dragSelectRectangle.getWidth() == 0) { clearDragSelectRectangle(); } } }); dragSelectRectangle.widthProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Object oldValue, Object newRectWidth) { if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1 && dragSelectRectangle.getWidth() > 0) { try { ChromosomeLength chromLength = new ChromosomeLength(genomeVersion); String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel() .getSelectedIndex()]; double startCoordinate = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth() * dragSelectRectangle.getX(); double selectionWidth = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth() * dragSelectRectangle.getWidth(); if (dragSelectRectangle.getX() == 0) { startCoordinate = 1; } selectionIndicator.setText("chr" + currentChrom + ":" + nf.format(startCoordinate) + "-" + nf.format(startCoordinate + selectionWidth)); } catch (Exception ex) { selectionIndicator.setText("Build Error!"); } } else { selectionIndicator.setText(""); } } }); dragSelectRectangle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (e.getButton() == MouseButton.SECONDARY) { if (chromosomeSelector.getSelectionModel().isEmpty()) { scmItem1.setDisable(true); scmItem2.setDisable(true); } else { scmItem1.setDisable(false); scmItem2.setDisable(false); } if (ocm.isShowing()) { ocm.hide(); } scm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY()); } } }); }