Skip to content

Instantly share code, notes, and snippets.

@ValeriusGC
Created February 7, 2018 13:40
Show Gist options
  • Save ValeriusGC/e9201f78b21cc3c8758a8a1467899306 to your computer and use it in GitHub Desktop.
Save ValeriusGC/e9201f78b21cc3c8758a8a1467899306 to your computer and use it in GitHub Desktop.
ANother tornadofx sample
package com.gdetotut.sample.chapter_02
import javafx.application.Application
import javafx.geometry.Insets
import javafx.scene.paint.Color
import javafx.scene.text.FontWeight
import tornadofx.*
class AsyncProgressApp : App(AsyncProgressView::class)
fun main(args: Array<String>) {
Application.launch(AsyncProgressApp::class.java, *args)
}
class AsyncProgressView : View("Async Progress") {
override val root = borderpane {
setPrefSize(400.0, 300.0)
padding = Insets(5.0)
center {
button("Start") {
action {
runAsync {
updateTitle("Doing some work")
for (i in 1..10) {
updateMessage("Working $i...")
if (i == 5)
updateTitle("Dome something else")
Thread.sleep(500)
updateProgress(i.toLong(), 10)
}
}
}
}
}
bottom {
hbox(5) {
add<ProgressView>()
add<ProgressView2>()
}
}
}
}
class ProgressView : View() {
val status: TaskStatus by inject()
override val root = vbox(4) {
visibleWhen { status.running }
style { borderColor += box(Color.LIGHTGREY, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) }
label(status.title).style { fontWeight = FontWeight.BOLD }
hbox(4) {
label(status.message)
progressbar(status.progress)
visibleWhen { status.running }
}
}
}
class ProgressView2 : View() {
val status: TaskStatus by inject()
override val root = vbox(4) {
visibleWhen { status.running }
style { borderColor += box(Color.AQUAMARINE, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) }
label(status.title).style { fontWeight = FontWeight.BOLD }
hbox(4) {
label(status.message)
progressbar(status.progress)
visibleWhen { status.running }
}
}
}
class AsyncProgressButtonView : View() {
override val root = stackpane {
setPrefSize(400.0, 400.0)
button("Click me") {
action {
runAsyncWithProgress {
Thread.sleep(2000)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment