TextureSync/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt

32 lines
1.2 KiB
Kotlin

package org.hso.texturesyncclient.view.importView
import javafx.stage.FileChooser.ExtensionFilter
import org.hso.texturesyncclient.controller.RootController
import tornadofx.Controller
import tornadofx.FileChooserMode
import tornadofx.chooseFile
class ImportViewController : Controller() {
private val iv = find(ImportView::class)
private val rootc = find(RootController::class)
fun btnFileChooserAction() {
val list = listOf("*.png", "*.PNG", "*.jpg", "*.JPG", "*.jpeg", "*.JPEG")
val arrayFilter = arrayOf(ExtensionFilter("Texturen vom Bildformat: PNG oder JPG", list))
val file = chooseFile("Textur auswählen", arrayFilter, FileChooserMode.Single, owner = null)
if (file.isNotEmpty()) {
iv.tfFilePath.text = file[0].absolutePath
iv.tfName.text = file[0].nameWithoutExtension
}
}
fun btnImportAction() {
rootc.importTexture(iv.tfFilePath.text, iv.tfName.text, iv.cvTags.chips)
}
fun validateImport() {
iv.btnImport.isVisible = iv.tfFilePath.text.isNotEmpty() && iv.tfName.text.isNotEmpty() && iv.cvTags.chips.isNotEmpty() && iv.cvTags.chips.stream().allMatch { x -> x.length < 32 }
}
}