Example usage for javafx.scene.control TextField textProperty

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

Introduction

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

Prototype

public final StringProperty textProperty() 

Source Link

Usage

From source file:com.rcs.shoe.shop.fx.controller.ui.NewProductController.java

private void setQuantities(List<V_ProductHistory> quantities) {
    for (V_ProductHistory quantity : quantities) {
        TextField tx = quantityFields.get("text" + quantity.getSize());
        tx.textProperty().setValue(quantity.getQuantity().toString());
        Label label = quantityLabels.get("label" + quantity.getSize());
        label.textProperty().setValue(quantity.getQuantity().toString());
    }// w w  w. ja  v  a  2  s  .  co m
}

From source file:cz.lbenda.gui.tableView.FilterMenuItem.java

private FilterMenuItem(VBox panel, FilterableTableView filterableTableView,
        FilterableTableColumn filterableTableColumn) {
    super(null, panel);
    this.filterableTableView = filterableTableView;
    okCancelBar.setAlignment(Pos.BOTTOM_RIGHT);
    this.tableColumn = filterableTableColumn;
    this.getStyleClass().add("listview-menu-item");

    SortedList<Item> sortedList = new SortedList<>(filteredList, Item::compareTo);
    ListView<Item> listView = new ListView<>();
    listView.setItems(sortedList);//  www  . j a  va  2 s .  c  o  m
    listView.setCellFactory(CheckBoxListCell.forListView(Item::onProperty));

    TextField textField = new TextField();
    textField.textProperty().addListener((observable, oldValue, newValue) -> {
        filteredList.setPredicate(item -> StringUtils.isEmpty(newValue) || !StringUtils.isEmpty(item.getName())
                && item.getName().toLowerCase().contains(newValue.toLowerCase()));
    });

    prepareBars();
    prepareQuickFilter();
    prepareOkCancelBar();
    panel.getChildren().add(buttonBar);
    panel.getChildren().add(textField);
    panel.getChildren().add(listView);
    panel.getChildren().add(quickFilter);
    panel.getChildren().add(okCancelBar);

    //noinspection unchecked
    filterableTableView.sortProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue == null || (newValue != comparatorAsc && newValue != comparatorDsc)) {
            filterableTableColumn.removeRightIndicator(sortIndicator);
            sortToggleGroup.selectToggle(null);
        } else {
            filterableTableColumn.removeRightIndicator(sortIndicator);
            filterableTableColumn.addRightIndicator(sortIndicator);
            if (newValue == comparatorAsc) {
                sortIndicator.setImage(IconFactory.getInstance().image(this, ICON_SORT_ASC,
                        IconFactory.IconLocation.INDICATOR));
            } else {
                sortIndicator.setImage(IconFactory.getInstance().image(this, ICON_SORT_DSC,
                        IconFactory.IconLocation.INDICATOR));
            }
        }
    });
}

From source file:ambroafb.general.mapeditor.MapEditor.java

public MapEditor() {
    this.setEditable(true);
    itemsMap = new HashMap<>();
    delimiter = " : "; // default value of delimiter
    keyPattern = ""; // (?<![\\d-])\\d+
    valuePattern = ""; // [0-9]{1,13}(\\.[0-9]*)?
    keySpecChars = "";
    valueSpecChars = "";

    this.setCellFactory((ListView<MapEditorElement> param) -> new CustomCell());

    removeElement = (MapEditorElement elem) -> {
        if (itemsMap.containsKey(elem.getKey())) {
            itemsMap.remove(elem.getKey());
            if (getValue() != null && getValue().compare(elem) == 0) {
                getEditor().setText(delimiter);
            }//from   w  w  w.  j  a  va2s  .  c  om
            getItems().remove(elem);
        }
    };

    editElement = (MapEditorElement elem) -> {
        getSelectionModel().select(-1);
        getEditor().setText(elem.getKey() + delimiter + elem.getValue());
        itemsMap.remove(elem.getKey());
        getItems().remove(elem);
    };

    // Never hide comboBox items listView:
    this.setSkin(new ComboBoxListViewSkin(this) {
        @Override
        protected boolean isHideOnClickEnabled() {
            return false;
        }
    });

    // Control textField input.
    TextField editor = getEditor();
    editor.setText(delimiter);
    editor.textProperty()
            .addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
                if (newValue == null || newValue.isEmpty() || newValue.equals(delimiter)) {
                    editor.setText(delimiter);
                } else if (!newValue.contains(delimiter)) {
                    editor.setText(oldValue);
                } else {
                    String keyInput = StringUtils.substringBefore(newValue, delimiter).trim();
                    String valueInput = StringUtils.substringAfter(newValue, delimiter).trim();

                    if (!keyInput.isEmpty() && !Pattern.matches(keyPattern, keyInput)) {
                        keyInput = StringUtils.substringBefore(oldValue, delimiter).trim();
                    }
                    if (!valueInput.isEmpty() && !Pattern.matches(valuePattern, valueInput)) {
                        valueInput = StringUtils.substringAfter(oldValue, delimiter).trim();
                    }

                    editor.setText(keyInput + delimiter + valueInput);
                }
            });

    this.setConverter(new StringConverter<MapEditorElement>() {
        @Override
        public String toString(MapEditorElement object) {
            if (object == null) {
                return delimiter;
            }
            return object.getKey() + delimiter + object.getValue();
        }

        @Override
        public MapEditorElement fromString(String input) {
            MapEditorElement result = null;
            if (input != null && input.contains(delimiter)) {
                result = getNewInstance();
                if (result == null)
                    return null;
                String keyInput = StringUtils.substringBefore(input, delimiter).trim();
                String valueInput = StringUtils.substringAfter(input, delimiter).trim();
                if (!keyInput.isEmpty()) {
                    result.setKey(keyInput);
                }
                if (!valueInput.isEmpty()) {
                    result.setValue(valueInput);
                }
                boolean keyOutOfSpec = keySpecChars.isEmpty()
                        || !StringUtils.containsOnly(result.getKey(), keySpecChars);
                boolean valueOutOfSpec = valueSpecChars.isEmpty()
                        || !StringUtils.containsOnly(result.getValue(), valueSpecChars);
                if (!keyInput.isEmpty() && !valueInput.isEmpty() && !itemsMap.containsKey(keyInput)
                        && (keyOutOfSpec && valueOutOfSpec)) {
                    itemsMap.put(keyInput, result);
                    getItems().add(result);
                    return null;
                }
            }
            return result;
        }
    });

    // Control caret position in textField.
    editor.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
        int caretOldPos = editor.getCaretPosition();
        int delimiterIndex = editor.getText().indexOf(delimiter);
        if (event.getCode().equals(KeyCode.RIGHT)) {
            if (caretOldPos + 1 > delimiterIndex && caretOldPos + 1 <= delimiterIndex + delimiter.length()) {
                editor.positionCaret(delimiterIndex + delimiter.length());
                event.consume();
            }
        } else if (event.getCode().equals(KeyCode.LEFT)) {
            if (caretOldPos - 1 >= delimiterIndex && caretOldPos - 1 < delimiterIndex + delimiter.length()) {
                editor.positionCaret(delimiterIndex);
                event.consume();
            }
        }
    });
}

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

protected void onColumnsChanged(ListChangeListener.Change<? extends SimpleStringProperty> c) {
    while (c.next()) {
        List<? extends SimpleStringProperty> added = c.getAddedSubList();
        List<? extends SimpleStringProperty> removed = c.getRemoved();

        for (SimpleStringProperty column : added) {
            int columnIndex = columnHeaders.indexOf(column);
            addColumnConstraint();//from   w w w .  j av a2s.c  om

            TextField title = new TextField();
            title.textProperty().bindBidirectional(column);
            title.getStyleClass().add("editorViewLabel");

            MenuItem deleteColumnItem = new MenuItem(Localized.get("column.delete"));
            deleteColumnItem.setOnAction(e -> {
                columnHeaders.remove(column);
            });
            title.setContextMenu(new ContextMenu(deleteColumnItem));

            headers.add(title);
            dataContainer.add(title, columnIndex + COLUMN_OFFSET, 0);

            for (int i = 0; i < rows.size(); i++) {
                ChartRow chartRow = rows.get(i);
                SimpleStringProperty value = chartRow.getValue(columnIndex);

                TextField editor = createValueEditor(chartRow, i, columnIndex);
                editor.textProperty().bindBidirectional(value);
            }
        }
        for (SimpleStringProperty column : removed) {
            Optional<Integer> first = dataContainer.getChildren().stream()
                    .filter(n -> GridPane.getRowIndex(n) == 0).map(n -> (TextField) n)
                    .filter(t -> t.getText().equals(column.getValue())).map(t -> GridPane.getColumnIndex(t))
                    .findFirst();
            if (first.isPresent()) {
                int columnIndex = first.get();
                rows.forEach(r -> {
                    SimpleStringProperty value = r.getValue(columnIndex);
                    value.set("");
                    value.unbind();
                });
                List<Node> childrenToRemove = dataContainer.getChildren().stream()
                        .filter(n -> GridPane.getColumnIndex(n) == columnIndex).collect(Collectors.toList());
                dataContainer.getChildren().removeAll(childrenToRemove);
                dataContainer.getColumnConstraints().remove(dataContainer.getColumnConstraints().size() - 1);
            }
        }

        sortGridPane();
    }
}

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 ww w . j  a v  a2s  .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.pixida.logtest.designer.logreader.LogReaderEditor.java

