105 lines
2.7 KiB
Kotlin
105 lines
2.7 KiB
Kotlin
package org.hso.texturesyncclient.view.mainView
|
|
|
|
import javafx.collections.ObservableList
|
|
import javafx.scene.image.Image
|
|
import org.hso.texturesyncclient.model.GUIModel
|
|
import org.hso.texturesyncclient.model.TextureFormat
|
|
import tornadofx.Controller
|
|
import javafx.stage.DirectoryChooser
|
|
import org.hso.texturesyncclient.controller.RootController
|
|
import tornadofx.clear
|
|
import javax.swing.JColorChooser.showDialog
|
|
import java.io.File
|
|
|
|
|
|
class MainViewController : Controller() {
|
|
|
|
private val mv = find(MainView::class)
|
|
private val rootc = find(RootController::class)
|
|
|
|
// FolderView elements
|
|
private val folderView = mv.folderView.root
|
|
|
|
// DetailView elements
|
|
private val preview = mv.detailView.preview
|
|
private val metaLabel = mv.detailView.metaLabel
|
|
private val cvTags = mv.detailView.cvTags
|
|
|
|
|
|
// FolderView functions
|
|
fun addElement(element: GUIModel) {
|
|
folderView.children.add(element)
|
|
}
|
|
|
|
fun addAllElements(elementList: ArrayList<GUIModel>) {
|
|
folderView.children.addAll(elementList)
|
|
}
|
|
|
|
|
|
// DetailView functions
|
|
fun setPreview3DTexture(img: Image) {
|
|
preview.setTexture(img)
|
|
}
|
|
|
|
fun setMeta(name: String, res: String, etc: String) {
|
|
metaLabel.text = "Name: $name\nAuflösung: $res\nAnderes: $etc"
|
|
}
|
|
|
|
fun setTags(chips: ObservableList<String>) {
|
|
cvTags.chips.clear()
|
|
cvTags.chips.addAll(chips)
|
|
}
|
|
|
|
// update the tags for the selected element
|
|
fun updateTags() {
|
|
println(cvTags.chips)
|
|
}
|
|
|
|
|
|
/**
|
|
* save the texture file to r
|
|
* @param data the file as a byte array
|
|
* @param name name for the file
|
|
* @param format specific file format. jpeg or png
|
|
*/
|
|
fun exportTexture(data: ByteArray, name: String, format : TextureFormat){
|
|
|
|
|
|
val directoryChooser = DirectoryChooser()
|
|
|
|
directoryChooser.title = "Export Verzeichnis wählen"
|
|
|
|
// TODO directoryChooser.setInitialDirectory(new File(System.getProperty("user.home")))
|
|
|
|
val dir = directoryChooser.showDialog(primaryStage)
|
|
|
|
if (dir != null) {
|
|
|
|
//copy data (bytesarray) with name and extension to dir
|
|
|
|
}
|
|
}
|
|
|
|
fun cvSearchAction(tags: ObservableList<String>) {
|
|
var previewList = arrayListOf<GUIModel>()
|
|
|
|
// show spinner, block ui
|
|
folderView.children.clear()
|
|
folderView.children.add(mv.spinnerSearch)
|
|
mv.spinnerSearch.isVisible = true
|
|
mv.cvSearch.isDisable = true
|
|
|
|
runAsync {
|
|
previewList = rootc.search(tags)
|
|
} ui {
|
|
// when search finished
|
|
folderView.children.clear()
|
|
addAllElements(previewList)
|
|
mv.spinnerSearch.isVisible = false
|
|
mv.cvSearch.isDisable = false
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |