All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.maizegenetics.gui.FileChooserUtils.kt Maven / Gradle / Ivy

@file:JvmName("FileChooserUtils")

package net.maizegenetics.gui

import javafx.application.Platform
import javafx.concurrent.Task
import javafx.stage.FileChooser
import net.maizegenetics.prefs.TasselPrefs
import net.maizegenetics.tassel.TASSELGUI
import java.io.File

/**
 * @author Terry Casstevens
 * Created November 05, 2018
 */

private val open = FileChooser().also {
    it.initialDirectory = File(TasselPrefs.getOpenDir())
}

fun singeFile(): File? {

    val task = object : Task() {
        override fun call(): File? {
            return open.showOpenDialog(TASSELGUI.instance.primaryStage)
        }
    }
    Platform.runLater(task)
    val result = task.get()

    if (result != null) {
        TasselPrefs.putOpenDir(result.absolutePath.substringBeforeLast('/'))
    }

    return result

}

fun multipleFiles(): List? {

    val task = object : Task?>() {
        override fun call(): List? {
            return open.showOpenMultipleDialog(TASSELGUI.instance.primaryStage)
        }
    }
    Platform.runLater(task)
    val result = task.get()

    if (result != null) {
        TasselPrefs.putOpenDir(result[0].absolutePath.substringBeforeLast('/'))
    }

    return result

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy