declare

fun <C : Component, V> SwingNodeUpdater<C>.declare(value: V, mirror: MirrorState<V>, read: C.() -> V, write: C.(V) -> Unit, onSettled: C.(V) -> Unit = {})

Declares value onto a widget property the user can also change, keeping mirror in sync with it.

Unlike SwingNodeUpdater.set, which compares this pass's declaration against the last one, this also depends on the value the widget holds. It runs whenever either side changes, in particular on the pass that follows the user taking the widget away from the declaration - nothing polls; reading the widget's mirrored value is what subscribes the component to those changes.

read and write carry the property, and a widget's own accessors are usually the whole of them:

declare(checked, mirror, JCheckBox::isSelected, JCheckBox::setSelected)

Pass blocks instead where the write is more than a plain assignment - one that coerces its argument, or that must be skipped for a value the widget already holds.

Call this exactly once per pass, for one node, against a mirror remembered in that node's own group. It calls SwingNodeUpdater.set, so a declare inside a conditional shifts every later slot in the update block; and what a declaration is compared against lives on mirror rather than in the composition, so a mirror that outlives its node answers for a widget that is no longer there. State a condition in value, not in whether the call happens.

Parameters

value

the declaration for the property, settled on every pass either side changes.

mirror

the record this declaration and the widget's value are compared against.

read

answers with the value the widget holds. Called once before the write, and a second time only where a write was made.

write

puts a value onto the widget, marked as the library's own so the events it raises are not taken for the user's.

onSettled

handed what the widget was left holding, where that differs from value. Defaults to doing nothing.


fun <C : Component, V> SwingNodeUpdater<C>.declare(value: V, mirror: MirrorState<V>, read: C.() -> V, write: C.(held: V, declared: V) -> Unit, onSettled: C.(V) -> Unit = {})

Declares value onto a widget property whose write is a transition rather than an assignment: write is handed what the widget holds alongside what is declared, so it can write only the part that differs and leave what the rest of the value anchors standing - the caret inside a document, above all. The held value is the one the settlement has already read, so the write costs no second read.

Everything the assigning overload says about when a settlement runs, and about calling it once per pass for one node, holds here too.

Parameters

value

the declaration for the property, settled on every pass either side changes.

mirror

the record this declaration and the widget's value are compared against.

read

answers with the value the widget holds. Called once before the write, and a second time only where a write was made.

write

moves the widget from the value it holds to the one declared, marked as the library's own so the events it raises are not taken for the user's.

onSettled

handed what the widget was left holding, where that differs from value. Defaults to doing nothing.