Java Code Examples for javafx.beans.property.ObjectProperty#bind()

The following examples show how to use javafx.beans.property.ObjectProperty#bind() . 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: DemoUtil.java    From RadialFx with 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 2
Source File: SearchHandler.java    From PreferencesFX with Apache License 2.0 5 votes vote down vote up
/**
 * Binds the predicateProperty to ensure filtering according to the searchText.
 *
 * @param predicateProperty of the rootItem of a {@link FilterableTreeItem}
 */
public void bindFilterPredicate(ObjectProperty<Predicate<Category>> predicateProperty) {
  predicateProperty.bind(Bindings.createObjectBinding(() -> {
    if (searchText.get() == null || searchText.get().isEmpty()) {
      return null;
    }
    return filterPredicate;
  }, searchText));
}
 
Example 3
Source File: ModelImportDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected boolean validate(@NotNull final VarTable vars) {

    final ImageView imageView = getImageView();

    if (!vars.has(PROP_FILE)) {
        imageView.setImage(null);
        return false;
    }

    final Path file = vars.get(PROP_FILE);

    if (!JmeFilePreviewManager.isModelFile(file)) {
        imageView.setImage(null);
        return false;
    }

    final Path renderedFile = getRenderedFile();
    if (renderedFile != null && file.equals(renderedFile)) {
        return super.validate(vars);
    }

    final int width = (int) imageView.getFitWidth();
    final int height = (int) imageView.getFitHeight();

    final JmeFilePreviewManager previewManager = JmeFilePreviewManager.getInstance();
    previewManager.showExternal(file, width, height);

    final ImageView sourceView = previewManager.getImageView();
    final ObjectProperty<Image> imageProperty = imageView.imageProperty();
    imageProperty.bind(sourceView.imageProperty());

    setRenderedFile(file);

    return super.validate(vars);
}
 
Example 4
Source File: BezierOffsetSnippet.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public HBox ToggleButtonColor(String text,
		ObjectProperty<Color> colorProperty,
		BooleanProperty toggledProperty, boolean isToggled) {
	HBox hbox = new HBox();
	ToggleButton toggleButton = new ToggleButton(text);
	toggleButton.setOnAction((ae) -> {
		refreshAll();
	});
	ColorPicker colorPicker = new ColorPicker(colorProperty.get());
	colorProperty.bind(colorPicker.valueProperty());
	hbox.getChildren().addAll(toggleButton, colorPicker);
	toggledProperty.bind(toggleButton.selectedProperty());
	toggleButton.setSelected(isToggled);
	return hbox;
}
 
Example 5
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void recreateParagraphGraphic( int parNdx ) {
    ObjectProperty<IntFunction<? extends Node>> gProp;
    gProp = getCell(parNdx).graphicFactoryProperty();
    gProp.unbind();
    gProp.bind(paragraphGraphicFactoryProperty());
}
 
Example 6
Source File: DemoUtil.java    From RadialFx with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addGraphicControl(final String title,
    final ObjectProperty<Node> graphicProperty) {

final Node circle  = CircleBuilder.create().radius(4).fill(Color.ORANGE).build();
final Node square  = RectangleBuilder.create().width(8).height(8).build();
final Node text  = TextBuilder.create().text("test").build();

final ComboBox<Node> choices = new ComboBox<Node>(FXCollections.observableArrayList(circle, square, text));
choices.setCellFactory(new Callback<ListView<Node>, ListCell<Node>>() {
    @Override
    public ListCell<Node> call(final ListView<Node> param) {
	final ListCell<Node> cell = new ListCell<Node>() {
	    @Override
	    public void updateItem(final Node item, final boolean empty) {
		super.updateItem(item, empty);
		if (item != null) {
		    setText(item.getClass().getSimpleName());
		} else {
		    setText(null);
		}
	    }
	};
	return cell;
    }
});
choices.getSelectionModel().select(0);
graphicProperty.bind(choices.valueProperty());

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

titleText.textProperty().bind(new StringBinding() {
    {
	super.bind(choices.selectionModelProperty());
    }

    @Override
    protected String computeValue() {
	return title + " : "
		+ String.valueOf(choices.selectionModelProperty().get().getSelectedItem().getClass().getSimpleName());
    }

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

   }