List of usage examples for javafx.scene.control TextField isFocused
public final boolean isFocused()
From source file:com.bekwam.mavenpomupdater.MenuBarDelegate.java
private TextField getFocusedTextField() { TextField[] tfs = new TextField[] { tfNewVersion, tfFilters, tfRootDir }; for (TextField tf : tfs) { if (tf.isFocused()) { return tf; }/*ww w. j a va 2 s . com*/ } return null; }
From source file:snpviewer.SnpViewer.java
public void refreshView(String chrom, boolean forceRedraw) { //if forceRedraw is false look for existing png files for each snpFile if (chrom == null) { /*if null is passed then select/reselect chromosome from * chromosomeSelector, return and let chromosomeSelector's * listener refire this method//from w ww. j a v a 2s. com */ if (chromosomeSelector.getSelectionModel().isEmpty()) { chromosomeSelector.getSelectionModel().selectFirst(); } else { int sel = chromosomeSelector.getSelectionModel().getSelectedIndex(); chromosomeSelector.getSelectionModel().clearSelection(); chromosomeSelector.getSelectionModel().select(sel); } return; } int totalFiles = affFiles.size() + unFiles.size(); if (totalFiles < 1) { return; } ArrayList<Pane> panesToAdd = new ArrayList<>(); ArrayList<ScrollPane> labelsToAdd = new ArrayList<>(); clearSplitPanes(); setProgressMode(true); nextChromMenu.setDisable(false); nextChromMenu.setDisable(false); for (final SnpFile f : affFiles) { Pane sPane = new Pane(); sPane.setMinHeight(chromSplitPane.getHeight() / totalFiles); sPane.setMinWidth(chromSplitPane.getWidth()); sPane.setVisible(true); panesToAdd.add(sPane); ScrollPane labelPane = new ScrollPane(); Label fileLabel = new Label(f.inputFile.getName() + "\n(Affected)"); fileLabel.setTextFill(Color.WHITE); labelPane.setMinHeight(labelSplitPane.getHeight() / totalFiles); labelPane.setPrefWidth(labelSplitPane.getWidth()); labelPane.minHeightProperty().bind(labelSplitPane.heightProperty().divide(totalFiles)); VBox vbox = new VBox(); vbox.setSpacing(10); vbox.getChildren().add(fileLabel); final TextField textField = new TextField(); textField.setStyle("-fx-text-fill: white; -fx-background-color: " + "rgba(90%,90%,90%,0.3); -fx-border-color:white"); textField.setPromptText("Sample Name"); if (f.getSampleName() != null) { textField.setText(f.getSampleName()); } textField.setFocusTraversable(true); textField.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode().equals(KeyCode.ENTER)) { if (!textField.getText().isEmpty()) { String name = textField.getText().trim(); if (name.length() > 0) { f.setSampleName(name); } textField.getParent().requestFocus(); saveProject(); } } } }); textField.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!textField.isFocused()) { if (!textField.getText().isEmpty()) { String name = textField.getText().trim(); if (name.length() > 0) { f.setSampleName(name); } saveProject(); } } } }); vbox.getChildren().add(textField); Label noCalls = new Label(); if (f.getPercentNoCall() != null) { noCalls.setText("No Calls: " + DecimalFormat.getInstance().format(f.getPercentNoCall()) + " %"); } else { noCalls.setText("No Calls: none"); } Label meanQual = new Label(); if (f.getMeanQuality() != null) { meanQual.setText("Av. Call Conf: " + DecimalFormat.getInstance().format(100 - (f.getMeanQuality() * 100)) + " %"); } else { meanQual.setText("No Call Confidence Data"); } vbox.getChildren().add(noCalls); vbox.getChildren().add(meanQual); labelPane.setContent(vbox); // labelPane.getChildren().add(fileLabel); // labelPane.getChildren().add(new TextField()); labelsToAdd.add(labelPane); } for (final SnpFile f : unFiles) { Pane sPane = new Pane(); sPane.setMinHeight(chromSplitPane.getHeight() / totalFiles); sPane.setMinWidth(chromSplitPane.getWidth()); sPane.setVisible(true); panesToAdd.add(sPane); ScrollPane labelPane = new ScrollPane(); Label fileLabel = new Label(f.inputFile.getName() + "\n(Unaffected)"); fileLabel.setStyle("-fx-text-fill: black"); labelPane.setMinHeight(labelSplitPane.getHeight() / totalFiles); labelPane.setPrefWidth(labelSplitPane.getWidth()); labelPane.minHeightProperty().bind(labelSplitPane.heightProperty().divide(totalFiles)); VBox vbox = new VBox(); vbox.setSpacing(10); vbox.getChildren().add(fileLabel); final TextField textField = new TextField(); textField.setStyle("-fx-text-fill: black; " + "-fx-background-color: rgba(90%,90%,90%,0.3);" + " -fx-border-color:white"); textField.setPromptText("Sample Name"); if (f.getSampleName() != null) { textField.setText(f.getSampleName()); } textField.setFocusTraversable(true); textField.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode().equals(KeyCode.ENTER)) { if (!textField.getText().isEmpty()) { f.setSampleName(textField.getText()); textField.getParent().requestFocus(); saveProject(); } } } }); textField.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!textField.isFocused()) { if (!textField.getText().isEmpty()) { f.setSampleName(textField.getText()); saveProject(); } } } }); vbox.getChildren().add(textField); Label noCalls = new Label(); if (f.getPercentNoCall() != null) { noCalls.setText("No Calls: " + DecimalFormat.getInstance().format(f.getPercentNoCall()) + " %"); } else { noCalls.setText("No Calls: none"); } Label meanQual = new Label(); if (f.getMeanQuality() != null) { meanQual.setText("Av. Call Conf: " + DecimalFormat.getInstance().format(100 - (f.getMeanQuality() * 100)) + " %"); } else { meanQual.setText("No Call Confidence Data"); } vbox.getChildren().add(noCalls); vbox.getChildren().add(meanQual); labelPane.setContent(vbox); // labelPane.getChildren().add(fileLabel); labelsToAdd.add(labelPane); } if (panesToAdd.size() > 0) { chromSplitPane.getItems().addAll(panesToAdd); labelSplitPane.getItems().addAll(labelsToAdd); ArrayList<SnpFile> bothFiles = new ArrayList<>(affFiles); bothFiles.addAll(unFiles); final Iterator<SnpFile> fileIter = bothFiles.iterator(); final Iterator<Pane> paneIter = panesToAdd.iterator(); SnpFile firstFileToProcess = fileIter.next(); Pane firstPaneToProcess = paneIter.next(); String pngPath = null; if (qualityFilter != null) { Integer percent = new Integer(100 - (int) (qualityFilter * 100)); pngPath = percent.toString(); } drawWithIterator(firstFileToProcess, firstPaneToProcess, pngPath, fileIter, paneIter, 1, totalFiles, chrom, forceRedraw, chromSplitPane); } else { setProgressMode(false); } }