List of usage examples for javafx.util StringConverter StringConverter
StringConverter
From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java
public void createInputForHandlingOfNonHeadlineLines(final List<Triple<String, Node, String>> formItems) { final Map<HandlingOfNonHeadlineLines, String> mapValueToChoice = new HashMap<>(); mapValueToChoice.put(HandlingOfNonHeadlineLines.FAIL, "Abort - Each line in the log file is assumed to be a log entry"); mapValueToChoice.put(HandlingOfNonHeadlineLines.CREATE_MULTILINE_ENTRY, "Append to payload - This will create multiline payloads"); mapValueToChoice.put(HandlingOfNonHeadlineLines.ASSUME_LAST_TIMESTAMP, "Create new log entry and use timestamp of recent log entry"); mapValueToChoice.put(HandlingOfNonHeadlineLines.ASSUME_LAST_TIMESTAMP_AND_CHANNEL, "Create new log entry and use timestamp and channel of recent log entry"); final ChoiceBox<HandlingOfNonHeadlineLines> handlingOfNonHeadlineLinesInput = new ChoiceBox<>( FXCollections.observableArrayList(HandlingOfNonHeadlineLines.values())); handlingOfNonHeadlineLinesInput.setConverter(new StringConverter<HandlingOfNonHeadlineLines>() { @Override//from w w w . j a v a2 s .co m public String toString(final HandlingOfNonHeadlineLines object) { return mapValueToChoice.get(object); } @Override public HandlingOfNonHeadlineLines fromString(final String string) { for (final Entry<HandlingOfNonHeadlineLines, String> entry : mapValueToChoice.entrySet()) { if (entry.getValue() == string) // Intentionally comparing references to obtain a bijection { return entry.getKey(); } } return null; // Should never happen } }); handlingOfNonHeadlineLinesInput.getSelectionModel().select(this.logReader.getHandlingOfNonHeadlineLines()); handlingOfNonHeadlineLinesInput.getSelectionModel().selectedIndexProperty() .addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> { this.logReader.setHandlingOfNonHeadlineLines( handlingOfNonHeadlineLinesInput.getItems().get(newValue.intValue())); this.setChanged(true); }); formItems.add(Triple.of("Dangling Lines", handlingOfNonHeadlineLinesInput, "Define what to do if dangling lines are spotted. Dangling lines are lines which do not match the headline pattern, i.e." + " which do not introduce a new log entry.")); }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java
private void initializePathComboBox() { pathComboBox.setCellFactory((param) -> { final ListCell<UUID> cell = new ListCell<UUID>() { @Override//ww w .j a va 2 s . c o m protected void updateItem(UUID c, boolean emptyRow) { super.updateItem(c, emptyRow); if (c == null) { setText(null); } else { String desc = OTFUtility.getDescription(c, panelViewCoordinate); setText(desc); } } }; return cell; }); pathComboBox.setButtonCell(new ListCell<UUID>() { @Override protected void updateItem(UUID c, boolean emptyRow) { super.updateItem(c, emptyRow); if (emptyRow) { setText(""); } else { String desc = OTFUtility.getDescription(c, panelViewCoordinate); // log.debug("Setting path button cell to \"" + desc + "\""); setText(desc); } } }); pathComboBox.setConverter(new StringConverter<UUID>() { @Override public String toString(UUID uuid) { if (uuid == null) { return null; } else { return OTFUtility.getDescription(uuid, panelViewCoordinate); } } @Override public UUID fromString(String userId) { return null; } }); currentPathProperty.bind(pathComboBox.getSelectionModel().selectedItemProperty()); }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java
private void initializeSelectableModuleListView() { allModulesMarker.selectedProperty().set(true); // default only. may be changed in getContent() selectableModuleListView.setCellFactory(CheckBoxListCell.forListView(SelectableModule::selectedProperty, new StringConverter<SelectableModule>() { @Override//from w ww.j av a 2 s.c om public String toString(SelectableModule object) { return object.getDescription(); } @Override public SelectableModule fromString(String string) { return null; } })); selectableModuleListView.setTooltip(new Tooltip( "Select one or more modules to enable filtering for selected modules\nor deselect all to disable filtering by module.\nDefault module list is " + Arrays.toString(getDefaultModules().toArray(new UUID[getDefaultModules().size()])))); }
From source file:gov.va.isaac.gui.refexViews.refexEdit.AddSememePopup.java
private void buildDataFields(boolean assemblageValid, DynamicSememeDataBI[] currentValues) { if (assemblageValid) { for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) { allValid_.removeBinding(ssp); }//from ww w . j ava 2 s . co m currentDataFieldWarnings_.clear(); for (SememeGUIDataTypeNodeDetails nd : currentDataFields_) { nd.cleanupListener(); } currentDataFields_.clear(); GridPane gp = new GridPane(); gp.setHgap(10.0); gp.setVgap(10.0); gp.setStyle("-fx-padding: 5;"); int row = 0; boolean extraInfoColumnIsRequired = false; for (DynamicSememeColumnInfo ci : assemblageInfo_.getColumnInfo()) { SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("") : null); SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null && ci.getValidator() == null) ? null : new SimpleStringProperty()); ComboBox<DynamicSememeDataType> polymorphicType = null; Label l = new Label(ci.getColumnName()); l.getStyleClass().add("boldLabel"); l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l)); Tooltip.install(l, new Tooltip(ci.getColumnDescription())); int col = 0; gp.add(l, col++, row); if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) { polymorphicType = new ComboBox<>(); polymorphicType.setEditable(false); polymorphicType.setConverter(new StringConverter<DynamicSememeDataType>() { @Override public String toString(DynamicSememeDataType object) { return object.getDisplayName(); } @Override public DynamicSememeDataType fromString(String string) { throw new RuntimeException("unecessary"); } }); for (DynamicSememeDataType type : DynamicSememeDataType.values()) { if (type == DynamicSememeDataType.POLYMORPHIC || type == DynamicSememeDataType.UNKNOWN) { continue; } else { polymorphicType.getItems().add(type); } } polymorphicType.getSelectionModel() .select((currentValues == null ? DynamicSememeDataType.STRING : (currentValues[row] == null ? DynamicSememeDataType.STRING : currentValues[row].getDynamicSememeDataType()))); } SememeGUIDataTypeNodeDetails nd = SememeGUIDataTypeFXNodeBuilder.buildNodeForType( ci.getColumnDataType(), ci.getDefaultColumnValue(), (currentValues == null ? null : currentValues[row]), valueIsRequired, defaultValueTooltip, (polymorphicType == null ? null : polymorphicType.getSelectionModel().selectedItemProperty()), allValid_, ci.getValidator(), ci.getValidatorData()); currentDataFieldWarnings_.addAll(nd.getBoundToAllValid()); if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) { nd.addUpdateParentListListener(currentDataFieldWarnings_); } currentDataFields_.add(nd); gp.add(nd.getNodeForDisplay(), col++, row); Label colType = new Label(ci.getColumnDataType().getDisplayName()); colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType)); gp.add((polymorphicType == null ? colType : polymorphicType), col++, row); if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) { extraInfoColumnIsRequired = true; StackPane stackPane = new StackPane(); stackPane.setMaxWidth(Double.MAX_VALUE); if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) { ImageView information = Images.INFORMATION.createImageView(); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(defaultValueTooltip); Tooltip.install(information, tooltip); tooltip.setAutoHide(true); information.setOnMouseClicked( event -> tooltip.show(information, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(information); } if (ci.isColumnRequired()) { ImageView exclamation = Images.EXCLAMATION.createImageView(); final BooleanProperty showExclamation = new SimpleBooleanProperty( StringUtils.isNotBlank(valueIsRequired.get())); valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue, newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue))); exclamation.visibleProperty().bind(showExclamation); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(valueIsRequired); Tooltip.install(exclamation, tooltip); tooltip.setAutoHide(true); exclamation.setOnMouseClicked( event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(exclamation); } gp.add(stackPane, col++, row); } row++; } ColumnConstraints cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.ALWAYS); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); if (extraInfoColumnIsRequired) { cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); } if (row == 0) { sp_.setContent(new Label("This assemblage does not allow data fields")); } else { sp_.setContent(gp); } allValid_.invalidate(); } else { sp_.setContent(null); } }
From source file:gov.va.isaac.gui.refexViews.refexEdit.AddRefexPopup.java
private void buildDataFields(boolean assemblageValid, RefexDynamicDataBI[] currentValues) { if (assemblageValid) { for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) { allValid_.removeBinding(ssp); }//from w w w .j a v a2s .c o m currentDataFieldWarnings_.clear(); for (RefexDataTypeNodeDetails nd : currentDataFields_) { nd.cleanupListener(); } currentDataFields_.clear(); GridPane gp = new GridPane(); gp.setHgap(10.0); gp.setVgap(10.0); gp.setStyle("-fx-padding: 5;"); int row = 0; boolean extraInfoColumnIsRequired = false; for (RefexDynamicColumnInfo ci : assemblageInfo_.getColumnInfo()) { SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("") : null); SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null && ci.getValidator() == null) ? null : new SimpleStringProperty()); ComboBox<RefexDynamicDataType> polymorphicType = null; Label l = new Label(ci.getColumnName()); l.getStyleClass().add("boldLabel"); l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l)); Tooltip.install(l, new Tooltip(ci.getColumnDescription())); int col = 0; gp.add(l, col++, row); if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) { polymorphicType = new ComboBox<>(); polymorphicType.setEditable(false); polymorphicType.setConverter(new StringConverter<RefexDynamicDataType>() { @Override public String toString(RefexDynamicDataType object) { return object.getDisplayName(); } @Override public RefexDynamicDataType fromString(String string) { throw new RuntimeException("unecessary"); } }); for (RefexDynamicDataType type : RefexDynamicDataType.values()) { if (type == RefexDynamicDataType.POLYMORPHIC || type == RefexDynamicDataType.UNKNOWN) { continue; } else { polymorphicType.getItems().add(type); } } polymorphicType.getSelectionModel() .select((currentValues == null ? RefexDynamicDataType.STRING : (currentValues[row] == null ? RefexDynamicDataType.STRING : currentValues[row].getRefexDataType()))); } RefexDataTypeNodeDetails nd = RefexDataTypeFXNodeBuilder.buildNodeForType(ci.getColumnDataType(), ci.getDefaultColumnValue(), (currentValues == null ? null : currentValues[row]), valueIsRequired, defaultValueTooltip, (polymorphicType == null ? null : polymorphicType.getSelectionModel().selectedItemProperty()), allValid_, new SimpleObjectProperty<>(ci.getValidator()), new SimpleObjectProperty<>(ci.getValidatorData())); currentDataFieldWarnings_.addAll(nd.getBoundToAllValid()); if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) { nd.addUpdateParentListListener(currentDataFieldWarnings_); } currentDataFields_.add(nd); gp.add(nd.getNodeForDisplay(), col++, row); Label colType = new Label(ci.getColumnDataType().getDisplayName()); colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType)); gp.add((polymorphicType == null ? colType : polymorphicType), col++, row); if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) { extraInfoColumnIsRequired = true; StackPane stackPane = new StackPane(); stackPane.setMaxWidth(Double.MAX_VALUE); if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) { ImageView information = Images.INFORMATION.createImageView(); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(defaultValueTooltip); Tooltip.install(information, tooltip); tooltip.setAutoHide(true); information.setOnMouseClicked( event -> tooltip.show(information, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(information); } if (ci.isColumnRequired()) { ImageView exclamation = Images.EXCLAMATION.createImageView(); final BooleanProperty showExclamation = new SimpleBooleanProperty( StringUtils.isNotBlank(valueIsRequired.get())); valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue, newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue))); exclamation.visibleProperty().bind(showExclamation); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(valueIsRequired); Tooltip.install(exclamation, tooltip); tooltip.setAutoHide(true); exclamation.setOnMouseClicked( event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(exclamation); } gp.add(stackPane, col++, row); } row++; } ColumnConstraints cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.ALWAYS); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); if (extraInfoColumnIsRequired) { cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); } if (row == 0) { sp_.setContent(new Label("This assemblage does not allow data fields")); } else { sp_.setContent(gp); } allValid_.invalidate(); } else { sp_.setContent(null); } }
From source file:net.sourceforge.pmd.util.fxdesigner.util.DesignerUtil.java
public static <T> StringConverter<T> stringConverter(Function<T, String> toString, Function<String, T> fromString) { return new StringConverter<T>() { @Override//w w w .ja va 2s . co m public String toString(T object) { return toString.apply(object); } @Override public T fromString(String string) { return fromString.apply(string); } }; }
From source file:org.ado.musicdroid.view.AppPresenter.java
@Override public void initialize(URL location, ResourceBundle resources) { mediaConverterService = new MediaConverterService(); mediaConverterService.valueProperty().addListener((observable, oldValue, newValue) -> { if (newValue != null) { conversionProcessLabel.setText(String.format("Processing \"%s\" ...", newValue.getName())); }/*from w w w. j av a2 s.c o m*/ }); mediaConverterService.setOnSucceeded(event -> { conversionProcessLabel.setText("Conversion finished"); exportButton.setDisable(false); }); mediaConverterService.setOnFailed(event -> { conversionProcessLabel.setText("Conversion failed!"); exportButton.setDisable(false); LOGGER.error(event.getSource().exceptionProperty().getValue().toString()); }); final List<JadbDevice> devices = getJadbDevices(); LOGGER.info("Devices [{}]", devices); devicesComboBox.setItems(new ObservableListBase<JadbDevice>() { @Override public JadbDevice get(int index) { return devices.get(index); } @Override public int size() { return devices.size(); } }); devicesComboBox.setConverter(new StringConverter<JadbDevice>() { @Override public String toString(JadbDevice device) { return device.getSerial(); } @Override public JadbDevice fromString(String string) { return null; } }); if (!devicesComboBox.getItems().isEmpty()) { devicesComboBox.setValue(devices.get(0)); exportButton.setDisable(false); } loadAlbumList(); }
From source file:spdxedit.license.LicenseEditControl.java
@FXML void initialize() { assert rdoNone != null : "fx:id=\"rdoNone\" was not injected: check your FXML file 'LicenseEditControl.fxml'."; assert rdoNoAssert != null : "fx:id=\"rdoNoAssert\" was not injected: check your FXML file 'LicenseEditControl.fxml'."; assert rdoStandard != null : "fx:id=\"rdoStandard\" was not injected: check your FXML file 'LicenseEditControl.fxml'."; assert chcListedLicense != null : "fx:id=\"chcListedLicense\" was not injected: check your FXML file 'LicenseEditControl.fxml'."; assert chcExtractedLicenses != null : "fx:id=\"chcExtractedLicenses\" was not injected: check your FXML file 'LicenseEditControl.fxml'."; assert rdoExtracted != null : "fx:id=\"rdoExtracted\" was not injected: check your FXML file 'LicenseEditControl.fxml'."; assert btnNewFromFile != null : "fx:id=\"btnNewFromFile\" was not injected: check your FXML file 'LicenseEditControl.fxml'."; //Make radio buttons mutually exclusive ToggleGroup licenseTypeGroup = new ToggleGroup(); rdoExtracted.setToggleGroup(licenseTypeGroup); rdoStandard.setToggleGroup(licenseTypeGroup); rdoNone.setToggleGroup(licenseTypeGroup); rdoNoAssert.setToggleGroup(licenseTypeGroup); //Choice boxes should disable when their respective radio buttons are untoggled. rdoStandard.selectedProperty()// ww w .jav a2 s . c om .addListener((observable, oldValue, newValue) -> chcListedLicense.setDisable(!newValue)); rdoExtracted.selectedProperty() .addListener((observable, oldValue, newValue) -> chcExtractedLicenses.setDisable(!newValue)); chcListedLicense.getItems() .addAll(Arrays.stream(ListedLicenses.getListedLicenses().getSpdxListedLicenseIds()).sorted() .collect(Collectors.toList())); chcExtractedLicenses.setConverter(new StringConverter<ExtractedLicenseInfo>() { @Override public String toString(ExtractedLicenseInfo object) { return object.getName(); } @Override public ExtractedLicenseInfo fromString(String string) { return Arrays.stream(documentContainer.getExtractedLicenseInfos()) .filter(license -> StringUtils.equals(license.getName(), string)).findAny().get(); } }); btnNewFromFile.setVisible(showExtractLicenseButton); //Apply the initial value if (this.initialValue instanceof SpdxListedLicense) { chcListedLicense.setValue(((SpdxListedLicense) initialValue).getLicenseId()); chcListedLicense.setDisable(false); rdoStandard.selectedProperty().setValue(true); } else if (initialValue instanceof ExtractedLicenseInfo) { refreshExtractedLicenses(); chcExtractedLicenses.setValue((ExtractedLicenseInfo) initialValue); chcExtractedLicenses.setDisable(false); rdoExtracted.selectedProperty().setValue(true); } else if (initialValue instanceof SpdxNoAssertionLicense) { rdoNoAssert.selectedProperty().setValue(true); } else if (initialValue instanceof SpdxNoneLicense) { rdoNone.selectedProperty().setValue(true); } else { new Alert(Alert.AlertType.ERROR, "Unsupported license type: " + initialValue.getClass().getSimpleName() + ".", ButtonType.OK); } //Listen for change events licenseTypeGroup.selectedToggleProperty().addListener((observable1, oldValue1, newValue1) -> { hanldLicenseChangeEvent(); }); chcExtractedLicenses.valueProperty().addListener((observable, oldValue, newValue) -> { hanldLicenseChangeEvent(); }); chcListedLicense.valueProperty().addListener((observable, oldValue, newValue) -> { hanldLicenseChangeEvent(); }); }
From source file:spdxedit.util.StringConverters.java
public static StringConverter<ExtractedLicenseInfo> createStringConverterForDocument( final SpdxDocument document) { return new StringConverter<ExtractedLicenseInfo>() { @Override/*from w w w . ja v a2s .c o m*/ public String toString(ExtractedLicenseInfo object) { return object.getName(); } @Override public ExtractedLicenseInfo fromString(String string) { try { ExtractedLicenseInfo result = null; for (ExtractedLicenseInfo extractedLicenseInfo : document.getExtractedLicenseInfos()) { if (StringUtils.equals(extractedLicenseInfo.getName(), string)) { result = extractedLicenseInfo; break; } } if (result == null) { logger.error("Unable to find extracted license with name " + string); } return result; } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } } }; }