diff --git a/pom.xml b/pom.xml
index ce7a5b2..61ef960 100644
--- a/pom.xml
+++ b/pom.xml
@@ -117,7 +117,7 @@
scm:git:git://github.com/saalfeldlab/saalfx
scm:git:git@github.com:saalfeldlab/saalfx.git
- saalfx-1.3.0
+ saalfx-2.0.0
https://github.com/saalfeldlab/saalfx
diff --git a/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/Action.kt b/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/Action.kt
index 73ac209..06609f1 100644
--- a/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/Action.kt
+++ b/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/Action.kt
@@ -192,18 +192,15 @@ open class Action(val eventType: EventType) {
private fun testChecks(event: E?): Boolean {
return checks.isEmpty() || let {
- var valid = true
for ((description, check) in checks) {
- valid = valid && check(event)
- if (!valid) {
- val msg = description?.let {
- "$it (${check::class.java})"
- } ?: "(${check::class.java})"
+ if (!check(event)) {
+ val startMsg = description?.let { "$it " } ?: ""
+ val msg ="$startMsg(${check::class.java})"
logger.trace { "Check: $msg did not pass" }
- break
+ return false
}
}
- valid
+ true
}
}
diff --git a/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/ActionSet.kt b/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/ActionSet.kt
index 1e713ed..c5e5ec5 100644
--- a/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/ActionSet.kt
+++ b/src/main/kotlin/org/janelia/saalfeldlab/fx/actions/ActionSet.kt
@@ -1,7 +1,5 @@
package org.janelia.saalfeldlab.fx.actions
-import io.github.oshai.kotlinlogging.KLogger
-import io.github.oshai.kotlinlogging.KotlinLogging
import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
@@ -9,7 +7,6 @@ import javafx.scene.Node
import javafx.scene.input.*
import javafx.stage.Window
import org.janelia.saalfeldlab.fx.event.KeyTracker
-import java.lang.invoke.MethodHandles
import java.util.function.Consumer
@@ -64,21 +61,19 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
apply?.let { it(this) }
}
- private fun testChecksForEventType(event: Event, eventType: EventType = event.eventType): Boolean {
- return checks[eventType]?.let { checks ->
- var pass = true
- for ((reason, check) in checks) {
- if (!check(event)) {
- ACTION_SET_LOGGER.debug { "Verify All Failed: $reason" }
- pass = false
- break
- }
+ private fun Action.testChecksForEventType(event: Event, eventType: EventType = event.eventType): Boolean {
+ val checks = checks[eventType] ?: return true
+
+ for ((reason, check) in checks) {
+ if (!check(event)) {
+ logger.debug { "Verify All Failed: $reason" }
+ return false
}
- pass
- } ?: true
+ }
+ return true
}
- private tailrec fun testChecksForInheritedEventTypes(event: Event, eventType: EventType? = event.eventType): Boolean {
+ private tailrec fun Action.testChecksForInheritedEventTypes(event: Event, eventType: EventType? = event.eventType): Boolean {
if (eventType == null) return true
return if (!testChecksForEventType(event, eventType)) false else testChecksForInheritedEventTypes(event, eventType.superType)
}
@@ -194,7 +189,7 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
/* configure via the callback*/
withAction()
- }.also { addAction(it)}
+ }.also { addAction(it) }
}
/**
@@ -300,7 +295,7 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
/* configure based on the callback */
withAction()
- }.also { addAction(it)}
+ }.also { addAction(it) }
}
/**
@@ -391,9 +386,7 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
try {
action(event)
} catch (e: Exception) {
- val logger = if (action.filter) FILTER_LOGGER else ACTION_LOGGER
- val nameText = action.name?.let { "$name: $it" } ?: name
- logger.error(e) { "$nameText (${event.eventType} was valid, but failed" }
+ action.logger.error(e) { "${event.eventType} was valid, but failed" }
throw e
}
} else {
@@ -410,7 +403,9 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
* @param action the [Action] to handle [event]
* @param event to handle
*/
- protected open fun preInvokeCheck(action: Action, event: E) = action.canHandleEvent(event.eventType) && testChecksForInheritedEventTypes(event)
+ protected open fun preInvokeCheck(action: Action, event: E) = action.run {
+ canHandleEvent(event.eventType) && testChecksForInheritedEventTypes(event)
+ }
/**
* Optional callback for before the extension functions [installActionSet] are called.
@@ -441,10 +436,6 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
companion object {
- private val ACTION_SET_LOGGER: KLogger = KotlinLogging.logger {}
- private val ACTION_LOGGER: KLogger = KotlinLogging.logger("${MethodHandles.lookup().lookupClass().name}-Action")
- private val FILTER_LOGGER: KLogger = KotlinLogging.logger("${MethodHandles.lookup().lookupClass().name}-Filter")
-
/**
* Install [actionSet] in the receiver [Node]
*
diff --git a/src/main/kotlin/org/janelia/saalfeldlab/fx/util/InvokeOnJavaFXApplicationThread.kt b/src/main/kotlin/org/janelia/saalfeldlab/fx/util/InvokeOnJavaFXApplicationThread.kt
index 8eb93fe..e72d3b7 100644
--- a/src/main/kotlin/org/janelia/saalfeldlab/fx/util/InvokeOnJavaFXApplicationThread.kt
+++ b/src/main/kotlin/org/janelia/saalfeldlab/fx/util/InvokeOnJavaFXApplicationThread.kt
@@ -28,7 +28,6 @@
*/
package org.janelia.saalfeldlab.fx.util
-import javafx.application.Platform
import kotlinx.coroutines.*
import java.lang.Runnable
@@ -42,10 +41,7 @@ class InvokeOnJavaFXApplicationThread {
operator fun invoke(task: suspend CoroutineScope.() -> Unit) = sharedMainScope.launch(block = task)
@JvmStatic
- operator fun invoke(task: Runnable) {
- if (Platform.isFxApplicationThread()) task.run()
- else invoke { task.run() }
- }
+ operator fun invoke(task: Runnable) = invoke { task.run() }
@Throws(InterruptedException::class)
fun invokeAndWait(task: suspend CoroutineScope.() -> Unit) = runBlocking {