Kanzi  3.9.6
Java API
BindingBuilder Class Reference

Use BindingBuilder to create bindings. More...

Static Public Member Functions

static AbstractBinding createOneWay (String sourcePath, PropertyType<?> sourcePropertyType)
 Creates a one-way binding. More...
 
static AbstractBinding createOneWay (String sourcePath, PropertyType<?> sourcePropertyType, PropertyField sourcePropertyField)
 Creates a one-way binding. More...
 
static AbstractBinding createOneWay (Object value)
 Creates a manual binding source. More...
 
static AbstractBinding createOneWay (ResourceID resourceId)
 Creates a resource binding. More...
 
static AbstractBinding createToSource (String readPath, PropertyType<?> readPropertyType, String pushPath, PropertyType<?> pushPropertyType)
 Creates a To Source binding. More...
 
static AbstractBinding createToSource (String readPath, PropertyType<?> readPropertyType, PropertyField readPropertyField, String pushPath, PropertyType<?> pushPropertyType, PropertyField pushPropertyField)
 Creates a To Source binding. More...
 
static AbstractBinding createTwoWay (String sourcePath, PropertyType<?> sourcePropertyType)
 Creates a two-way binding. More...
 
static AbstractBinding createTwoWay (String sourcePath, PropertyType<?> sourcePropertyType, PropertyField sourcePropertyField)
 Creates a two-way binding. More...
 

Detailed Description

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:

// Creates a one-way binding to the Opacity property of Node A.
AbstractBinding binding =
BindingBuilder.createOneWay("../Node A", Node2D.OpacityProperty);

To set a binding to the property of a node:

// Sets the binding to Node B. Creates a binding runtime that you can use to remove the
// binding.
AbstractBindingRuntime runtime = nodeB.setBinding(binding, Node2D.OpacityProperty);

To remove a binding from a node:

// Removes from Node B the binding to the Opacity property of Node A using the binding
// runtime.
nodeB.removeBinding(runtime);

To create a callback binding processor to a binding and to set a two-way binding between properties of two nodes:

// Create a two-way binding to the Opacity property of Node A.
AbstractBinding binding =
BindingBuilder.createTwoWay("../Node A", Node2D.OpacityProperty);
// Create a callback processor that accepts only float values greater than or equal to
// 0.5.
CallbackBindingProcessor processor =
CallbackBindingProcessor.create(getDomain(), value -> {
if (value instanceof Float)
{
return ((float) value >= 0.5f);
}
return false;
});
// Add a callback processor to the binding. You must do this before adding the binding
// to a node.
binding.addProcessor(processor);
// Bind from the Opacity property of Node A to the Opacity property of Node B.
AbstractBindingRuntime runtime = nodeB.setBinding(binding, Node2D.OpacityProperty);
final float opacityAa = 0.333333f;
// Setting the opacity of Node A to less than 0.5 does not change the opacity of
// Node B.
nodeA.setOpacity(opacityAa);
final float opacityBa = nodeB.getOpacity();
final float opacityAb = 0.55555f;
// Setting the opacity of Node A to a value greater than or equal to 0.5 changes the
// opacity of Node B.
nodeA.setOpacity(opacityAb);

To listen to changes in a property's value using a callback processor:

// Create a one-way binding to an object's own Opacity property.
AbstractBinding binding = BindingBuilder.createOneWay(".", Node2D.OpacityProperty);
// Implement the action to be performed on change in the property as a callback
// processor.
CallbackBindingProcessor processor =
CallbackBindingProcessor.create(getDomain(), value -> {
Log.debug("Opacity value changed to: " + value);
// The return does not matter here.
return true;
});
// Add a callback processor to the binding. You must do this before adding the binding
// to a node.
binding.addProcessor(processor);
// Add binding to the node you want to observe.
// Note the lack of target property and field.
node.setBinding(binding);

To create, set, and remove bindings with an owner:

