Java Code Examples for javafx.beans.binding.StringBinding

The following examples show how to use javafx.beans.binding.StringBinding. These examples are extracted from open source projects. 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
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 2
Source Project: pikatimer   Source File: Segment.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void updateDistanceStringProperty(){
    if (getEndSplit() != null && getStartSplit() != null) {
        distanceStringProperty.unbind();
        distanceStringProperty.bind(new StringBinding(){
            {
            super.bind(getEndSplit().splitDistanceProperty(),getStartSplit().splitDistanceProperty());
            }
            @Override
            protected String computeValue() {
                return getEndSplit().getSplitDistance().subtract(getStartSplit().getSplitDistance()).abs().toPlainString().concat(" " + getEndSplit().getSplitDistanceUnits().toShortString());
            }
        });
        //distanceStringProperty.setValue(getEndSplit().getSplitDistance().subtract(getStartSplit().getSplitDistance()).abs().toPlainString().concat(" " + getEndSplit().getSplitDistanceUnits().toShortString()));
    } else {
        distanceStringProperty.unbind();
        distanceStringProperty.setValue("0");
    }
        
}
 
Example 3
Source Project: curly   Source File: BatchRunnerResult.java    License: Apache License 2.0 6 votes vote down vote up
public BatchRunnerResult() {
    reportRow().add(new ReadOnlyStringWrapper("Batch run"));
    
    StringBinding successOrNot = Bindings.when(completelySuccessful())
            .then(ApplicationState.getMessage(COMPLETED_SUCCESSFUL))
            .otherwise(ApplicationState.getMessage(COMPLETED_UNSUCCESSFUL));
    StringBinding successMessageBinding = Bindings.when(completed())
            .then(successOrNot).otherwise(ApplicationState.getMessage(INCOMPLETE));
    reportRow().add(successMessageBinding);

    reportRow().add(percentCompleteString().concat(" complete"));
    reportRow().add(percentSuccessString().concat(" success"));
    reportRow().add(getDuration());
    allBindings.add(successOrNot);
    allBindings.add(successMessageBinding);
}
 
Example 4
Source Project: RadialFx   Source File: DemoUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private Slider addSliderControl(final String title,
    final DoubleProperty prop) {
final Slider slider = new Slider();
slider.setValue(prop.get());
prop.bind(slider.valueProperty());
final VBox box = new VBox();
final Text titleText = new Text(title);

titleText.textProperty().bind(new StringBinding() {
    {
	super.bind(slider.valueProperty());
    }

    @Override
    protected String computeValue() {
	return title + " : " + twoDForm.format(slider.getValue());
    }

});
box.getChildren().addAll(titleText, slider);
getChildren().add(box);
return slider;
   }
 
Example 5
Source Project: RadialFx   Source File: DemoUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addColorControl(final String title,
    final ObjectProperty<Paint> paintProperty) {
final ColorPicker colorPicker = ColorPickerBuilder.create()
	.value((Color) paintProperty.get()).build();

paintProperty.bind(colorPicker.valueProperty());
final VBox box = new VBox();
final Text titleText = new Text(title);

titleText.textProperty().bind(new StringBinding() {
    {
	super.bind(colorPicker.valueProperty());
    }

    @Override
    protected String computeValue() {
	return title + " : " + colorPicker.getValue().toString();
    }

});
box.getChildren().addAll(titleText, colorPicker);
getChildren().add(box);
   }
 
Example 6
Source Project: RadialFx   Source File: DemoUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addBooleanControl(final String title,
    final BooleanProperty boolProp) {
final CheckBox check = new CheckBox();
check.setSelected(boolProp.get());
boolProp.bind(check.selectedProperty());

final VBox box = new VBox();
final Text titleText = new Text(title);

titleText.textProperty().bind(new StringBinding() {
    {
	super.bind(check.selectedProperty());
    }

    @Override
    protected String computeValue() {
	return title + " : "
		+ String.valueOf(check.selectedProperty().get());
    }

});
box.getChildren().addAll(titleText, check);
getChildren().add(box);

   }
 