private TextField createIntegerInputField(final TextField textInput, final Supplier<Integer> getter,
        final Consumer<Integer> setter) {
    final TextField integerInput = new TextField(getter.get() == null ? "" : String.valueOf(getter.get()));
    integerInput.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
        if (!newValue.matches("\\d*")) {
            integerInput.setText(newValue.replaceAll("[^\\d]", ""));
            newValue = textInput.getText();
        }/* ww  w .  j a  v a 2 s.  c  om*/
        if (StringUtils.isNotBlank(newValue)) {
            try {
                setter.accept(Integer.parseInt(newValue));
            } catch (final NumberFormatException nfe) {
                // This can only happen if the value is "too long" / too high for "int"
                integerInput.setText(String.valueOf(Integer.MAX_VALUE));
                setter.accept(Integer.MAX_VALUE);
            }
        } else {
            setter.accept(null);
        }
        this.setChanged(true);
    });
    final double maxWidthOfIntegerInput = 80d;
    integerInput.setMaxWidth(maxWidthOfIntegerInput);
    return integerInput;
}

From source file:de.pixida.logtest.designer.testrun.TestRunEditor.java

public void createLogFileSourceInputItems(final List<Triple<String, Node, String>> formItems) {
    final TextField logFilePath = new TextField();
    this.logFilePathProperty.bind(logFilePath.textProperty());
    HBox.setHgrow(logFilePath, Priority.ALWAYS);
    final Button selectLogFileButton = SelectFileButton.createButtonWithFileSelection(logFilePath,
            LogReaderEditor.LOG_FILE_ICON_NAME, "Select log file", null, null);
    final HBox fileInputConfig = new HBox(logFilePath, selectLogFileButton);
    final VBox lines = new VBox();
    final double spacingOfLines = 5d;
    lines.setSpacing(spacingOfLines);// ww w .j a va  2 s.c o m
    final HBox inputTypeLine = new HBox();
    final double hSpacingOfInputTypeChoices = 30d;
    inputTypeLine.setSpacing(hSpacingOfInputTypeChoices);
    final ToggleGroup group = new ToggleGroup();
    final RadioButton inputTypeText = new RadioButton("Paste/Enter log");
    inputTypeText.setToggleGroup(group);
    this.loadLogFromEnteredTextProperty.bind(inputTypeText.selectedProperty());
    final RadioButton inputTypeFile = new RadioButton("Read log file");
    inputTypeFile.setToggleGroup(group);
    this.loadLogFromFileProperty.bind(inputTypeFile.selectedProperty());
    inputTypeFile.setSelected(true);
    inputTypeLine.getChildren().add(inputTypeText);
    inputTypeLine.getChildren().add(inputTypeFile);
    fileInputConfig.visibleProperty().bind(inputTypeFile.selectedProperty());
    fileInputConfig.managedProperty().bind(fileInputConfig.visibleProperty());
    final TextArea logInputText = new TextArea();
    HBox.setHgrow(logInputText, Priority.ALWAYS);
    final int numLinesForEnteringLogInputManually = 10;
    logInputText.setPrefRowCount(numLinesForEnteringLogInputManually);
    logInputText.setStyle("-fx-font-family: monospace");
    this.enteredLogTextProperty.bind(logInputText.textProperty());
    final HBox enterTextConfig = new HBox();
    enterTextConfig.getChildren().add(logInputText);
    enterTextConfig.visibleProperty().bind(inputTypeText.selectedProperty());
    enterTextConfig.managedProperty().bind(enterTextConfig.visibleProperty());
    lines.getChildren().addAll(inputTypeLine, fileInputConfig, enterTextConfig);
    formItems.add(Triple.of("Trace Log", lines, null));
}

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

protected void onRowsChanged(ListChangeListener.Change<? extends ChartRow> c) {
    while (c.next()) {
        List<? extends ChartRow> addedSubList = c.getAddedSubList();

        for (ChartRow chartRow : addedSubList) {
            int rowNum = rows.indexOf(chartRow);

            TextField categoryEditor = createCategoryEditor(chartRow, rowNum);
            addRowConstraint();/* w ww  .  ja  v  a2 s  . c o m*/
            dataContainer.add(categoryEditor, 0, rowNum + ROW_OFFSET);

            for (int i = 0; i < columnHeaders.size(); i++) {
                TextField editor = createValueEditor(chartRow, rowNum, i);
                SimpleStringProperty value = chartRow.getValue(i);
                editor.textProperty().bindBidirectional(value);
            }
        }
    }
}

From source file:de.pixida.logtest.designer.testrun.TestRunEditor.java

private List<Triple<String, Node, String>> createConfigurationForm() {
    final List<Triple<String, Node, String>> formItems = new ArrayList<>();

    // Automaton file
    final TextField automatonFilePath = new TextField();
    this.automatonFilePathProperty.bind(automatonFilePath.textProperty());
    HBox.setHgrow(automatonFilePath, Priority.ALWAYS);
    final Button selectAutomatonFilePathButton = SelectFileButton.createButtonWithFileSelection(
            automatonFilePath, Editor.Type.AUTOMATON.getIconName(), "Select " + Editor.Type.AUTOMATON.getName(),
            Editor.Type.AUTOMATON.getFileMask(), Editor.Type.AUTOMATON.getFileDescription());
    final HBox automatonFilePathConfig = new HBox(automatonFilePath, selectAutomatonFilePathButton);
    formItems.add(Triple.of("Automaton", automatonFilePathConfig, null));

    // Automaton parameters
    final TextArea parametersInputText = new TextArea();
    parametersInputText.setStyle("-fx-font-family: monospace");
    HBox.setHgrow(parametersInputText, Priority.ALWAYS);
    final int parametersInputLinesSize = 4;
    parametersInputText.setPrefRowCount(parametersInputLinesSize);
    this.parametersProperty.bind(parametersInputText.textProperty());
    formItems.add(Triple.of("Parameters", parametersInputText,
            "Set parameters for the execution. Each line can contain a parameter as follows: ${PARAMETER}=value, e.g. ${TIMEOUT}=10."));

    // Log file/*  ww  w  . j a  v a  2  s .  co m*/
    this.createLogFileSourceInputItems(formItems);

    // Log reader configuration file
    final TextField logReaderConfigurationFilePath = new TextField();
    this.logReaderConfigurationFilePathProperty.bind(logReaderConfigurationFilePath.textProperty());
    HBox.setHgrow(logReaderConfigurationFilePath, Priority.ALWAYS);
    final Button selectLogReaderConfigurationFilePathButton = SelectFileButton.createButtonWithFileSelection(
            logReaderConfigurationFilePath, Editor.Type.LOG_READER_CONFIG.getIconName(),
            "Select " + Editor.Type.LOG_READER_CONFIG.getName(), Editor.Type.LOG_READER_CONFIG.getFileMask(),
            Editor.Type.LOG_READER_CONFIG.getFileDescription());
    final HBox logReaderConfigurationFilePathConfig = new HBox(logReaderConfigurationFilePath,
            selectLogReaderConfigurationFilePathButton);
    formItems.add(Triple.of("Log Reader Configuration", logReaderConfigurationFilePathConfig, null));

    // Debug output
    final CheckBox cb = new CheckBox();
    this.showDebugOutputProperty.bind(cb.selectedProperty());
    formItems.add(Triple.of("Show Debug Output", cb,
            "Show verbose debug output. Might generate lots of text and slows down the"
                    + " evaluation, but is very helpful for debugging automatons while developing them."));

    return formItems;
}

From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java

private List<Triple<String, Node, String>> createConfigurationForm() {
    final List<Triple<String, Node, String>> formItems = new ArrayList<>();

    // Headline pattern
    final TextField textInput = new TextField(this.logReader.getHeadlinePattern());
    textInput.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
        this.logReader.setHeadlinePattern(newValue);
        this.setChanged(true);
    });/*  w  ww. jav a  2s.  c  o  m*/
    textInput.setStyle("-fx-font-family: monospace");
    formItems.add(Triple.of("Headline Pattern", textInput,
            "The perl style regular expression is used to spot the beginning of"
                    + " log entries in the log file. If a log entry consists of multiple lines, this pattern must only match the first"
                    + " line, called \"head line\". Groups can intentionally be matched to spot values like timestamp or channel name."
                    + " All matching groups are removed from the payload before they are processed by an automaton."));

    // Index of timestamp
    Supplier<Integer> getter = () -> this.logReader.getHeadlinePatternIndexOfTimestamp();
    Consumer<Integer> setter = value -> this.logReader.setHeadlinePatternIndexOfTimestamp(value);
    final TextField indexOfTimestampInput = this.createIntegerInputField(textInput, getter, setter);
    formItems.add(Triple.of("Timestamp Group", indexOfTimestampInput,
            "Denotes which matching group in the headline pattern contains"
                    + " the timestamp. Index 0 references the whole pattern match, index 1 is the first matching group etc. The timestamp must"
                    + " always be a valid integer. Currently, this integer is always interpreted as milliseconds. If no value is set, no"
                    + " timestamp will be extracted and timing conditions cannot be used. If the referenced matching group is optional"
                    + " and does not match for a specific head line, the last recent timestamp will be used for the extracted log entry."));

    // Index of channel
    getter = () -> this.logReader.getHeadlinePatternIndexOfChannel();
    setter = value -> this.logReader.setHeadlinePatternIndexOfChannel(value);
    final TextField indexOfChannelInput = this.createIntegerInputField(textInput, getter, setter);
    formItems.add(Triple.of("Channel Group", indexOfChannelInput,
            "Denotes which matching group in the headline pattern contains"
                    + " the channel. If the value is empty or the matching group is optional and it did not match, the default channel is used"
                    + " for the extracted log entry."));

    // Trim payload
    CheckBox cb = new CheckBox();
    cb.setSelected(this.logReader.getTrimPayload());
    cb.selectedProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> {
        this.logReader.setTrimPayload(BooleanUtils.toBoolean(newValue));
        this.setChanged(true);
    });
    formItems.add(Triple.of("Trim Payload", cb, "Only has effect on multiline payloads."
            + " If enabled, all leading and trailing whitespaces are removed from the payload"
            + " after the matching groups are removed. This allows for regular expressions in the automaton that match the beginning"
            + " and the end of the payload, without having to take care too much for whitespaces in the source log file."));

    // Handling of non headline lines
    this.createInputForHandlingOfNonHeadlineLines(formItems);

    // Trim payload
    cb = new CheckBox();
    cb.setSelected(this.logReader.getRemoveEmptyPayloadLinesFromMultilineEntry());
    cb.selectedProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> {
        this.logReader.setRemoveEmptyPayloadLinesFromMultilineEntry(BooleanUtils.toBoolean(newValue));
        this.setChanged(true);
    });
    formItems.add(Triple.of("Remove Empty Lines", cb,
            "If enabled, empty lines will be removed from multiline payload entries."));

    // Charset
    final SortedMap<String, Charset> charsets = Charset.availableCharsets();
    final ChoiceBox<String> encodingInput = new ChoiceBox<>(
            FXCollections.observableArrayList(charsets.keySet()));
    encodingInput.getSelectionModel().select(this.logReader.getLogFileCharset().name());
    encodingInput.getSelectionModel().selectedItemProperty()
            .addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
                this.logReader.setLogFileCharset(charsets.get(newValue));
                this.setChanged(true);
            });
    formItems.add(Triple.of("Log File Encoding", encodingInput,
            "Encoding of the log file. Note that some of the encodings are"
                    + " platform specific such that reading the log on a different platform might fail. Usually, log files are written"
                    + " using UTF-8, UTF-16, ISO-8859-1 or ASCII."));

    return formItems;
}