TextureSync/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt

84 lines
2.6 KiB
Kotlin

package org.hso.texturesyncclient.view.mainView
import javafx.collections.ObservableList
import javafx.scene.image.Image
import org.hso.texturesyncclient.model.GUIModel
import tornadofx.Controller
import org.hso.texturesyncclient.controller.RootController
import org.hso.texturesyncclient.model.Texture
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
private var lockUpdate: Boolean = false //lock update func when the system changes the detailview chipview
// 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, format: String, date: String) {
metaLabel.text = "Name: $name\nAuflösung: $res\nFormat: $format\nEinfügedatum: $date"
}
fun setTags(chips: ObservableList<String>) {
lockUpdate = false //dont trigger update with onChange
cvTags.chips.clear()
cvTags.chips.addAll(chips)
lockUpdate = true //allow update with onChange
}
fun updateTags() {
if (lockUpdate) { //the chipView was changed by the user
println("Tags changed")
rootc.updateTexture(cvTags.chips)
}
}
// DetailView actions
fun cvSearchAction(tags: ObservableList<String>) {
// show spinner, block ui
folderView.children.clear()
mv.cvSearch.isDisable = true
setPreview3DTexture(Image("icons/TextureSync_Icon_256x256.jpeg")) // reset the 3DPreview to the logo
runAsync {
rootc.queryElements(tags)
} ui {
// when search finished
mv.cvSearch.isDisable = false
}
}
fun btnImportAction() {
rootc.switchMainToImport()
}
fun removeTextureFromView(data: Texture) {
// stream all children nodes, filter them as GUIModel with data.id == data.id, for any found object if it's still present remove it from the folderView
folderView.children.stream().filter { x -> (x as GUIModel).data.id == data.id }.findAny()
.ifPresent { x -> folderView.children.remove(x) }
}
}