Class Binding
- All Implemented Interfaces:
Proxy
GObject
instance (or source) and another property on another GObject
instance (or target).
Whenever the source property changes, the same value is applied to the target property; for instance, the following binding:
g_object_bind_property (object1, "property-a",
object2, "property-b",
G_BINDING_DEFAULT);
will cause the property named "property-b" of object2
to be updated
every time GObject#set
or the specific accessor changes the value of
the property "property-a" of object1
.
It is possible to create a bidirectional binding between two properties
of two GObject
instances, so that if either property changes, the
other is updated as well, for instance:
g_object_bind_property (object1, "property-a",
object2, "property-b",
G_BINDING_BIDIRECTIONAL);
will keep the two properties in sync.
It is also possible to set a custom transformation function (in both directions, in case of a bidirectional binding) to apply a custom transformation from the source value to the target value before applying it; for instance, the following binding:
g_object_bind_property_full (adjustment1, "value",
adjustment2, "value",
G_BINDING_BIDIRECTIONAL,
celsius_to_fahrenheit,
fahrenheit_to_celsius,
NULL, NULL);
will keep the "value" property of the two adjustments in sync; the
celsiusToFahrenheit
function will be called whenever the "value"
property of adjustment1
changes and will transform the current value
of the property before applying it to the "value" property of adjustment2
.
Vice versa, the fahrenheitToCelsius
function will be called whenever
the "value" property of adjustment2
changes, and will transform the
current value of the property before applying it to the "value" property
of adjustment1
.
Note that GBinding
does not resolve cycles by itself; a cycle like
object1:propertyA -> object2:propertyB
object2:propertyB -> object3:propertyC
object3:propertyC -> object1:propertyA
might lead to an infinite loop. The loop, in this particular case,
can be avoided if the objects emit the GObject::notify
signal only
if the value has effectively been changed. A binding is implemented
using the GObject::notify
signal, so it is susceptible to all the
various ways of blocking a signal emission, like GObjects.signalStopEmission(org.gnome.gobject.GObject, int, org.gnome.glib.Quark)
or GObjects.signalHandlerBlock(org.gnome.gobject.GObject, int)
.
A binding will be severed, and the resources it allocates freed, whenever
either one of the GObject
instances it refers to are finalized, or when
the GBinding
instance loses its last reference.
Bindings for languages with garbage collection can use
unbind()
to explicitly release a binding between the source
and target properties, instead of relying on the last reference on the
binding, source, and target instances to drop.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Binding.Builder<B extends Binding.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionBinding
(MemorySegment address) Create a Binding proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Binding
asParent()
Returns this instance as if it were its parent type.static Binding.Builder
<? extends Binding.Builder> builder()
ABinding.Builder
object constructs aBinding
with the specified properties.Retrieves theGObject
instance used as the source of the binding.Retrieves theGObject
instance used as the target of the binding.getFlags()
Retrieves the flags passed when constructing theGBinding
.Deprecated.Use g_binding_dup_source() for a safer version of this function.Retrieves the name of the property ofGBinding
:source used as the source of the binding.Deprecated.Use g_binding_dup_target() for a safer version of this function.Retrieves the name of the property ofGBinding
:target used as the target of the binding.static Type
getType()
Get the GType of the Binding classvoid
unbind()
Explicitly releases the binding between the source and the target property expressed by this Binding.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Binding
Create a Binding proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
dupSource
Retrieves theGObject
instance used as the source of the binding.A
GBinding
can outlive the sourceGObject
as the binding does not hold a strong reference to the source. If the source is destroyed before the binding then this function will returnnull
.- Returns:
- the source
GObject
, ornull
if the source does not exist any more.
-
dupTarget
Retrieves theGObject
instance used as the target of the binding.A
GBinding
can outlive the targetGObject
as the binding does not hold a strong reference to the target. If the target is destroyed before the binding then this function will returnnull
.- Returns:
- the target
GObject
, ornull
if the target does not exist any more.
-
getFlags
Retrieves the flags passed when constructing theGBinding
.- Returns:
- the
GBindingFlags
used by theGBinding
-
getSource
Deprecated.Use g_binding_dup_source() for a safer version of this function.Retrieves theGObject
instance used as the source of the binding.A
GBinding
can outlive the sourceGObject
as the binding does not hold a strong reference to the source. If the source is destroyed before the binding then this function will returnnull
.Use g_binding_dup_source() if the source or binding are used from different threads as otherwise the pointer returned from this function might become invalid if the source is finalized from another thread in the meantime.
- Returns:
- the source
GObject
, ornull
if the source does not exist any more.
-
getSourceProperty
Retrieves the name of the property ofGBinding
:source used as the source of the binding.- Returns:
- the name of the source property
-
getTarget
Deprecated.Use g_binding_dup_target() for a safer version of this function.Retrieves theGObject
instance used as the target of the binding.A
GBinding
can outlive the targetGObject
as the binding does not hold a strong reference to the target. If the target is destroyed before the binding then this function will returnnull
.Use g_binding_dup_target() if the target or binding are used from different threads as otherwise the pointer returned from this function might become invalid if the target is finalized from another thread in the meantime.
- Returns:
- the target
GObject
, ornull
if the target does not exist any more.
-
getTargetProperty
Retrieves the name of the property ofGBinding
:target used as the target of the binding.- Returns:
- the name of the target property
-
unbind
public void unbind()Explicitly releases the binding between the source and the target property expressed by this Binding.This function will release the reference that is being held on the this Binding instance if the binding is still bound; if you want to hold on to the
GBinding
instance after calling g_binding_unbind(), you will need to hold a reference to it.Note however that this function does not take ownership of this Binding, it only unrefs the reference that was initially created by g_object_bind_property() and is owned by the binding.
-
builder
ABinding.Builder
object constructs aBinding
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withBinding.Builder.build()
.
-