Search in sources :

Example 1 with TextInputControl

use of javafx.scene.control.TextInputControl in project org.csstudio.display.builder by kasemir.

the class TextEntryRepresentation method createJFXNode.

@Override
public TextInputControl createJFXNode() throws Exception {
    value_text = computeText(null);
    // Note implementation selection:
    // "multi_line" and "wrap_words" cannot change at runtime.
    // In editor, there is no visible difference,
    // and at runtime changes are simply not supported.
    final TextInputControl text;
    if (model_widget.propMultiLine().getValue()) {
        final TextArea area = new TextArea();
        area.setWrapText(model_widget.propWrapWords().getValue());
        text = area;
    } else
        text = new TextField();
    text.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
    text.getStyleClass().add("text_entry");
    if (!toolkit.isEditMode()) {
        // Initially used 'focus' to activate the widget, but
        // when a display is opened, one of the text fields likely has the focus.
        // That widget will then NOT show any value, because we're active as if the
        // user just navigated into the field to edit it.
        // Now requiring key press, including use of cursor keys, to activate.
        text.setOnKeyPressed(event -> {
            switch(event.getCode()) {
                case ESCAPE:
                    if (active) {
                        // Revert original value, leave active state
                        restore();
                        setActive(false);
                    }
                    break;
                case ENTER:
                case UNDEFINED:
                    // --> Handle in onKeyTyped for both cases
                    break;
                default:
                    // Any other key results in active state
                    setActive(true);
            }
        });
        text.setOnKeyTyped(event -> {
            final String typed = event.getCharacter();
            if (typed.length() == 1 && event.getCharacter().charAt(0) == 13) {
                // Multi line mode requires Control-ENTER.
                if (!isMultiLine() || event.isControlDown()) {
                    // Submit value, leave active state
                    submit();
                    setActive(false);
                }
            }
        });
        // Clicking into widget also activates
        text.setOnMouseClicked(event -> setActive(true));
        // While getting the focus does not activate the widget
        // (first need to type something or click),
        // _loosing_ focus de-activates the widget.
        // Otherwise widget where one moves the cursor, then clicks
        // someplace else would remain active and not show any updates
        text.focusedProperty().addListener((prop, old, focused) -> {
            if (active && !focused) {
                restore();
                setActive(false);
            }
        });
    }
    return text;
}
Also used : TextInputControl(javafx.scene.control.TextInputControl) TextArea(javafx.scene.control.TextArea) TextField(javafx.scene.control.TextField)

Example 2 with TextInputControl

use of javafx.scene.control.TextInputControl in project JFoenix by jfoenixadmin.

the class IntegerValidator method evalTextInputField.

private void evalTextInputField() {
    TextInputControl textField = (TextInputControl) srcControl.get();
    String text = textField.getText();
    try {
        hasErrors.set(false);
        if (!text.isEmpty()) {
            Integer.parseInt(text);
        }
    } catch (Exception e) {
        hasErrors.set(true);
    }
}
Also used : TextInputControl(javafx.scene.control.TextInputControl)

Example 3 with TextInputControl

use of javafx.scene.control.TextInputControl in project JFoenix by jfoenixadmin.

the class StringLengthValidator method evalTextInputField.

private void evalTextInputField() {
    TextInputControl textField = (TextInputControl) srcControl.get();
    String text = textField.getText();
    hasErrors.set(false);
    if (!text.isEmpty()) {
        if (text.length() > StringLength - 1) {
            hasErrors.set(true);
        // textField.textProperty().set(text.substring(0, 19));
        }
    }
}
Also used : TextInputControl(javafx.scene.control.TextInputControl)

Example 4 with TextInputControl

use of javafx.scene.control.TextInputControl in project dolphin-platform by canoo.

the class SimpleFormRow method createEditor.

protected Control createEditor(FormField bean) {
    try {
        Control editor = null;
        if (bean.getContentType().equals(String.class)) {
            // if (((StringFormFieldBean) bean).isMultiline()) {
            // editor = new TextArea();
            // ((TextArea) editor).setWrapText(true);
            // } else {
            editor = new TextField();
            // }
            FXBinder.bind(((TextInputControl) editor).textProperty()).bidirectionalTo(bean.valueProperty());
        } else if (bean.getContentType().equals(Boolean.class)) {
            editor = new CheckBox();
            FXBinder.bind(((CheckBox) editor).textProperty()).bidirectionalTo(bean.titleProperty());
            FXBinder.bind(((CheckBox) editor).selectedProperty()).bidirectionalTo(bean.valueProperty());
        } else if (bean.getContentType().equals(Date.class)) {
            editor = new DatePicker();
            FXBinder.bind(((DatePicker) editor).valueProperty()).bidirectionalTo(bean.valueProperty(), new BidirectionalConverter<Date, LocalDate>() {

                @Override
                public LocalDate convert(Date value) {
                    return LocalDate.from(value.toInstant());
                }

                @Override
                public Date convertBack(LocalDate value) {
                    return Date.from(Instant.from(value));
                }
            });
        }
        FXBinder.bind(editor.disableProperty()).to(bean.disabledProperty());
        Utils.registerTooltip(editor, bean);
        editor.setMaxWidth(Double.MAX_VALUE);
        editor.getStyleClass().add("simple-form-editor");
        return editor;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : TextInputControl(javafx.scene.control.TextInputControl) TextInputControl(javafx.scene.control.TextInputControl) Control(javafx.scene.control.Control) CheckBox(javafx.scene.control.CheckBox) TextField(javafx.scene.control.TextField) DatePicker(javafx.scene.control.DatePicker) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 5 with TextInputControl

use of javafx.scene.control.TextInputControl in project JFoenix by jfoenixadmin.

the class DoubleValidator method evalTextInputField.

private void evalTextInputField() {
    TextInputControl textField = (TextInputControl) srcControl.get();
    try {
        Double.parseDouble(textField.getText());
        hasErrors.set(false);
    } catch (Exception e) {
        hasErrors.set(true);
    }
}
Also used : TextInputControl(javafx.scene.control.TextInputControl)

Aggregations

TextInputControl (javafx.scene.control.TextInputControl)7 TextField (javafx.scene.control.TextField)2 ParseException (java.text.ParseException)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 CheckBox (javafx.scene.control.CheckBox)1 Control (javafx.scene.control.Control)1 DatePicker (javafx.scene.control.DatePicker)1 TextArea (javafx.scene.control.TextArea)1