Example 7
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 8
Source Project: marathonv5   Source File: StringBindingSample.java    License: Apache License 2.0 5 votes vote down vote up
public StringBindingSample() {
    final SimpleDateFormat format = new SimpleDateFormat("mm/dd/yyyy");
    final TextField dateField = new TextField();
    dateField.setPromptText("Enter a birth date");
    dateField.setMaxHeight(TextField.USE_PREF_SIZE);
    dateField.setMaxWidth(TextField.USE_PREF_SIZE);

    Label label = new Label();
    label.textProperty().bind(new StringBinding() {
        {
            bind(dateField.textProperty());
        }            
        @Override protected String computeValue() {
            try {
                Date date = format.parse(dateField.getText());
                Calendar c = Calendar.getInstance();
                c.setTime(date);

                Date today = new Date();
                Calendar c2 = Calendar.getInstance();
                c2.setTime(today);

                if (c.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) - 1
                        && c.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
                    return "You were born yesterday";
                } else {
                    return "You were born " + format.format(date);
                }
            } catch (Exception e) {
                return "Please enter a valid birth date (mm/dd/yyyy)";
            }
        }
    });

    VBox vBox = new VBox(7);
    vBox.setPadding(new Insets(12));
    vBox.getChildren().addAll(label, dateField);
    getChildren().add(vBox);
}
 
Example 9
Source Project: marathonv5   Source File: StringBindingSample.java    License: Apache License 2.0 5 votes vote down vote up
public StringBindingSample() {
    final SimpleDateFormat format = new SimpleDateFormat("mm/dd/yyyy");
    final TextField dateField = new TextField();
    dateField.setPromptText("Enter a birth date");
    dateField.setMaxHeight(TextField.USE_PREF_SIZE);
    dateField.setMaxWidth(TextField.USE_PREF_SIZE);

    Label label = new Label();
    label.textProperty().bind(new StringBinding() {
        {
            bind(dateField.textProperty());
        }            
        @Override protected String computeValue() {
            try {
                Date date = format.parse(dateField.getText());
                Calendar c = Calendar.getInstance();
                c.setTime(date);

                Date today = new Date();
                Calendar c2 = Calendar.getInstance();
                c2.setTime(today);

                if (c.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) - 1
                        && c.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
                    return "You were born yesterday";
                } else {
                    return "You were born " + format.format(date);
                }
            } catch (Exception e) {
                return "Please enter a valid birth date (mm/dd/yyyy)";
            }
        }
    });

    VBox vBox = new VBox(7);
    vBox.setPadding(new Insets(12));
    vBox.getChildren().addAll(label, dateField);
    getChildren().add(vBox);
}
 
Example 10
Source Project: pikatimer   Source File: Participant.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Participant() {
    fullNameProperty.bind(new StringBinding(){
        {super.bind(firstNameProperty,middleNameProperty, lastNameProperty);}
        @Override
        protected String computeValue() {
            return (firstNameProperty.getValueSafe() + " " + middleNameProperty.getValueSafe() + " " + lastNameProperty.getValueSafe()).replaceAll("( )+", " ");
        }
    });
    
    //Convenience properties for the getDNF and getDQ status checks
    dnfProperty.bind(new BooleanBinding(){
        {super.bind(statusProperty);}
        @Override
        protected boolean computeValue() {
            if (statusProperty.getValue().equals(Status.DNF)) return true;
            return false; 
        }
    });
    dqProperty.bind(new BooleanBinding(){
        {super.bind(statusProperty);}
        @Override
        protected boolean computeValue() {
            if (statusProperty.getValue().equals(Status.DQ)) return true;
            return false; 
        }
    });
    
    waves.addListener(new ListChangeListener<Wave>() {
        @Override
        public void onChanged(Change<? extends Wave> c) {
        
            Platform.runLater(() -> wavesChangedCounterProperty.setValue(wavesChangedCounterProperty.get()+1));
        }
    });
    
    status = Status.GOOD;
    statusProperty.set(status);
    
}
 
Example 11
Source Project: mars-sim   Source File: Clock.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 12
Source Project: VocabHunter   Source File: WordNoteHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void bindProperties(final TextArea textAreaNotePreview, final SessionModel sessionModel) {
    SimpleObjectProperty<WordModel> currentWordProperty = sessionModel.currentWordProperty();
    StringBinding noteBinding = selectString(currentWordProperty, "note");

    textAreaNotePreview.textProperty().bind(noteBinding);
    textAreaNotePreview.visibleProperty().bind(noteBinding.isNotEmpty());
}
 
Example 13
Source Project: VocabHunter   Source File: AbstractFilterModel.java    License: Apache License 2.0 5 votes vote down vote up
protected void bindValues() {
    ObservableNumberValue count = wordCountProperty();
    StringBinding filenameText = Bindings.createStringBinding(() -> filename(file.get()), file);

    error.bind(Bindings.equal(count, 0));
    filename.bind(filenameText);
}
 
