From 389fd0480be9b020ab0787fdec36ad0bfd3e8e97 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Wed, 7 Feb 2018 20:01:23 +0100 Subject: [PATCH] Disabling main controls while busy --- .../rhubarb_for_spine/AnimationFileModel.kt | 19 +++++++++++++++++-- .../rhubarb_for_spine/AudioFileModel.kt | 14 ++++++++++++++ .../rhubarb_for_spine/MainView.kt | 5 +++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt index 005c784..53f496e 100644 --- a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt +++ b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt @@ -1,5 +1,7 @@ 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.SimpleObjectProperty import javafx.beans.property.SimpleStringProperty @@ -57,6 +59,21 @@ class AnimationFileModel(animationFilePath: Path, private val executor: Executor } .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, audioEventName: String) { val animationName = getAnimationName(audioEventName) @@ -66,8 +83,6 @@ class AnimationFileModel(animationFilePath: Path, private val executor: Executor private fun getAnimationName(audioEventName: String): String = "say_$audioEventName" - val audioFileModels by audioFileModelsProperty - init { slots = spineJson.slots.observable() mouthSlot = spineJson.guessMouthSlot() diff --git a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt index fb4b66e..0bf6076 100644 --- a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt +++ b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt @@ -1,6 +1,7 @@ package com.rhubarb_lip_sync.rhubarb_for_spine import javafx.application.Platform +import javafx.beans.binding.BooleanBinding import javafx.beans.binding.ObjectBinding import javafx.beans.binding.StringBinding import javafx.beans.property.SimpleBooleanProperty @@ -66,6 +67,19 @@ class AudioFileModel( } 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 { bind(object : StringBinding() { init { diff --git a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt index f43822f..76a0823 100644 --- a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt +++ b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt @@ -35,6 +35,7 @@ class MainView : View() { minWidth = 800.0 prefWidth = 1000.0 fieldset("Settings") { + disableProperty().bind(fileModelProperty.select { it!!.busyProperty }) field("Spine JSON file") { filePathTextField = textfield { textProperty().bindBidirectional(mainModel.filePathStringProperty) @@ -123,13 +124,13 @@ class MainView : View() { } onDragOver = EventHandler { event -> - if (event.dragboard.hasFiles()) { + if (event.dragboard.hasFiles() && mainModel.animationFileModel?.busy != true) { event.acceptTransferModes(TransferMode.COPY) event.consume() } } onDragDropped = EventHandler { event -> - if (event.dragboard.hasFiles()) { + if (event.dragboard.hasFiles() && mainModel.animationFileModel?.busy != true) { filePathTextField!!.text = event.dragboard.files.firstOrNull()?.path event.isDropCompleted = true event.consume()