Java Code Examples for javafx.beans.binding.Bindings#createStringBinding()
The following examples show how to use
javafx.beans.binding.Bindings#createStringBinding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MutableTabPane.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
/** Makes the title unique w.r.t. already present tabs. */ private Val<String> uniqueNameBinding(Val<String> titleProperty, int tabIdx) { Binding<String> uniqueBinding = Bindings.createStringBinding( () -> { String title = titleProperty.getOrElse("Unnamed"); int sameName = 0; LiveList<T> controllers = getControllers(); for (int i = 0; i < controllers.size() && i < tabIdx; i++) { if (title.equals(controllers.get(i).titleProperty().getOrElse("Unnamed"))) { sameName++; } } return sameName == 0 ? title : title + " (" + sameName + ")"; }, titleProperty, getTabs() ); return Val.wrap(uniqueBinding); }
Example 2
Source File: MemoryViewerTableModel.java From Noexes with GNU General Public License v3.0 | 6 votes |
private StringBinding createBinding(int i) { SimpleLongProperty prop; switch(i / 4){ case 0: prop = value1; break; case 1: prop = value2; break; case 2: prop = value3; break; case 3: prop = value4; break; default: throw new IllegalArgumentException(String.valueOf(i)); } int rem = i % 4; return Bindings.createStringBinding(() -> { int j = (prop.intValue() >> (24 - rem * 8)) & 0xFF; return new String(new byte[]{formatChar(j)}, StandardCharsets.UTF_8); }, prop); }
Example 3
Source File: GenericBackendDialogN5.java From paintera with GNU General Public License v2.0 | 5 votes |
private Node initializeNode( final Node rootNode, final String datasetPromptText, final Node browseNode) { final MenuButton datasetDropDown = new MenuButton(); final StringBinding datasetDropDownText = Bindings.createStringBinding(() -> dataset.get() == null || dataset.get().length() == 0 ? datasetPromptText : datasetPromptText + ": " + dataset.get(), dataset); final ObjectBinding<Tooltip> datasetDropDownTooltip = Bindings.createObjectBinding(() -> Optional.ofNullable(dataset.get()).map(Tooltip::new).orElse(null), dataset); datasetDropDown.tooltipProperty().bind(datasetDropDownTooltip); datasetDropDown.disableProperty().bind(this.isN5Valid.not()); datasetDropDown.textProperty().bind(datasetDropDownText); datasetChoices.addListener((ListChangeListener<String>) change -> { final MatchSelection matcher = MatchSelection.fuzzySorted(datasetChoices, s -> { dataset.set(s); datasetDropDown.hide(); }); LOG.debug("Updating dataset dropdown to fuzzy matcher with choices: {}", datasetChoices); final CustomMenuItem menuItem = new CustomMenuItem(matcher, false); // clear style to avoid weird blue highlight menuItem.getStyleClass().clear(); datasetDropDown.getItems().setAll(menuItem); datasetDropDown.setOnAction(e -> {datasetDropDown.show(); matcher.requestFocus();}); }); final GridPane grid = new GridPane(); grid.add(rootNode, 0, 0); grid.add(datasetDropDown, 0, 1); GridPane.setHgrow(rootNode, Priority.ALWAYS); GridPane.setHgrow(datasetDropDown, Priority.ALWAYS); grid.add(browseNode, 1, 0); return grid; }
Example 4
Source File: Clock.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public StringBinding getElapsedStringBinding(LocalDateTime start) { return Bindings.createStringBinding(() -> units.stream() .filter(u -> start.plus(1, u).isBefore(time.get())) // ignore units where less than 1 unit has elapsed .sorted(Comparator.reverseOrder()) // sort with biggest first .findFirst() // get the first (biggest) unit .map(u -> String.format("%d %s ago", u.between(start, time.get()), u)) // format as string .orElse("Just now") // default if elapsed time is less than smallest unit , time); }
Example 5
Source File: AbstractFilterModel.java From VocabHunter with Apache License 2.0 | 5 votes |
protected void bindValues() { ObservableNumberValue count = wordCountProperty(); StringBinding filenameText = Bindings.createStringBinding(() -> filename(file.get()), file); error.bind(Bindings.equal(count, 0)); filename.bind(filenameText); }
Example 6
Source File: AboutPanelSkin.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates the {@link Hyperlink} leading to the git revision on github * * @return The {@link Hyperlink} leading to the git revision on github */ private Hyperlink createGitRevisionHyperlink() { final StringBinding revisionText = Bindings.createStringBinding( () -> Optional.ofNullable(getControl().getBuildInformation()) .map(ApplicationBuildInformation::getApplicationGitRevision).orElse(null), getControl().buildInformationProperty()); final BooleanBinding disableProperty = Bindings.when(Bindings .and(Bindings.isNotNull(revisionText), Bindings.notEqual(revisionText, "unknown"))) .then(false).otherwise(true); final Hyperlink gitRevisionHyperlink = new Hyperlink(); gitRevisionHyperlink.textProperty().bind(revisionText); // if the git revision equals "unknown" disable the hyperlink gitRevisionHyperlink.disableProperty().bind(disableProperty); gitRevisionHyperlink.visitedProperty().bind(disableProperty); gitRevisionHyperlink.underlineProperty().bind(disableProperty); // if the git revision has been clicked on open the corresponding commit page on github gitRevisionHyperlink.setOnAction(event -> { try { final URI uri = new URI("https://github.com/PhoenicisOrg/phoenicis/commit/" + getControl().getBuildInformation().getApplicationGitRevision()); getControl().getOpener().open(uri); } catch (URISyntaxException e) { LOGGER.error("Could not open GitHub URL.", e); } }); return gitRevisionHyperlink; }
Example 7
Source File: GoogleCloud.java From paintera with GNU General Public License v2.0 | 4 votes |
public GenericBackendDialogN5 backendDialog(ExecutorService propagationExecutor) { final Label storageLabel = new Label(); final Label bucketLabel = new Label(); final StringBinding storageAsString = Bindings.createStringBinding( () -> Optional.ofNullable(storage.getValue()).map(Storage::toString).orElse(""), storage ); final StringBinding bucketAsString = Bindings.createStringBinding( () -> Optional.ofNullable(bucket.getValue()).map(Bucket::getName).orElse(""), bucket ); storageLabel.textProperty().bind(storageAsString); bucketLabel.textProperty().bind(bucketAsString); final GridPane grid = new GridPane(); grid.add(storageLabel, 1, 0); grid.add(bucketLabel, 1, 1); grid.add(new Label("storage"), 0, 0); grid.add(new Label("bucket"), 0, 1); grid.setHgap(10); final Consumer<Event> onClick = event -> { { final GoogleCloudBrowseHandler handler = new GoogleCloudBrowseHandler(); final Optional<Pair<Storage, Bucket>> res = handler.select(grid.getScene()); LOG.debug("Got result from handler: {}", res); if (res.isPresent()) { LOG.debug("Got result from handler: {} {}", res.get().getA(), res.get().getB()); storageAndBucket.storage.set(res.get().getA()); storageAndBucket.bucket.set(res.get().getB()); } } }; final Button browseButton = new Button("Browse"); browseButton.setOnAction(onClick::accept); return new GenericBackendDialogN5(grid, browseButton, "google", writerSupplier, propagationExecutor); }
Example 8
Source File: Clock.java From mars-sim with GNU General Public License v3.0 | 4 votes |
public StringBinding getTimeStringBinding(DateTimeFormatter formatter) { return Bindings.createStringBinding(() -> formatter.format(time.get()), time); }
Example 9
Source File: I18nManagerImpl.java From VocabHunter with Apache License 2.0 | 4 votes |
@Override public StringExpression textBinding(final I18nKey key, final ObservableValue<?>... arguments) { return Bindings.createStringBinding(() -> text(key, toArgs(arguments)), arguments); }
Example 10
Source File: StringBindings.java From phoenicis with GNU Lesser General Public License v3.0 | 2 votes |
/** * Maps a {@link ObservableValue} object to a {@link StringBinding} by applying the given converter function. * In case the input value is empty, i.e. contains <code>null</code>, the given default value is used * * @param property The input value * @param converter The converter function * @param defaultValue The default value in case the input value is empty * @param <E> The type of the input value * @return A {@link StringBinding} containing the converted value */ public static <E> StringBinding map(ObservableValue<E> property, Function<E, String> converter, String defaultValue) { return Bindings.createStringBinding( () -> Optional.ofNullable(property.getValue()).map(converter).orElse(defaultValue), property); }