Nicely visualizing progress

This commit is contained in:
Daniel Wolf 2018-02-09 23:23:37 +01:00
parent b75a3ca1d9
commit 19a6b77529
2 changed files with 46 additions and 23 deletions

View File

@ -69,7 +69,7 @@ class AudioFileModel(
private val futureProperty = SimpleObjectProperty<Future<*>?>()
private var future by futureProperty
private val audioFileStateProperty = SimpleObjectProperty<AudioFileState>().apply {
val audioFileStateProperty = SimpleObjectProperty<AudioFileState>().apply {
bind(object : ObjectBinding<AudioFileState>() {
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 {

View File

@ -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<AudioFileModel, AudioFileState>() {
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