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(); } }
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())); } }
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 startEdit() { super.startEdit(); textField.setText(converter.toString(getItem())); setContentDisplay(ContentDisplay.GRAPHIC_ONLY); textField.requestFocus(); }
/** * 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); }
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); } }); }
private void updateTextField() { textField.setText(converter.toString(property.getValue())); }
private String getItemText() { return getConverter().toString(getItem()); }
/************************************************************************** * * 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(); }
public ConvertingStringProperty(final Property<T> property, final StringConverter<T> converter) { this.set(converter.toString(property.getValue())); this.addListener(new ChangeListener<String>() { // TODO check performance impact @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { property.setValue(converter.fromString(newValue)); } }); }
/** * Sets the field's current value to its persistent value, thus resetting * any changes made by the user. */ public void reset() { if (!hasChanged()) { return; } userInput.setValue(stringConverter.toString((V) persistentValue.getValue())); }
/** {@inheritDoc} */ @Override protected void completeUserInput(T completion){ String newText = converter.toString(completion); getCompletionTarget().setText(newText); getCompletionTarget().positionCaret(newText.length()); }
/** * The constructor of {@code DoubleField}. * * @param valueProperty * The property that is used to store the current valid value * of the field. * @param persistentValueProperty * The property that is used to store the latest persisted * value of the field. */ protected DoubleField(SimpleDoubleProperty valueProperty, SimpleDoubleProperty persistentValueProperty) { super(valueProperty, persistentValueProperty); stringConverter = new AbstractStringConverter<Double>() { @Override public Double fromString(String string) { return Double.parseDouble(string); } }; renderer = new SimpleDoubleControl(); userInput.set(stringConverter.toString(value.getValue())); }
/** * The constructor of {@code IntegerField}. * * @param valueProperty * The property that is used to store the current valid value * of the field. * @param persistentValueProperty * The property that is used to store the latest persisted * value of the field. */ protected IntegerField(SimpleIntegerProperty valueProperty, SimpleIntegerProperty persistentValueProperty) { super(valueProperty, persistentValueProperty); stringConverter = new AbstractStringConverter<Integer>() { @Override public Integer fromString(String string) { return Integer.parseInt(string); } }; renderer = new SimpleIntegerControl(); userInput.set(stringConverter.toString(value.getValue())); }
/** * The constructor of {@code BooleanField}. * * @param valueProperty * The property that is used to store the current valid value * of the field. * @param persistentValueProperty * The property that is used to store the latest persisted * value of the field. */ protected BooleanField(SimpleBooleanProperty valueProperty, SimpleBooleanProperty persistentValueProperty) { super(valueProperty, persistentValueProperty); stringConverter = new AbstractStringConverter<Boolean>() { @Override public Boolean fromString(String string) { return Boolean.parseBoolean(string); } }; renderer = new SimpleBooleanControl(); userInput.set(stringConverter.toString(value.getValue())); }
/** * Internal constructor for the {@code DataField} class. To create new * elements, see the static factory methods in {@code Field}. * * @param valueProperty The property that is used to store the current valid value * of the field. * @param persistentValueProperty The property that is used to store the latest persisted * @see Field ::ofStringType * @see Field ::ofIntegerType * @see Field ::ofDoubleType * @see Field ::ofBooleanType */ public DateField(ObjectProperty<LocalDate> valueProperty, ObjectProperty<LocalDate> persistentValueProperty) { super(valueProperty, persistentValueProperty); Chronology chronology = Chronology.ofLocale(Locale.getDefault(Locale.Category.FORMAT)); stringConverter = new LocalDateStringConverter(FormatStyle.SHORT, null, chronology); renderer = new SimpleDateControl(); userInput.setValue(null); userInput.setValue(stringConverter.toString((LocalDate) persistentValue.getValue())); }
public Node apply(MultiSelect<E> multiSelect, E item) { SplitMenuButton button = new SplitMenuButton(); button.setText(multiSelect.getConverter().toString(item)); MenuItem remove = new MenuItem(String.format("Remove %s", item)); remove.setOnAction(event -> { int index = multiSelect.getChildrenUnmodifiable().indexOf(button); multiSelect.getItems().remove(item); multiSelect.getChildrenUnmodifiable().get(index).requestFocus(); }); button.getItems().add(remove); button.addEventFilter(KeyEvent.KEY_PRESSED, event -> { if (event.getCode() == KeyCode.BACK_SPACE) remove.getOnAction().handle(null); }); return button; } }
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())); } }
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); } }