private void initializeExpressionsSortFilterChoiceBox() { expressionSorterChoiceBox.setItems(FXCollections.observableArrayList(ExpressionSortOrder.values())); expressionSorterChoiceBox.getSelectionModel().select(expressionSortOrder); expressionSorterChoiceBox.setConverter(new StringConverter<ExpressionSortOrder>() { @Override public String toString(ExpressionSortOrder object) { return object.getDisplayName(); } @Override public ExpressionSortOrder fromString(String string) { return null; } }); expressionSorterChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ExpressionSortOrder>() { @Override public void changed(ObservableValue observable, ExpressionSortOrder oldValue, ExpressionSortOrder newValue) { expressionSortOrder = newValue; populateExpressionsListView(); } }); }
/** * Sets up the {@link ComboBox} listing all node color scheme choices. */ private void setUpNodeColorSchemeComboBox() { nodeColorScheme.setConverter(new StringConverter<Pair<String, ColorScheme>>() { @Override public String toString(final Pair<String, ColorScheme> object) { return object.getKey(); } @Override public Pair<String, ColorScheme> fromString(final String string) { return NODE_COLOR_SCHEMES.stream() .filter(pair -> pair.getKey().equals(string)) .collect(Collectors.toList()).get(0); } }); nodeColorScheme.getItems().addAll(NODE_COLOR_SCHEMES); nodeColorScheme.getSelectionModel().selectFirst(); }
private void commitEditorText(Spinner<T> spinner) { if (!spinner.isEditable()) return; try { String text = spinner.getEditor().getText(); SpinnerValueFactory<T> valueFactory = spinner.getValueFactory(); if (valueFactory != null) { StringConverter<T> converter = valueFactory.getConverter(); if (converter != null) { T value = converter.fromString(text); if (value == null) return; valueFactory.setValue(value); } } } catch (NumberFormatException e) { // Ignore text input. return; } }
private void apiVersionLine( final GridPane parent ) { final Label lineLabel = new Label( "Api Version:" ); parent.add( lineLabel, 0, 2 ); final ComboBox<ApiVersion> apiVersionBox = new ComboBox<>( FXCollections.observableArrayList( ApiVersion.values( ) ) ); apiVersionBox.converterProperty( ).setValue( new StringConverter<ApiVersion>( ) { @Override public String toString( final ApiVersion object ) { return object.getName( ); } @Override public ApiVersion fromString( final String string ) { return ApiVersion.fromName( string ); } } ); apiVersionBox.getSelectionModel( ).select( _model.getApiVersion( ) ); apiVersionBox.getSelectionModel( ).selectedItemProperty( ).addListener( ( o, oldValue, newValue ) -> _model.requestNewApiVersion( newValue ) ); lineLabel.setLabelFor( apiVersionBox ); parent.add( apiVersionBox, 1, 2 ); }
@Override public void initialize(URL location, ResourceBundle resources) { // TODO Auto-generated method stub choixSchema.getItems().add(main.getDefaultSchema()); for (Projet p : main.getProjects()) { choixSchema.getItems().add(p.getSchemaProjet()); } // change the text to make it pretty choixSchema.setConverter(new StringConverter<Schema>() { @Override public String toString(Schema object) { // TODO Auto-generated method stub return object.getName(); } @Override public Schema fromString(String string) { // TODO Auto-generated method stub return new Schema(string); } }); }
private void createMarginFields() { NumericTextField topField = new NumericTextField(); NumericTextField rightField = new NumericTextField(); NumericTextField bottomField = new NumericTextField(); NumericTextField leftField = new NumericTextField(); StringConverter<Number> converter = new NumberStringConverter(); leftField.textProperty().bindBidirectional(getSkinnable().leftMarginProperty(), converter); rightField.textProperty().bindBidirectional(getSkinnable().rightMarginProperty(), converter); topField.textProperty().bindBidirectional(getSkinnable().topMarginProperty(), converter); bottomField.textProperty().bindBidirectional(getSkinnable().bottomMarginProperty(), converter); marginsGridPane = new GridPane(); marginsGridPane.getStyleClass().add("custom-fields"); marginsGridPane.add(new Label(Messages.getString("MarginSelector.TOP")), 0, 0); marginsGridPane.add(topField, 1, 0); marginsGridPane.add(new Label(Messages.getString("MarginSelector.RIGHT")), 2, 0); marginsGridPane.add(rightField, 3, 0); marginsGridPane.add(new Label(Messages.getString("MarginSelector.BOTTOM")), 0, 1); marginsGridPane.add(bottomField, 1, 1); marginsGridPane.add(new Label(Messages.getString("MarginSelector.LEFT")), 2, 1); marginsGridPane.add(leftField, 3, 1); }
public static StringConverter<Conviction> forConvictionConverter(Translator translator) { return new StringConverter<Conviction>() { @Override public String toString(Conviction object) { if (object == null) { return ""; } return translator.getConvictionList().get(object.ordinal()); } @Override public Conviction fromString(String string) { return Conviction.valueOf(string); } }; }
public static StringConverter<Race> forRaceConverter(Translator translator) { return new StringConverter<Race>() { @Override public String toString(Race object) { if (object == null) { return ""; } return translator.getRaceList().get(object.ordinal()); } @Override public Race fromString(String string) { return Race.valueOf(string); } }; }
public static StringConverter<Profession> forProfessionConverter(Translator translator) { return new StringConverter<Profession>() { @Override public String toString(Profession object) { if (object == null) { return ""; } return translator.getProfessionList().get(object.ordinal()); } @Override public Profession fromString(String string) { return Profession.valueOf(string); } }; }
public static StringConverter<DiceHelper.AdditionType> forAdditionType(Translator translator) { return new StringConverter<AdditionType>() { @Override public String toString(AdditionType object) { if (object == null) { return ""; } return translator.getDiceAdditionProertyList().get(object.ordinal()); } @Override public AdditionType fromString(String string) { return AdditionType.valueOf(string); } }; }
public static StringConverter<MeleWeapon.MeleWeaponType> forMeleWeaponType( Translator translator) { return new StringConverter<MeleWeaponType>() { @Override public String toString(MeleWeaponType object) { if (object == null) { return ""; } return translator.getWeaponMeleTypeList().get(object.ordinal()); } @Override public MeleWeaponType fromString(String string) { return MeleWeaponType.valueOf(string); } }; }
public static StringConverter<MeleWeapon.MeleWeaponClass> forMeleWeaponClass( Translator translator) { return new StringConverter<MeleWeaponClass>() { @Override public String toString(MeleWeaponClass object) { if (object == null) { return ""; } return translator.getWeaponMeleClassList().get(object.ordinal()); } @Override public MeleWeaponClass fromString(String string) { return MeleWeaponClass.valueOf(string); } }; }
public static StringConverter<RangedWeapon.RangedWeaponType> forRangedWeaponType( Translator translator) { return new StringConverter<RangedWeaponType>() { @Override public String toString(RangedWeaponType object) { if (object == null) { return ""; } return translator.getWeaponRangedTypeList().get(object.ordinal()); } @Override public RangedWeaponType fromString(String string) { return RangedWeaponType.valueOf(string); } }; }
/** * Initializes the language ChoiceBox, retrieving all the available languages */ protected void initializeLanguageChoiceBox() { ResourceBundle i18nMessages = this.scrabble.getI18nMessages(); List<LanguageInterface> availableLanguages = Arrays.asList(new French(), new English()); this.languageChoiceBox.getItems().addAll(availableLanguages); this.languageChoiceBox.setValue(availableLanguages.get(0)); this.languageChoiceBox.setConverter(new StringConverter<LanguageInterface>() { @Override public String toString(LanguageInterface object) { return i18nMessages.getString(object.getName()); } @Override public LanguageInterface fromString(String string) { return null; } }); }
private void loadDrug() { drugs = drugGetway.allDrugs(); comboBoxDrug.getItems().addAll(drugs); comboBoxDrug.setConverter(new StringConverter<Drug>() { @Override public String toString(Drug object) { return object.getName(); } @Override public Drug fromString(String string) { return comboBoxDrug.getItems().stream().filter(ap -> ap.getName().equals(string)).findFirst().orElse(null); } }); comboBoxDrug.getSelectionModel().selectFirst(); comboBoxDrug.setOnKeyReleased((KeyEvent event) -> { drugs.forEach((drug) -> { if (String.valueOf(event.getText()).matches(Character.toString(drug.getName().charAt(0)))) { comboBoxDrug.setValue(drug); } }); }); comboBoxDrug.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends Drug> observable, Drug oldValue, Drug newValue) -> { System.out.println("Selected drug id : " + newValue.getId() + " Name : " + newValue.getName()); }); }
public CheckBoxListCell( final Callback<T, ObservableValue<Boolean>> getSelectedProperty, final BooleanProperty disableProperty, final StringConverter<T> converter ) { this.getStyleClass().add("check-box-list-cell"); setSelectedStateCallback(getSelectedProperty); setConverter(converter); checkBox = new CheckBox(); checkBox.disableProperty().bind(disableProperty); setAlignment(Pos.CENTER_LEFT); setContentDisplay(ContentDisplay.LEFT); // by default the graphic is null until the cell stops being empty setGraphic(null); }
static <T> void updateItem(final Cell<T> cell, final StringConverter<T> converter, final HBox hbox, final Node graphic, final ChoiceBox<T> choiceBox ) { if (cell.isEmpty()) { cell.setText(null); cell.setGraphic(null); } else if (cell.isEditing()) { if (choiceBox != null) { choiceBox.getSelectionModel().select(cell.getItem()); } cell.setText(null); if (graphic != null) { hbox.getChildren().setAll(graphic, choiceBox); cell.setGraphic(hbox); } else { cell.setGraphic(choiceBox); } } else { cell.setText(getItemText(cell, converter)); cell.setGraphic(graphic); } }
static <T> void updateItem(final Cell<T> cell, final StringConverter<T> converter, final HBox hbox, final Node graphic, final TextField textField ) { if (cell.isEmpty()) { cell.setText(null); cell.setGraphic(null); } else if (cell.isEditing()) { if (textField != null) { textField.setText(getItemText(cell, converter)); } cell.setText(null); if (graphic != null) { hbox.getChildren().setAll(graphic, textField); cell.setGraphic(hbox); } else { cell.setGraphic(textField); } } else { cell.setText(getItemText(cell, converter)); cell.setGraphic(graphic); } }
static <T> void startEdit(final Cell<T> cell, final StringConverter<T> converter, final HBox hbox, final Node graphic, final TextField textField ) { if (textField != null) { textField.setText(getItemText(cell, converter)); } cell.setText(null); if (graphic != null) { hbox.getChildren().setAll(graphic, textField); cell.setGraphic(hbox); } else { cell.setGraphic(textField); } textField.selectAll(); // requesting focus so that key input can immediately go into the // TextField (see RT-28132) textField.requestFocus(); }
static <T> TextField createTextField(final Cell<T> cell, final StringConverter<T> converter) { final TextField textField = new TextField(getItemText(cell, converter)); // Use onAction here rather than onKeyReleased (with check for Enter), // as otherwise we encounter RT-34685 textField.setOnAction(event -> { if (converter == null) { throw new IllegalStateException( "Attempting to convert text input into Object, but provided " + "StringConverter is null. Be sure to set a StringConverter " + "in your cell factory."); } cell.commitEdit(converter.fromString(textField.getText())); event.consume(); }); textField.setOnKeyReleased(t -> { if (t.getCode() == KeyCode.ESCAPE) { cell.cancelEdit(); t.consume(); } }); return textField; }
static <T> void updateItem(final Cell<T> cell, final StringConverter<T> converter, final HBox hbox, final Node graphic, final ComboBox<T> comboBox ) { if (cell.isEmpty()) { cell.setText(null); cell.setGraphic(null); } else if (cell.isEditing()) { if (comboBox != null) { comboBox.getSelectionModel().select(cell.getItem()); } cell.setText(null); if (graphic != null) { hbox.getChildren().setAll(graphic, comboBox); cell.setGraphic(hbox); } else { cell.setGraphic(comboBox); } } else { cell.setText(getItemText(cell, converter)); cell.setGraphic(graphic); } }
static <T> void startEdit(final Cell<T> cell, final StringConverter<T> converter, final HBox hbox, final Node graphic, final TextField textField) { if (textField != null) { textField.setText(getItemText(cell, converter)); } cell.setText(null); if (graphic != null) { hbox.getChildren().setAll(graphic, textField); cell.setGraphic(hbox); } else { cell.setGraphic(textField); } textField.selectAll(); // requesting focus so that key input can immediately go into the // TextField (see RT-28132) textField.requestFocus(); }
public static <T> void bind(TextField textField, ObjectProperty<T> value, StringConverter<T> stringConverter, Runnable onCommit) { executeOnFocusLostOrEnter(textField, () -> { T oldValue = value.get(); value.set(stringConverter.fromString(textField.getText())); textField.setText(stringConverter.toString(stringConverter.fromString(textField.getText()))); textField.positionCaret(textField.getLength()); if (onCommit != null && !Objects.equals(oldValue, value.get())) { onCommit.run(); } }); value.addListener((v, o, n) -> textField.setText(stringConverter.toString(n))); textField.setText(stringConverter.toString(value.get())); }
public KomiSpinnerFactory() { setValue(6.5); setConverter(new StringConverter<Double>() { @Override public String toString(Double object) { return object.toString(); } @Override public Double fromString(String string) { return Double.parseDouble(string); } }); }
private void initializeExpressionsChoiceFilterChoiceBox() { expressionChooserChoiceBox.setItems(FXCollections.observableArrayList(ExpressionChoiceFilter.values())); expressionChooserChoiceBox.getSelectionModel().select(expressionChoiceFilter); expressionChooserChoiceBox.setConverter(new StringConverter<ExpressionChoiceFilter>() { @Override public String toString(ExpressionChoiceFilter object) { return object.getDisplayName(); } @Override public ExpressionChoiceFilter fromString(String string) { return null; } }); expressionChooserChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ExpressionChoiceFilter>() { @Override public void changed(ObservableValue observable, ExpressionChoiceFilter oldValue, ExpressionChoiceFilter newValue) { expressionChoiceFilter = newValue; populateExpressionsListView(); } }); }
@SuppressWarnings("unchecked") private String getChoiceBoxItemText(@SuppressWarnings("rawtypes") ChoiceBox choiceBox, int index) { @SuppressWarnings("rawtypes") StringConverter converter = choiceBox.getConverter(); String text = null; if (converter == null) { text = choiceBox.getItems().get(index).toString(); } else { text = converter.toString(choiceBox.getItems().get(index)); } return stripHTMLTags(text); }
@SuppressWarnings("unchecked") @Override public String _getValue() { @SuppressWarnings("rawtypes") ChoiceBoxTableCell cell = (ChoiceBoxTableCell) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings("unchecked") @Override public String _getValue() { @SuppressWarnings("rawtypes") ChoiceBoxTreeTableCell cell = (ChoiceBoxTreeTableCell) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public String _getValue() { ChoiceBoxListCell cell = (ChoiceBoxListCell) node; StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public String _getValue() { ChoiceBoxTreeCell cell = (ChoiceBoxTreeCell) getComponent(); StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings("unchecked") @Override public String _getValue() { TextFieldListCell<?> cell = (TextFieldListCell<?>) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings("unchecked") @Override public String _getValue() { TextFieldTableCell<?, ?> cell = (TextFieldTableCell<?, ?>) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings("unchecked") @Override public String _getValue() { TextFieldTreeCell<?> cell = (TextFieldTreeCell<?>) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings("unchecked") @Override public String _getValue() { @SuppressWarnings("rawtypes") ChoiceBoxTreeCell cell = (ChoiceBoxTreeCell) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings("unchecked") @Override public String _getValue() { @SuppressWarnings("rawtypes") ChoiceBoxListCell cell = (ChoiceBoxListCell) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }
@SuppressWarnings("unchecked") @Override public String _getValue() { TextFieldTreeTableCell<?, ?> cell = (TextFieldTreeTableCell<?, ?>) node; @SuppressWarnings("rawtypes") StringConverter converter = cell.getConverter(); if (converter != null) { return converter.toString(cell.getItem()); } return cell.getItem().toString(); }