commonMain.jetbrains.datalore.base.observable.property.DelayedValueProperty.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2020. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.base.observable.property
import jetbrains.datalore.base.observable.event.EventHandler
import jetbrains.datalore.base.observable.event.ListenerCaller
import jetbrains.datalore.base.observable.event.Listeners
import jetbrains.datalore.base.registration.Registration
import kotlin.jvm.JvmOverloads
class DelayedValueProperty
@JvmOverloads
constructor(
private var myValue: ValueT? = null) :
BaseReadableProperty(),
Property {
private var myHandlers: Listeners>>? = null
private var myPendingEvent: PropertyChangeEvent? = null
override val propExpr: String
get() = "delayedProperty()"
override fun get(): ValueT? {
return myValue
}
override fun set(value: ValueT?) {
if (value == myValue) return
val oldValue = myValue
myValue = value
if (myPendingEvent != null) {
throw IllegalStateException()
}
myPendingEvent =
PropertyChangeEvent(oldValue, myValue)
}
fun flush() {
if (myHandlers != null) {
myHandlers!!.fire(object : ListenerCaller>> {
override fun call(l: EventHandler>) {
l.onEvent(myPendingEvent!!)
}
})
}
myPendingEvent = null
}
override fun addHandler(handler: EventHandler>): Registration {
if (myHandlers == null) {
myHandlers = object : Listeners>>() {
override fun afterLastRemoved() {
myHandlers = null
}
}
}
return myHandlers!!.add(handler)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy