2019-04-30 16:49:02 +02:00
package org.hso.texturesyncclient.view.mainView
2019-05-09 15:24:45 +02:00
import javafx.collections.ObservableList
import javafx.scene.image.Image
2019-06-03 15:29:01 +02:00
import org.hso.texturesyncclient.model.GUIModel
2019-04-30 16:49:02 +02:00
import tornadofx.Controller
2019-06-04 18:20:09 +02:00
import org.hso.texturesyncclient.controller.RootController
2019-06-05 22:33:37 +02:00
import org.hso.texturesyncclient.model.Texture
2019-06-03 22:24:18 +02:00
2019-04-30 16:49:02 +02:00
class MainViewController : Controller ( ) {
2019-05-09 15:24:45 +02:00
private val mv = find ( MainView :: class )
2019-06-04 18:20:09 +02:00
private val rootc = find ( RootController :: class )
2019-05-09 15:24:45 +02:00
// FolderView elements
2019-06-03 15:29:01 +02:00
private val folderView = mv . folderView . root
2019-05-09 15:24:45 +02:00
// DetailView elements
private val preview = mv . detailView . preview
private val metaLabel = mv . detailView . metaLabel
private val cvTags = mv . detailView . cvTags
2019-06-08 12:47:34 +02:00
private var lockUpdate : Boolean = false //lock update func when the system changes the detailview chipview
2019-05-09 15:24:45 +02:00
2019-06-03 15:29:01 +02:00
// FolderView functions
fun addElement ( element : GUIModel ) {
2019-06-03 16:46:57 +02:00
folderView . children . add ( element )
}
2019-06-03 15:29:01 +02:00
// DetailView functions
2019-05-09 15:24:45 +02:00
fun setPreview3DTexture ( img : Image ) {
preview . setTexture ( img )
}
2019-06-08 13:31:29 +02:00
fun setMeta ( name : String , res : String , format : String , date : String ) {
metaLabel . text = " Name: $name \n Auflösung: $res \n Format: $format \n Einfügedatum: $date "
2019-05-09 15:24:45 +02:00
}
fun setTags ( chips : ObservableList < String > ) {
2019-06-08 12:47:34 +02:00
lockUpdate = false //dont trigger update with onChange
2019-05-09 15:24:45 +02:00
cvTags . chips . clear ( )
cvTags . chips . addAll ( chips )
2019-06-08 12:47:34 +02:00
lockUpdate = true //allow update with onChange
2019-05-09 15:24:45 +02:00
}
2019-06-08 21:59:09 +02:00
fun getTags ( ) : ObservableList < String > {
return cvTags . chips
}
2019-05-09 15:24:45 +02:00
fun updateTags ( ) {
2019-06-08 12:47:34 +02:00
if ( lockUpdate ) { //the chipView was changed by the user
println ( " Tags changed " )
rootc . updateTexture ( cvTags . chips )
}
2019-05-09 15:24:45 +02:00
}
2019-06-05 16:23:45 +02:00
// DetailView actions
2019-06-04 18:20:09 +02:00
fun cvSearchAction ( tags : ObservableList < String > ) {
// show spinner, block ui
folderView . children . clear ( )
mv . cvSearch . isDisable = true
2019-06-08 14:27:11 +02:00
setPreview3DTexture ( Image ( " icons/TextureSync_Icon_256x256.jpeg " ) ) // reset the 3DPreview to the logo
2019-06-04 18:20:09 +02:00
2019-06-05 22:33:37 +02:00
runAsync {
2019-06-07 16:19:04 +02:00
rootc . queryElements ( tags )
2019-06-05 22:33:37 +02:00
} ui {
// when search finished
mv . cvSearch . isDisable = false
}
2019-06-03 22:24:18 +02:00
}
2019-06-05 16:23:45 +02:00
fun btnImportAction ( ) {
2019-06-09 13:38:11 +02:00
RootController . switchMainToImport ( )
2019-06-05 16:23:45 +02:00
}
2019-06-04 18:20:09 +02:00
2019-06-05 22:33:37 +02:00
fun removeTextureFromView ( data : Texture ) {
2019-06-07 13:48:42 +02:00
// 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
2019-06-08 12:47:34 +02:00
folderView . children . stream ( ) . filter { x -> ( x as GUIModel ) . data . id == data . id } . findAny ( )
. ifPresent { x -> folderView . children . remove ( x ) }
2019-06-05 22:33:37 +02:00
}
2019-06-08 22:09:43 +02:00
fun setVisibleMetaTags ( bool : Boolean ) {
if ( bool ) {
metaLabel . isVisible = true
cvTags . isVisible = true
} else {
metaLabel . isVisible = false
cvTags . isVisible = false
}
}
2019-04-30 16:49:02 +02:00
}