Example usage for javafx.scene.control TextField focusedProperty

List of usage examples for javafx.scene.control TextField focusedProperty

Introduction

In this page you can find the example usage for javafx.scene.control TextField focusedProperty.

Prototype

public final ReadOnlyBooleanProperty focusedProperty() 

Source Link

Usage

From source file:de.ks.idnadrev.information.chart.ChartDataEditor.java

private TextField createCategoryEditor(ChartRow chartRow, int rowNum) {
    TextField categoryEditor = new TextField();
    categoryEditor.textProperty().bindBidirectional(chartRow.getCategory());

    categoryEditor.focusedProperty().addListener(getEditorFocusListener(rowNum, categoryEditor));

    categoryEditor.textProperty().addListener((p, o, n) -> {
        categoryEditor.setUserData(true);
    });//from w w w.ja v  a 2 s  .c om
    BiFunction<Integer, Integer, TextField> nextCategoryField = (row, column) -> {
        if (categoryEditors.size() > row) {
            return categoryEditors.get(row);
        } else {
            return null;
        }
    };
    BiConsumer<Integer, Integer> clipBoardHandler = (row, col) -> {
        String string = Clipboard.getSystemClipboard().getString();
        if (StringUtils.containsWhitespace(string)) {
            List<String> datas = Arrays.asList(StringUtils.split(string, "\n"));
            int missingRows = (row + datas.size()) - rows.size();
            if (missingRows > 0) {
                for (int i = 0; i < missingRows; i++) {
                    rows.add(new ChartRow());
                }
            }
            for (int i = row; i < row + datas.size(); i++) {
                ChartRow currentChartRow = rows.get(i);
                String data = datas.get(i - row);
                currentChartRow.setCategory(data);
            }
        }
    };
    categoryEditor.setOnKeyReleased(getInputKeyHandler(rowNum, -1, nextCategoryField, clipBoardHandler));

    validationRegistry.registerValidator(categoryEditor, (control, value) -> {
        if (value != null) {
            Set<String> values = categoryEditors.stream()//
                    .filter(e -> e != categoryEditor)//
                    .map(e -> e.textProperty().getValueSafe())//
                    .filter(v -> !v.isEmpty())//
                    .collect(Collectors.toSet());
            if (values.contains(value)) {
                ValidationMessage message = new ValidationMessage("validation.noDuplicates", control, value);
                return ValidationResult.fromMessages(message);
            }
        }
        return null;
    });
    categoryEditors.add(categoryEditor);
    return categoryEditor;
}

From source file:de.ks.idnadrev.information.chart.ChartDataEditor.java

protected TextField createValueEditor(ChartRow chartRow, int rowNum, int column) {
    TextField editor = new TextField();
    valueEditors.put(rowNum, column, editor);
    validationRegistry.registerValidator(editor, new DoubleValidator());
    dataContainer.add(editor, column + COLUMN_OFFSET, rowNum + ROW_OFFSET);

    editor.focusedProperty().addListener(getEditorFocusListener(rowNum, editor));

    editor.textProperty().addListener((p, o, n) -> {
        editor.setUserData(true);/*from  w ww.  j av  a  2  s. c o m*/
    });

    BiFunction<Integer, Integer, TextField> nextTextField = (row, col) -> valueEditors.row(row).get(col);
    BiConsumer<Integer, Integer> clipBoardHandler = (row, col) -> {
        String string = Clipboard.getSystemClipboard().getString();
        if (StringUtils.containsWhitespace(string)) {
            List<String> datas = Arrays.asList(StringUtils.split(string));
            int missingRows = (row + datas.size()) - rows.size();
            if (missingRows > 0) {
                for (int i = 0; i < missingRows; i++) {
                    rows.add(new ChartRow());
                }
            }
            for (int i = row; i < row + datas.size(); i++) {
                ChartRow currentChartRow = rows.get(i);
                String data = datas.get(i - row);
                currentChartRow.setValue(column, data);
            }
        }
    };
    editor.setOnKeyReleased(getInputKeyHandler(rowNum, column, nextTextField, clipBoardHandler));
    return editor;
}

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 w  w .j ava 2 s. co  m*/
         */
        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);
    }
}