// Create two bindings.
AbstractBinding binding1 =
BindingBuilder.createOneWay("../Node A", Node2D.OpacityProperty);
AbstractBinding binding2 =
BindingBuilder.createOneWay("../Node A", Node2D.BackgroundBrushProperty);
// Bind to opacity and background brush properties, use Node A as owner.
AbstractBindingRuntime runtime1 =
nodeB.setBindingWithOwner(binding1, nodeA, Node2D.OpacityProperty);
AbstractBindingRuntime runtime2 =
nodeB.setBindingWithOwner(binding2, nodeA, Node2D.BackgroundBrushProperty);
// Remove bindings at the same time using Node A as owner.
nodeB.removeBindingsWithOwner(nodeA);

To create and set a modifier binding:

// Create a binding to Render Transformation property Translation X property field of
// Node A.
AbstractBinding binding = BindingBuilder.createOneWay("../Node A",
Node2D.RenderTransformationProperty, PropertyField.PropertyFieldTranslationX);
// Bind it to Translation Y property field of the same node.
AbstractBindingRuntime runtime = nodeA.setModifierBinding(binding,
Node2D.RenderTransformationProperty, PropertyField.PropertyFieldTranslationY);

Member Function Documentation

◆ createOneWay() [1/4]

static AbstractBinding createOneWay ( String  sourcePath,
PropertyType<?>  sourcePropertyType 
)
static

Creates a one-way binding.

Parameters
sourcePathPath to source object.
sourcePropertyTypeSource property type from which to bind.
Returns
The created one-way binding.

◆ createOneWay() [2/4]

static AbstractBinding createOneWay ( String  sourcePath,
PropertyType<?>  sourcePropertyType,
PropertyField  sourcePropertyField 
)
static

Creates a one-way binding.

Parameters
sourcePathPath to source object.
sourcePropertyTypeSource property type from which to bind.
sourcePropertyFieldField of the source property type from which to bind. Use PropertyFieldWhole to bind to the whole property.
Returns
The created one-way binding.

◆ createOneWay() [3/4]

static AbstractBinding createOneWay ( Object  value)
static

Creates a manual binding source.

Parameters
valueValue to create with.

◆ createOneWay() [4/4]

static AbstractBinding createOneWay ( ResourceID  resourceId)
static

Creates a resource binding.

Parameters
resourceIdResource ID.
Returns
The created binding.

◆ createToSource() [1/2]

static AbstractBinding createToSource ( String  readPath,
PropertyType<?>  readPropertyType,
String  pushPath,
PropertyType<?>  pushPropertyType 
)
static

Creates a To Source binding.

Parameters
readPathPath to read object.
readPropertyTypeRead property type from which to bind.
pushPathPath to push object.
pushPropertyTypePush property type to which to bind.
Returns
The created To Source binding.

◆ createToSource() [2/2]

static AbstractBinding createToSource ( String  readPath,
PropertyType<?>  readPropertyType,
PropertyField  readPropertyField,
String  pushPath,
PropertyType<?>  pushPropertyType,
PropertyField  pushPropertyField 
)
static

Creates a To Source binding.

Parameters
readPathPath to read object.
readPropertyTypeRead property type from which to bind.
readPropertyFieldField of the read property type from which to bind. Use PropertyFieldWhole to bind to the whole property.
pushPathPath to push object.
pushPropertyTypePush property type to which to bind.
pushPropertyFieldField of the push property type from which to bind. Use PropertyFieldWhole to bind to the whole property.
Returns
The created To Source binding.

◆ createTwoWay() [1/2]

static AbstractBinding createTwoWay ( String  sourcePath,
PropertyType<?>  sourcePropertyType 
)
static

Creates a two-way binding.

Parameters
sourcePathPath to source object.
sourcePropertyTypeSource property type from which to bind.
Returns
The created two-way binding.

◆ createTwoWay() [2/2]

static AbstractBinding createTwoWay ( String  sourcePath,
PropertyType<?>  sourcePropertyType,
PropertyField  sourcePropertyField 
)
static

Creates a two-way binding.

Parameters
sourcePathPath to source object.
sourcePropertyTypeSource property type from which to bind.
sourcePropertyFieldField of the source property type from which to bind. Use PropertyFieldWhole to bind to the whole property.
Returns
The created two-way binding.