InteractiveValue
final class InteractiveValue<V>
Package: dev.joid.lib.ui.binding · Module: core · Source: InteractiveValue.java
Value of a node that both the code and the user change, with its bounds, its events and its two-way binding to a signal.
Description
Section titled “Description”The controls, the position of a node, its scroll offsets, the zoom of a UI and the camera of ModelViewerNode keep their value in an InteractiveValue.
It keeps the last value requested by a setter, the bound signal or a gesture, and applies it within the bounds (Keep a value that the bounds refuse); a change runs its steps in a fixed order (Know the order of a change).
A custom control creates one in its constructor and calls it from its own setters and input handlers.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
InteractiveValue<V> | create(NodeBindings bindings, String property, Supplier | Creates the value property of the node that owns bindings; getter reads the applied value from the node and setter stores it there. |
Properties
Section titled “Properties”| Property | Type | Default | Summary |
|---|---|---|---|
| source signal | V | set at creation | The getter of the value asked for, when the field keeps it apart from the value shown, as the view keeps the zoom asked for a UI; the getter of the value by default. |
| clamp | UnaryOperator<V> | UnaryOperator.identity() | The function that bounds every requested value before it applies; the default keeps the value unchanged. |
| then | BiConsumer<V,V> | (previous, next) -> { } | The action that runs with the previous and the applied value after each change; the default does nothing. |
Methods
Section titled “Methods”Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
V | get() | Returns the applied value, or the value waiting for the end of the input dispatch. |
V | getRequested() | Returns the last requested value before the bounds, or the applied value when none was requested. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
this | events(EventType beforeType, BiFunction | Sets the event types fired around a change and the functions that create the events from the previous and the next value; the before event can cancel the change. |
this | events(V target, EventType beforeType, BiFunction | Sets the events fired when the value changes to target, in place of the general ones, as the open and close events of a choice. |
T | start(V value) | Sets the start value from the code and drops the binding to a signal, then returns the node. |
boolean | change(V value) | Applies a change made by the user or by an action of the code, and returns false when a before listener cancelled it. |
void | reapply() | Applies the requested value again, after its bounds changed. |
void | set(V value) | Requests value: during the dispatch of an input event it waits for commit(), otherwise it applies through change(...). |
void | mark() | Starts the dispatch of an input event: changes wait until commit(). |
void | commit() | Ends the dispatch of an input event and applies the last waiting change. |
T | before(EventListener<?> listener) | Adds a listener of the before event, then returns the node. |
T | before(V target, EventListener<?> listener) | Adds a listener of the before event of the change to target, then returns the node. |
T | on(EventListener<?> listener) | Adds a listener of the on event, then returns the node. |
T | on(V target, EventListener<?> listener) | Adds a listener of the on event of the change to target, then returns the node. |
void | update(V value) | Applies a value that comes from the code or from the bound signal: no before event, then the on event when the applied value changed. |
T | bind(Signal | Binds the value to signal in both directions, then returns the node: the node takes the value of the signal and writes each change made by the user to it. |
Creation details
Section titled “Creation details”create
Section titled “create”<V> InteractiveValue<V> create(NodeBindings bindings, String property, Supplier<V> getter, Consumer<V> setter) factory
Creates the value property of the node that owns bindings; getter reads the applied value from the node and setter stores it there.
Property details
Section titled “Property details”source
Section titled “source”this source(Supplier<V> source)fluent signal
Default: set at creation
The getter of the value asked for, when the field keeps it apart from the value shown, as the view keeps the zoom asked for a UI; the getter of the value by default. With a source, the setter receives the value asked for and the getter returns the value shown.
this clamp(UnaryOperator<V> clamp)fluent
Default: UnaryOperator.identity()
The function that bounds every requested value before it applies; the default keeps the value unchanged.
Call reapply() after the bounds change.
this then(BiConsumer<V,V> then)fluent
Default: (previous, next) -> { }
The action that runs with the previous and the applied value after each change; the default does nothing.
Method details
Section titled “Method details”V get()
Returns the applied value, or the value waiting for the end of the input dispatch.
getRequested
Section titled “getRequested”V getRequested()
Returns the last requested value before the bounds, or the applied value when none was requested.
events
Section titled “events”this events(EventType<?> beforeType, BiFunction<V,V,? extends Event> before, EventType<?> onType, BiFunction<V,V,? extends Event> on) fluent
Sets the event types fired around a change and the functions that create the events from the previous and the next value; the before event can cancel the change.
this events(V target, EventType<?> beforeType, BiFunction<V,V,? extends Event> before, EventType<?> onType, BiFunction<V,V,? extends Event> on) fluent
Sets the events fired when the value changes to target, in place of the general ones, as the open and close events of a choice.
<T> T start(V value)
Sets the start value from the code and drops the binding to a signal, then returns the node.
The value applies without before event.
change
Section titled “change”boolean change(V value)
Applies a change made by the user or by an action of the code, and returns false when a before listener cancelled it.
During the dispatch of an input event, the change waits until the end of the dispatch, so the listeners of the event read the value before the change.
reapply
Section titled “reapply”void reapply()
Applies the requested value again, after its bounds changed.
void set(V value)
Requests value: during the dispatch of an input event it waits for commit(), otherwise it applies through change(...).
void mark()
Starts the dispatch of an input event: changes wait until commit().
commit
Section titled “commit”void commit()
Ends the dispatch of an input event and applies the last waiting change.
before
Section titled “before”<T> T before(EventListener<?> listener)
Adds a listener of the before event, then returns the node.
<T> T before(V target, EventListener<?> listener)
Adds a listener of the before event of the change to target, then returns the node.
<T> T on(EventListener<?> listener)
Adds a listener of the on event, then returns the node.
<T> T on(V target, EventListener<?> listener)
Adds a listener of the on event of the change to target, then returns the node.
update
Section titled “update”void update(V value)
Applies a value that comes from the code or from the bound signal: no before event, then the on event when the applied value changed.
<T> T bind(Signal<V> signal)
Binds the value to signal in both directions, then returns the node: the node takes the value of the signal and writes each change made by the user to it.
Throws an IllegalArgumentException when the signal is read-only.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
