property

fun <T : Component, V> SwingModifier.property(descriptor: ComponentPropertyDescriptor<T, V>, value: V, restores: RestorePolicy = RestorePolicy.EverythingWritten, inheritable: Boolean = false, rewriteOn: String? = null, alsoOverwrites: List<ComponentPropertyDescriptor<T, *>> = emptyList()): SwingModifier

Declares descriptor on the component, value for as long as this declaration stands. The property is read as the declaration arrives and written back when the declaration leaves, so a widget that outlives it carries what it did before.

Build descriptor once, as a top-level val, with ComponentPropertyDescriptor's constructors:

private val DividerSizeProperty =
ComponentPropertyDescriptor<JSplitPane, Int>(
name = "dividerSize",
read = { it.dividerSize },
write = { pane, v -> pane.dividerSize = v },
)

private fun SwingModifier.declaredDividerSize(dividerSize: Int?): SwingModifier =
if (dividerSize == null) this else property(DividerSizeProperty, dividerSize)

Declare only a property this library ships no modifier of its own for. Two declarations of one ComponentPropertyDescriptor.name - even through two different handles - share one slot: the last one declared wins, and they take one record of what the property stood at before either wrote it, put back from whichever of them leaves last.

Return

this modifier with descriptor declared on it.

Parameters

descriptor

the property being written.

value

the value to write while this declaration stands.

restores

what the component is held to once this declaration leaves. RestorePolicy.EverythingWritten, the default, holds it to carrying descriptor's read answer again. RestorePolicy.DeclaredPropertyOnly holds it to descriptor's name alone, for a write a look and feel derives a property of its own from. RestorePolicy.None is for a property the component offers no way to give back - one whose setter refuses the value read answered with, or rebuilds the component's UI - and descriptor's own write says what the component keeps instead.

inheritable

lets the declaration be provided to descendants as a component default - a property such as a color or a font that makes sense across a whole subtree. A property descriptor serves only some component types reaches only those among the descendants.

rewriteOn

names a bean property whose announced change means value may have been overwritten, so the node listens for it and writes value again. Name the property itself where the component announces every change of it, its own write included. Reassertion happens only after a matching PropertyChangeEvent; a component or look and feel that mutates it silently cannot be observed or reasserted.

alsoOverwrites

properties descriptor's own write lands on besides the one it declares - a coarse geometry naming each axis it covers, a button's fill keeping its opaque flag in step with it. Each is held beside the declared one and given back after it, so a removal puts back every property the write touched, not only the one this declaration names.