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

55 lines
1.7 KiB
Kotlin

package org.hso.texturesyncclient.view.importView
import org.hso.texturesyncclient.controller.RootController
import tornadofx.Controller
import javafx.stage.FileChooser
import java.io.File
class ImportViewController : Controller() {
private val iv = find(ImportView::class)
private val rootc = find(RootController::class)
private var lastImportDir: String = System.getProperty("user.home")
fun btnFileChooserAction() {
val fileChooser = FileChooser()
val fileExtensions = FileChooser.ExtensionFilter(
"Texturen vom Bildformat: PNG oder JPEG", "*.png", "*.PNG", "*.jpg", "*.JPG", "*.jpeg", "*.JPEG"
)
fileChooser.extensionFilters.addAll(fileExtensions)
fileChooser.initialDirectory = File(lastImportDir)
fileChooser.title = "Textur auswählen"
val file = fileChooser.showOpenDialog(null)
if (file != null) {
iv.tfFilePath.text = file.absolutePath
iv.tfName.text = file.nameWithoutExtension
lastImportDir = file.parent.toString() //store last user chosen dir
}
}
fun btnImportAction() {
rootc.importTexture(iv.tfFilePath.text, iv.tfName.text, iv.cvTags.chips)
RootController.switchImportToMain()
iv.tfFilePath.clear()
iv.tfName.clear()
iv.cvTags.chips.clear()
}
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 }
}
fun btnBackAction() {
RootController.switchImportToMain()
iv.tfFilePath.clear()
iv.tfName.clear()
iv.cvTags.chips.clear()
}
}