Use BindingBuilder to create bindings.
You can use bindings to set the value of a property or property field with the value from another property, property field, or a data source.
To create a one-way binding:
AbstractBinding binding =
BindingBuilder.createOneWay("../Node A", Node2D.OpacityProperty);
To set a binding to the property of a node:
AbstractBindingRuntime runtime = nodeB.setBinding(binding, Node2D.OpacityProperty);
To remove a binding from a node:
nodeB.removeBinding(runtime);
To create a callback binding processor to a binding and to set a two-way binding between properties of two nodes:
AbstractBinding binding =
BindingBuilder.createTwoWay("../Node A", Node2D.OpacityProperty);
CallbackBindingProcessor processor =
CallbackBindingProcessor.create(getDomain(), value -> {
if (value instanceof Float)
{
return ((float) value >= 0.5f);
}
return false;
});
binding.addProcessor(processor);
AbstractBindingRuntime runtime = nodeB.setBinding(binding, Node2D.OpacityProperty);
final float opacityAa = 0.333333f;
nodeA.setOpacity(opacityAa);
final float opacityBa = nodeB.getOpacity();
final float opacityAb = 0.55555f;
nodeA.setOpacity(opacityAb);
To listen to changes in a property's value using a callback processor:
AbstractBinding binding = BindingBuilder.createOneWay(".", Node2D.OpacityProperty);
CallbackBindingProcessor processor =
CallbackBindingProcessor.create(getDomain(), value -> {
Log.debug("Opacity value changed to: " + value);
return true;
});
binding.addProcessor(processor);
node.setBinding(binding);
To create, set, and remove bindings with an owner:
AbstractBinding binding1 =
BindingBuilder.createOneWay("../Node A", Node2D.OpacityProperty);
AbstractBinding binding2 =
BindingBuilder.createOneWay("../Node A", Node2D.BackgroundBrushProperty);
AbstractBindingRuntime runtime1 =
nodeB.setBindingWithOwner(binding1, nodeA, Node2D.OpacityProperty);
AbstractBindingRuntime runtime2 =
nodeB.setBindingWithOwner(binding2, nodeA, Node2D.BackgroundBrushProperty);
nodeB.removeBindingsWithOwner(nodeA);
To create and set a modifier binding:
AbstractBinding binding = BindingBuilder.createOneWay("../Node A",
Node2D.RenderTransformationProperty, PropertyField.PropertyFieldTranslationX);
AbstractBindingRuntime runtime = nodeA.setModifierBinding(binding,
Node2D.RenderTransformationProperty, PropertyField.PropertyFieldTranslationY);