Fix property listener
This commit is contained in:
parent
2a966d8cb3
commit
b7be570271
@ -12,8 +12,8 @@ import tornadofx.*
|
|||||||
/**
|
/**
|
||||||
* Bind a FX property to a device property with a given [spec]
|
* Bind a FX property to a device property with a given [spec]
|
||||||
*/
|
*/
|
||||||
fun <D : Device, T : Any> Device.fxProperty(
|
fun <D : Device, T : Any> D.fxProperty(
|
||||||
spec: DevicePropertySpec<D, T>
|
spec: DevicePropertySpec<D, T>,
|
||||||
): ReadOnlyProperty<T> = object : ObjectPropertyBase<T>() {
|
): ReadOnlyProperty<T> = object : ObjectPropertyBase<T>() {
|
||||||
override fun getBean(): Any = this
|
override fun getBean(): Any = this
|
||||||
override fun getName(): String = spec.name
|
override fun getName(): String = spec.name
|
||||||
@ -21,16 +21,12 @@ fun <D : Device, T : Any> Device.fxProperty(
|
|||||||
init {
|
init {
|
||||||
//Read incoming changes
|
//Read incoming changes
|
||||||
onPropertyChange(spec) {
|
onPropertyChange(spec) {
|
||||||
if (it != null) {
|
runLater {
|
||||||
runLater {
|
try {
|
||||||
try {
|
set(it)
|
||||||
set(it)
|
} catch (ex: Throwable) {
|
||||||
} catch (ex: Throwable) {
|
logger.info { "Failed to set property $name to $it" }
|
||||||
logger.info { "Failed to set property $name to $it" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
invalidated()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user