Shutting down executor service to that application can exit cleanly

This commit is contained in:
Daniel Wolf 2018-02-02 22:02:34 +01:00
parent 34610d0572
commit 6e5af62be7
3 changed files with 12 additions and 7 deletions

View File

@ -8,9 +8,9 @@ import java.nio.file.Path
import tornadofx.getValue
import tornadofx.observable
import tornadofx.setValue
import java.util.concurrent.Executors
import java.util.concurrent.ExecutorService
class AnimationFileModel(animationFilePath: Path) {
class AnimationFileModel(animationFilePath: Path, private val executor: ExecutorService) {
val spineJson = SpineJson(animationFilePath)
val slotsProperty = SimpleObjectProperty<ObservableList<String>>()
@ -50,7 +50,6 @@ class AnimationFileModel(animationFilePath: Path) {
var mouthShapesError by mouthShapesErrorProperty
private set
private val executor = Executors.newSingleThreadExecutor()
val audioFileModelsProperty = SimpleListProperty<AudioFileModel>(
spineJson.audioEvents
.map { event ->

View File

@ -8,8 +8,9 @@ import tornadofx.setValue
import java.nio.file.Files
import java.nio.file.InvalidPathException
import java.nio.file.Paths
import java.util.concurrent.ExecutorService
class MainModel {
class MainModel(private val executor: ExecutorService) {
val filePathStringProperty = SimpleStringProperty(getDefaultPathString()).alsoListen { value ->
filePathError = getExceptionMessage {
animationFileModel = null
@ -28,7 +29,7 @@ class MainModel {
throw Exception("File does not exist.")
}
animationFileModel = AnimationFileModel(path)
animationFileModel = AnimationFileModel(path, executor)
}
}
var filePathString by filePathStringProperty

View File

@ -14,10 +14,11 @@ import tornadofx.*
import java.io.File
import java.time.LocalDate
import java.time.Period
import java.util.concurrent.Executors
class MainView : View() {
val mainModel = MainModel()
private val executor = Executors.newSingleThreadExecutor()
private val mainModel = MainModel(executor)
class Person(val id: Int, val name: String, val birthday: LocalDate) {
val age: Int get() = Period.between(birthday, LocalDate.now()).years
@ -119,6 +120,10 @@ class MainView : View() {
}
}
whenUndocked {
executor.shutdownNow()
}
filePathButton!!.onAction = EventHandler<ActionEvent> {
val fileChooser = FileChooser().apply {
title = "Open Spine JSON file"