Disabling main controls while busy

This commit is contained in:
Daniel Wolf 2018-02-07 20:01:23 +01:00
parent 0cb82f3e4e
commit 389fd0480b
3 changed files with 34 additions and 4 deletions

View File

@ -1,5 +1,7 @@
package com.rhubarb_lip_sync.rhubarb_for_spine package com.rhubarb_lip_sync.rhubarb_for_spine
import javafx.beans.binding.BooleanBinding
import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleListProperty import javafx.beans.property.SimpleListProperty
import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty import javafx.beans.property.SimpleStringProperty
@ -57,6 +59,21 @@ class AnimationFileModel(animationFilePath: Path, private val executor: Executor
} }
.observable() .observable()
) )
val audioFileModels by audioFileModelsProperty
val busyProperty = SimpleBooleanProperty().apply {
bind(object : BooleanBinding() {
init {
for (audioFileModel in audioFileModels) {
super.bind(audioFileModel.busyProperty)
}
}
override fun computeValue(): Boolean {
return audioFileModels.any { it.busy }
}
})
}
val busy by busyProperty
private fun saveAnimation(mouthCues: List<MouthCue>, audioEventName: String) { private fun saveAnimation(mouthCues: List<MouthCue>, audioEventName: String) {
val animationName = getAnimationName(audioEventName) val animationName = getAnimationName(audioEventName)
@ -66,8 +83,6 @@ class AnimationFileModel(animationFilePath: Path, private val executor: Executor
private fun getAnimationName(audioEventName: String): String = "say_$audioEventName" private fun getAnimationName(audioEventName: String): String = "say_$audioEventName"
val audioFileModels by audioFileModelsProperty
init { init {
slots = spineJson.slots.observable() slots = spineJson.slots.observable()
mouthSlot = spineJson.guessMouthSlot() mouthSlot = spineJson.guessMouthSlot()

View File

@ -1,6 +1,7 @@
package com.rhubarb_lip_sync.rhubarb_for_spine package com.rhubarb_lip_sync.rhubarb_for_spine
import javafx.application.Platform import javafx.application.Platform
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.ObjectBinding import javafx.beans.binding.ObjectBinding
import javafx.beans.binding.StringBinding import javafx.beans.binding.StringBinding
import javafx.beans.property.SimpleBooleanProperty import javafx.beans.property.SimpleBooleanProperty
@ -66,6 +67,19 @@ class AudioFileModel(
} }
private val audioFileState by audioFileStateProperty private val audioFileState by audioFileStateProperty
val busyProperty = SimpleBooleanProperty().apply {
bind(object : BooleanBinding() {
init {
super.bind(futureProperty)
}
override fun computeValue(): Boolean {
return future != null
}
})
}
val busy by busyProperty
val statusLabelProperty = SimpleStringProperty().apply { val statusLabelProperty = SimpleStringProperty().apply {
bind(object : StringBinding() { bind(object : StringBinding() {
init { init {

View File

@ -35,6 +35,7 @@ class MainView : View() {
minWidth = 800.0 minWidth = 800.0
prefWidth = 1000.0 prefWidth = 1000.0
fieldset("Settings") { fieldset("Settings") {
disableProperty().bind(fileModelProperty.select { it!!.busyProperty })
field("Spine JSON file") { field("Spine JSON file") {
filePathTextField = textfield { filePathTextField = textfield {
textProperty().bindBidirectional(mainModel.filePathStringProperty) textProperty().bindBidirectional(mainModel.filePathStringProperty)
@ -123,13 +124,13 @@ class MainView : View() {
} }
onDragOver = EventHandler<DragEvent> { event -> onDragOver = EventHandler<DragEvent> { event ->
if (event.dragboard.hasFiles()) { if (event.dragboard.hasFiles() && mainModel.animationFileModel?.busy != true) {
event.acceptTransferModes(TransferMode.COPY) event.acceptTransferModes(TransferMode.COPY)
event.consume() event.consume()
} }
} }
onDragDropped = EventHandler<DragEvent> { event -> onDragDropped = EventHandler<DragEvent> { event ->
if (event.dragboard.hasFiles()) { if (event.dragboard.hasFiles() && mainModel.animationFileModel?.busy != true) {
filePathTextField!!.text = event.dragboard.files.firstOrNull()?.path filePathTextField!!.text = event.dragboard.files.firstOrNull()?.path
event.isDropCompleted = true event.isDropCompleted = true
event.consume() event.consume()