try { final StringConverter<T> sc = control.getConverter(); final T item = sc.fromString(editor.getText()); if (item != null) { getSkinnable().getChips().add(item);
private boolean updateDisplayText(ListCell<T> cell, T item, boolean empty) { if (empty) { // create empty cell if (cell == null) { return true; } cell.setGraphic(null); cell.setText(null); return true; } else if (item instanceof Node) { Node currentNode = cell.getGraphic(); Node newNode = (Node) item; // create a node from the selected node of the listview // using JFXComboBox {@link #nodeConverterProperty() NodeConverter}) NodeConverter<T> nc = this.getNodeConverter(); Node node = nc == null ? null : nc.toNode(item); if (currentNode == null || !currentNode.equals(newNode)) { cell.setText(null); cell.setGraphic(node == null ? newNode : node); } return node == null; } else { // run item through StringConverter if it isn't null StringConverter<T> c = this.getConverter(); String s = item == null ? this.getPromptText() : (c == null ? item.toString() : c.toString(item)); cell.setText(s); cell.setGraphic(null); return s == null || s.isEmpty(); } }
setText(null); } else { setText(converter.toString(newItem)); commitEdit(this.converter.fromString(textField.getText())); }); textField.focusedProperty().addListener((obs, wasFocused, isNowFocused) -> { if (!isNowFocused) { commitEdit(this.converter.fromString(textField.getText())); textField.setText(converter.toString(getItem())); cancelEdit(); event.consume();
changed.bind(Bindings.createBooleanBinding(() -> !stringConverter.toString((V) persistentValue.getValue()).equals(userInput.getValue()), userInput, persistentValue)); value.setValue(stringConverter.fromString(newValue));
private void refreshSliderValueBinding() { sliderValue.textProperty().unbind(); if (((JFXSlider) getSkinnable()).getValueFactory() != null) { sliderValue.textProperty() .bind(((JFXSlider) getSkinnable()).getValueFactory().call((JFXSlider) getSkinnable())); } else { sliderValue.textProperty().bind(Bindings.createStringBinding(() -> { if (getSkinnable().getLabelFormatter() != null) { return getSkinnable().getLabelFormatter().toString(getSkinnable().getValue()); } else { return String.valueOf(Math.round(getSkinnable().getValue())); } }, getSkinnable().valueProperty())); } }
comboBox.getEditor().textProperty().addListener((o, oldVal, newVal) -> { linesWrapper.usePromptText.invalidate(); comboBox.setValue(getConverter().fromString(newVal)); });
public <T> void bindTextBidirectional(@Nonnull Property<T> property, @Nonnull StringConverter<T> converter) { property.setValue(converter.fromString(textField.getText())); lastChange = -1; //reset the last change to ensure updates are reflected }); textField.setText(converter.toString(property.getValue())); textField.setText(converter.toString(newValue)); }); textField.textProperty().addListener((observable, oldValue, newValue) -> property.setValue(converter.fromString(newValue))); textField.setText(converter.toString(property.getValue()));
public JFXDefaultChip(JFXChipView<T> view, T item) { super(view, item); JFXButton closeButton = new JFXButton(null, new SVGGlyph()); closeButton.getStyleClass().add("close-button"); closeButton.setOnAction((event) -> view.getChips().remove(item)); String tagString = null; if (getItem() instanceof String) { tagString = (String) getItem(); } else { tagString = view.getConverter().toString(getItem()); } Label label = new Label(tagString); label.setWrapText(true); root = new HBox(label, closeButton); getChildren().setAll(root); label.setMaxWidth(100); } }
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { converter.fromString(newValue); } });
@Override public void startEdit() { super.startEdit(); textField.setText(converter.toString(getItem())); setContentDisplay(ContentDisplay.GRAPHIC_ONLY); textField.requestFocus(); }
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { property.setValue(converter.fromString(newValue)); } });
/** * Returns whether item is matching prefix string. * * @param prefix the prefix string * @param item the item * @return true if matching */ protected boolean isItemMatching(String prefix, Object item) { @SuppressWarnings("unchecked") String itemText = itemConverter == null ? item.toString() : itemConverter.toString(item); return itemText != null && itemText.toUpperCase().startsWith(prefix); }
/** * Convert the given string to an Item by using the configured converter. * * @param text The string that the converter knows how to convert to an item */ public void addItem(String text) { StringConverter<E> c = getConverter(); if (c == null) throw new IllegalArgumentException("You must define a converter before you can add items as Strings"); E item = c.fromString(text); if (item != null) getItems().add(item); }
public ConvertingStringProperty(final T row, final StringConverter<T> converter) { this.set(converter.toString(row)); this.addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { converter.fromString(newValue); } }); }
@Override public T build() { final T component = injector.getInstance(componentClass); for (String key: componentProperties.keySet()) { final Object value = componentProperties.get(key); final String setterName = String.format("set%s%s", key.substring(0, 1).toUpperCase(), key.substring(1)); try { Method setterMethod = null; for (Method method: componentClass.getMethods()) { if (method.getName().equals(setterName)) { setterMethod = method; break; } } if (setterMethod == null) { throw new IllegalStateException(String.format("No setter for field '%s' could be found.", key)); } final StringConverter<?> stringConverter = getStringConverter(setterMethod.getParameterTypes()[0]); setterMethod.invoke(component, stringConverter.fromString((String) value)); } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e) { throw new RuntimeException(e); } } return component; }
private void updateTextField() { textField.setText(converter.toString(property.getValue())); }
/** * Writes the value from the text field to the property */ private void updateProperty() { property.setValue(converter.fromString(textField.getText())); }
private String getItemText() { return getConverter().toString(getItem()); }
default ObjectProperty<OrderType> orderTypeProperty() { final StringProperty orderType = stringPropertyOf(HasOrderType.ORDER_TYPE, () -> null); final StringConverter<OrderType> converter = new StringConverter<OrderType>() { @Override public String toString(OrderType object) { return object == null ? null : object.name(); } @Override public OrderType fromString(String string) { return string == null ? null : OrderType.valueOf(string); } }; final ObjectProperty<OrderType> object = new SimpleObjectProperty<>(converter.fromString(orderType.get())); Bindings.bindBidirectional(orderType, object, converter); return object; }
/************************************************************************** * * Implementation * **************************************************************************/ protected String buildString() { final StringBuilder sb = new StringBuilder(); for (int i = 0, max = selectedItems.size(); i < max; i++) { T item = selectedItems.get(i); if (control.getConverter() == null) { sb.append(item); } else { sb.append(control.getConverter().toString(item)); } if (i < max - 1) { sb.append(", "); //$NON-NLS-1$ } } return sb.toString(); }