Example 14
/**
 * Constructor
 *
 * @param currentTheme The current theme
 */
public ThemeManager(ObjectProperty<Theme> currentTheme) {
    super();

    this.currentTheme = currentTheme;

    this.defaultCategoryIconsStylesheets = FXCollections.observableArrayList();
    this.defaultLibraryCategoryIconsStylesheets = FXCollections.observableArrayList();
    this.defaultEngineIconsStylesheets = FXCollections.observableArrayList();

    // the base stylesheets
    final ObservableList<String> baseStylesheets = FXCollections
            .observableList(getStylesheets(Themes.STANDARD));
    // the currently selected stylesheets (empty if the the selected theme is the standard theme)
    final ObservableList<String> currentStylesheets = CollectionBindings
            .mapToList(currentTheme, this::getNonStandardStylesheets);

    this.stylesheets = ConcatenatedList.create(
            defaultCategoryIconsStylesheets,
            defaultLibraryCategoryIconsStylesheets,
            defaultEngineIconsStylesheets,
            baseStylesheets,
            currentStylesheets);

    final ObjectBinding<Optional<URI>> currentWebEngineUri = ObjectBindings.map(currentTheme,
            theme -> theme.getResourceUri("description.css"));
    final StringBinding currentWebEngineStylesheet = StringBindings.map(currentWebEngineUri,
            uri -> uri.map(URI::toString).orElse(null));

    this.webEngineStylesheet = Bindings
            .when(Bindings.isNull(currentWebEngineStylesheet))
            .then(Themes.STANDARD.getResourceUri("description.css").map(URI::toString)
                    .orElseThrow(
                            () -> new IllegalStateException("Standard theme contains no \"description.css\" file")))
            .otherwise(currentWebEngineStylesheet);
}
 
Example 15
/**
 * 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 16
public StringBinding errorMessage()
{
	return errorMessage;
}
 
Example 17
Source Project: paintera   Source File: GoogleCloud.java    License: GNU General Public License v2.0 4 votes vote down vote up
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 18
public StringBinding asciiBinding(int i){
    return asciiBindings[i];
}
 
Example 19
Source Project: FXGLGames   Source File: AsteroidsMainMenu.java    License: MIT License 4 votes vote down vote up
@Override
protected Button createActionButton(StringBinding stringBinding, Runnable runnable) {
    return new Button();
}
 
Example 20
Source Project: mars-sim   Source File: Clock.java    License: GNU General Public License v3.0 4 votes vote down vote up
public StringBinding getElapsedStringBinding() {
    return getElapsedStringBinding(LocalDateTime.now());
}
 
Example 21
Source Project: mars-sim   Source File: Clock.java    License: GNU General Public License v3.0 4 votes vote down vote up
public StringBinding getTimeStringBinding(DateTimeFormatter formatter) {
    return Bindings.createStringBinding(() -> formatter.format(time.get()), time);
}
 
Example 22
Source Project: mars-sim   Source File: Clock.java    License: GNU General Public License v3.0 4 votes vote down vote up
public StringBinding getTimeStringBinding() {
    return getTimeStringBinding(DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM));
}
 
Example 23
Source Project: FXGLGames   Source File: AsteroidsMainMenu.java    License: MIT License 4 votes vote down vote up
@Override
protected Button createActionButton(StringBinding stringBinding, Runnable runnable) {
    return new Button();
}
 
Example 24
Source Project: JFoenix   Source File: JFXSlider.java    License: Apache License 2.0 4 votes vote down vote up
public final ObjectProperty<Callback<JFXSlider, StringBinding>> valueFactoryProperty() {
    if (valueFactory == null) {
        valueFactory = new SimpleObjectProperty<>(this, "valueFactory");
    }
    return valueFactory;
}
 
Example 25
Source Project: JFoenix   Source File: JFXSlider.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return the current slider value factory
 */
public final Callback<JFXSlider, StringBinding> getValueFactory() {
    return valueFactory == null ? null : valueFactory.get();
}
 
Example 26
public StringBinding webEngineStylesheetProperty() {
    return this.webEngineStylesheet;
}
 
Example 27
public StringBinding indexProperty() {
    return index;
}
 
Example 28
public StringBinding nameProperty() {
    return name;
}
 
Example 29
public StringBinding valueProperty() {
    return value;
}
 
Example 30
Source Project: curly   Source File: RunnerResult.java    License: Apache License 2.0 4 votes vote down vote up
public StringBinding percentSuccessString() {
    return percentSuccessBinding;
}