T
- the type of values which the listener processespublic class ControlPropertyListenerBuilder<T> extends Object
ControlPropertyListener
. This is no type on its own as explained in
ControlPropertyListenerHandle
. Such a handle is returned by this builder.
It is best created by calling ControlProperties.on(ObservableMap)
with the control's property map as an
argument. It is necessary to set a key (with forKey(Object)
) and a processor function for the value (with
processValue(Consumer)
) before calling buildDetached()
.
Specifying the value's type with forValueType(Class)
is optional. If it is done, the built listener will use
it to check the type of the value before casting it to the type accepted by the value processor. If those types do
not match, this prevents ClassCastException
(which would otherwise be caught and silently ignored). If that
case occurs frequently, specifying the type to allow the check will improve performance considerably.
A typical use looks like this:
ControlProperties.<Boolean> on(control.getProperties()) .forKey("visible") .processValue(this::setVisibility) .buildDetached();
Modifier and Type | Method and Description |
---|---|
ControlPropertyListenerHandle |
buildAttached()
Creates a new property listener according to the arguments specified before and
attaches it. |
ControlPropertyListenerHandle |
buildDetached()
Creates a new property listener according to the arguments specified before.
|
ControlPropertyListenerBuilder<T> |
forKey(Object key)
Sets the key.
|
ControlPropertyListenerBuilder<T> |
forValueType(Class<T> valueType)
Sets the type of the values which the built listener will process.
|
static <T> ControlPropertyListenerBuilder<T> |
on(javafx.collections.ObservableMap<Object,Object> properties)
Creates a builder for a
ControlPropertyListenerHandle which observes the specified property map. |
ControlPropertyListenerBuilder<T> |
processValue(Consumer<? super T> valueProcessor)
Sets the processor for the key's values.
|
public static <T> ControlPropertyListenerBuilder<T> on(javafx.collections.ObservableMap<Object,Object> properties)
ControlPropertyListenerHandle
which observes the specified property map.
Note that it is often necessary to explicitly specify the type parameter T
like so:
ControlProperties.<String> on(...)
T
- the type of values which the listener processesproperties
- the ObservableMap
holding the propertiesControlPropertyListenerBuilder
public ControlPropertyListenerBuilder<T> forKey(Object key)
buildDetached()
.key
- the key the built listener will observepublic ControlPropertyListenerBuilder<T> forValueType(Class<T> valueType)
valueProcessor
.
This type is optional. See the class comment on this builder
for details.
valueType
- the type of values the built listener will processpublic ControlPropertyListenerBuilder<T> processValue(Consumer<? super T> valueProcessor)
buildAttached()
.valueProcessor
- the Consumer
for the key's valuespublic ControlPropertyListenerHandle buildAttached()
attaches
it.ControlPropertyListenerHandle
; initially attachedbuildDetached()
public ControlPropertyListenerHandle buildDetached()
Note that this builder is not yet attached to the map! This can be done by calling
attach()
on the returned instance.
ControlPropertyListenerHandle
; initially detachedbuildAttached()
This documentation is licensed under CC-BY 4.0, attributed to Nicolai Parlog from CodeFX.