From 19a6b775298977405e4aa09fd2f8ac7d644e7eba Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Fri, 9 Feb 2018 23:23:37 +0100 Subject: [PATCH] Nicely visualizing progress --- .../rhubarb_for_spine/AudioFileModel.kt | 22 +-------- .../rhubarb_for_spine/MainView.kt | 47 +++++++++++++++++-- 2 files changed, 46 insertions(+), 23 deletions(-) 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 0a01c84..497acc6 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 @@ -69,7 +69,7 @@ class AudioFileModel( private val futureProperty = SimpleObjectProperty?>() private var future by futureProperty - private val audioFileStateProperty = SimpleObjectProperty().apply { + val audioFileStateProperty = SimpleObjectProperty().apply { bind(object : ObjectBinding() { init { super.bind(animatedProperty, futureProperty, animationProgressProperty) @@ -92,7 +92,7 @@ class AudioFileModel( } }) } - private val audioFileState by audioFileStateProperty + val audioFileState by audioFileStateProperty val busyProperty = SimpleBooleanProperty().apply { bind(object : BooleanBinding() { @@ -107,24 +107,6 @@ class AudioFileModel( } val busy by busyProperty - val statusLabelProperty = SimpleStringProperty().apply { - bind(object : StringBinding() { - init { - super.bind(audioFileStateProperty) - } - override fun computeValue(): String { - return when (audioFileState.status) { - AudioFileStatus.NotAnimated -> "Not animated" - AudioFileStatus.Pending -> "Waiting" - AudioFileStatus.Animating -> "${((animationProgress ?: 0.0) * 100).toInt()}%" - AudioFileStatus.Canceling -> "Canceling" - AudioFileStatus.Done -> "Done" - } - } - }) - } - val statusLabel by statusLabelProperty - val actionLabelProperty = 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 cc4ab47..978fadc 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 @@ -1,14 +1,18 @@ package com.rhubarb_lip_sync.rhubarb_for_spine -import javafx.beans.binding.Bindings import javafx.beans.property.Property import javafx.beans.property.SimpleBooleanProperty import javafx.beans.property.SimpleStringProperty import javafx.event.ActionEvent import javafx.event.EventHandler +import javafx.geometry.Pos import javafx.scene.control.* import javafx.scene.input.DragEvent import javafx.scene.input.TransferMode +import javafx.scene.layout.* +import javafx.scene.paint.Color +import javafx.scene.text.Font +import javafx.scene.text.FontWeight import javafx.scene.text.Text import javafx.stage.FileChooser import tornadofx.* @@ -110,8 +114,45 @@ class MainView : View() { } } } - column("Status", AudioFileModel::statusLabelProperty) - .weigthedWidth(1.0) + column("Status", AudioFileModel::audioFileStateProperty).apply { + weigthedWidth(1.0) + setCellFactory { tableColumn -> + return@setCellFactory object : TableCell() { + override fun updateItem(state: AudioFileState?, empty: Boolean) { + super.updateItem(state, empty) + graphic = if (state != null) { + when (state.status) { + AudioFileStatus.NotAnimated -> Text("Not animated").apply { + fill = Color.GRAY + } + AudioFileStatus.Pending -> ProgressBar().apply { + progress = -1.0 // Indeterminate + maxWidth = Double.MAX_VALUE + } + AudioFileStatus.Animating -> HBox().apply { + val progress = state.progress ?: 0.0 + val bar = progressbar(progress) { + maxWidth = Double.MAX_VALUE + } + HBox.setHgrow(bar, Priority.ALWAYS) + val progressString = "${(progress * 100).toInt()}%" + hbox { + minWidth = 30.0 + text(progressString) { + alignment = Pos.BASELINE_RIGHT + } + } + } + AudioFileStatus.Canceling -> Text("Canceling") + AudioFileStatus.Done -> Text("Done").apply { + font = Font.font(font.family, FontWeight.BOLD, font.size) + } + } + } else null + } + } + } + } column("", AudioFileModel::actionLabelProperty).apply { weigthedWidth(1.0) // Show button