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-04 18:20:09 +02:00
import org.hso.texturesyncclient.controller.RootController
2019-06-13 00:10:00 +02:00
import org.hso.texturesyncclient.model.GUIModel
2019-06-05 22:33:37 +02:00
import org.hso.texturesyncclient.model.Texture
2019-06-13 00:10:00 +02:00
import tornadofx.Controller
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 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 ) {
2019-06-13 00:10:00 +02:00
with ( mv . detailView ) {
2019-06-12 21:05:40 +02:00
nameInfo . text = name
formatInfo . text = format
2019-06-13 18:37:07 +02:00
resolutionInfo . text = res
2019-06-12 21:05:40 +02:00
dateInfo . text = 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-13 00:10:00 +02:00
fun getTags ( ) : ObservableList < String > {
2019-06-08 21:59:09 +02:00
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 " )
2019-06-13 00:10:00 +02:00
rootc . updateTexture (
tags = cvTags . chips . toTypedArray ( ) ,
name = mv . detailView . nameInfo . text
)
2019-06-08 12:47:34 +02:00
}
2019-05-09 15:24:45 +02:00
}
2019-06-14 11:18:58 +02:00
// MainView actions
2019-06-05 16:23:45 +02:00
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-13 21:22:42 +02:00
RootController . selectedTexture = null
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-13 00:10:00 +02:00
fun setVisibleMetaTags ( bool : Boolean ) {
if ( bool ) {
2019-06-12 21:05:40 +02:00
mv . detailView . metadataPanel . isVisible = true
2019-06-13 21:43:43 +02:00
mv . detailView . btnSubmit . isVisible = false
2019-06-08 22:09:43 +02:00
cvTags . isVisible = true
2019-06-13 00:10:00 +02:00
} else {
2019-06-12 21:05:40 +02:00
mv . detailView . metadataPanel . isVisible = false
2019-06-13 21:43:43 +02:00
mv . detailView . btnSubmit . isVisible = false
2019-06-08 22:09:43 +02:00
cvTags . isVisible = false
}
}
2019-06-10 12:41:11 +02:00
fun scExport ( ) {
2019-06-13 21:22:42 +02:00
RootController . selectedTexture ?. let { rootc . exportTexture ( RootController . selectedTexture !! ) }
2019-06-10 12:41:11 +02:00
}
2019-04-30 16:49:02 +02:00
}