Skip to content

Instantly share code, notes, and snippets.

@MairwunNx
Created December 5, 2018 15:59
Show Gist options
  • Save MairwunNx/9ea43c8dbbe8a97d9fd443907bfdc162 to your computer and use it in GitHub Desktop.
Save MairwunNx/9ea43c8dbbe8a97d9fd443907bfdc162 to your computer and use it in GitHub Desktop.
Dialog opening with Kotlin.
val alert = Alert(Alert.AlertType.CONFIRMATION)
alert.title = "Overwriting Balance File"
alert.contentText = "You has opened balance.bin file, you want to save current session file?"
val okButton = ButtonType("Yes", ButtonBar.ButtonData.YES)
val noButton = ButtonType("No", ButtonBar.ButtonData.NO)
val cancelButton = ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE)
alert.buttonTypes.setAll(okButton, noButton, cancelButton)
alert.showAndWait().ifPresent { type ->
if (type == ButtonType.OK) {
// todo: Save current session file changes and show create new dialog
ApplicationLogger().logger.info("OK Clicked!")
}
if (type == ButtonType.NO.apply {
val saveDialog = FileDialog(Frame(), "Select File Directory", FileDialog.SAVE)
saveDialog.file = "balance.bin"
saveDialog.isVisible = true
if (saveDialog.directory != null || saveDialog.file != null) {
val filePath = saveDialog.directory + saveDialog.file
val initialStream = (javaClass.getResourceAsStream("etc/balance.bin"))
File(filePath).outputStream().use { initialStream.copyTo(it) }
filePathTextField.text = filePath
fileIsOpened = true
}
})
if (type == ButtonType.NO) {
val saveDialog = FileDialog(Frame(), "Select File Directory", FileDialog.SAVE)
saveDialog.file = "balance.bin"
saveDialog.isVisible = true
if (saveDialog.directory != null || saveDialog.file != null) {
val filePath = saveDialog.directory + saveDialog.file
val initialStream = (javaClass.getResourceAsStream("etc/balance.bin"))
File(filePath).outputStream().use { initialStream.copyTo(it) }
filePathTextField.text = filePath
fileIsOpened = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment