Example usage for javafx.scene.control TextField setUserData

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

Introduction

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

Prototype

public void setUserData(Object value) 

Source Link

Document

Convenience method for setting a single Object property that can be retrieved at a later date.

Usage

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

private ChangeListener<Boolean> getEditorFocusListener(int rowNum, TextField editor) {
    return (p, o, n) -> {
        if (n) {//from  ww  w . jav  a 2s  .c  o m
            if (!isRowEmpty(rowNum) && rowNum + ROW_OFFSET == rows.size()) {
                rows.add(new ChartRow());
            }
            editor.setUserData(false);
        } else if (o && !n) {
            boolean edited = (Boolean) (editor.getUserData() == null ? false : editor.getUserData());
            if (edited) {
                triggerRedraw();
                editor.setUserData(false);
            }
        }
    };
}

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.j a va 2s.com*/
    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);
    });//w  w w .j a va  2s .  com

    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;
}