From e78e7e3a59d4fe53c6bfe2badac2370f0495c75d Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 4 Jun 2019 18:20:09 +0200 Subject: [PATCH] query images and show result --- client/build.gradle | 1 - .../org/hso/texturesyncclient/app/Main.kt | 1 + .../controller/Controller.kt | 49 ++++++++++++++++--- .../hso/texturesyncclient/model/GUIModel.kt | 9 ++++ .../model/GUIModelController.kt | 17 +++++++ .../view/mainView/FolderView.kt | 3 +- .../view/mainView/MainView.kt | 43 ++++++++++++---- .../view/mainView/MainViewController.kt | 24 ++++++++- .../view/startupView/StartupViewController.kt | 5 +- 9 files changed, 131 insertions(+), 21 deletions(-) create mode 100644 client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt diff --git a/client/build.gradle b/client/build.gradle index d74478e..e3b66ee 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -26,7 +26,6 @@ repositories { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1" implementation "no.tornado:tornadofx:$tornadofx_version" implementation "com.jfoenix:jfoenix:8.0.8" implementation 'com.google.code.gson:gson:2.8.5' diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt b/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt index a2b0341..838d174 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt @@ -3,6 +3,7 @@ package org.hso.texturesyncclient.app import org.hso.texturesyncclient.controller.RootController import org.hso.texturesyncclient.view.importView.ImportView import org.hso.texturesyncclient.view.mainView.MainView +import org.hso.texturesyncclient.view.mainView.MainViewController import org.hso.texturesyncclient.view.startupView.StartupView import tornadofx.App diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt index fa5d9a5..feb76f6 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -1,7 +1,9 @@ package org.hso.texturesyncclient.controller import javafx.collections.ObservableList +import javafx.stage.DirectoryChooser import org.hso.texturesyncclient.controller.net.Connection +import org.hso.texturesyncclient.model.GUIModel import org.hso.texturesyncclient.model.Sha256 import org.hso.texturesyncclient.model.Texture import org.hso.texturesyncclient.model.TextureFormat @@ -11,6 +13,8 @@ import org.hso.texturesyncclient.view.mainView.MainViewController import org.hso.texturesyncclient.view.startupView.StartupView import org.hso.texturesyncclient.view.startupView.StartupViewController import tornadofx.Controller +import tornadofx.observable +import tornadofx.observableList import java.net.InetAddress import java.util.Calendar import java.io.File @@ -85,18 +89,51 @@ class RootController : Controller() { con.ping() println("Connection successful") - // TODO store server ip for next start - - - // switch to MainView - find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) - } catch (e: Exception) { println(e) } } + fun search(tags: ObservableList): ArrayList { + val previewList = arrayListOf() + + try { + con.query(tags.toTypedArray()).forEach { + previewList.add(GUIModel(it, con.getTexturePreview(it.textureHash))) + } + } catch (e: Exception) { + println(e) + } + + println(previewList.size) + + return previewList + } + + + fun switchToMainView(){ + find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + } + + fun exportTexture(data: Texture) { + val directoryChooser = DirectoryChooser() + directoryChooser.title = "Export Verzeichnis wählen" + directoryChooser.initialDirectory = File(System.getProperty("user.home")) + + val dir = directoryChooser.showDialog(primaryStage) + if (dir != null) { + + // TODO copy data (bytesarray) with name and extension to dir + + } + } + + fun showDetail(data: Texture) { + mvc.setPreview3DTexture(con.getTexturePreview(data.textureHash)) + mvc.setMeta(data.name, data.resolution.toString(), "") + mvc.setTags(data.tags.toList().observable()) + } } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt index 5f568bf..19f21ca 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt @@ -12,6 +12,8 @@ import javafx.scene.layout.BackgroundFill import javafx.scene.layout.CornerRadii import javafx.scene.layout.VBox import javafx.scene.paint.Paint +import org.hso.texturesyncclient.controller.RootController +import org.hso.texturesyncclient.view.mainView.MainViewController import tornadofx.* class GUIModel constructor(data: Texture, img: Image) : VBox(){ @@ -21,9 +23,12 @@ class GUIModel constructor(data: Texture, img: Image) : VBox(){ private var contextMenu = ContextMenu() var exportItem = MenuItem("exportiern") + private val gmc = find(GUIModelController::class) + init { super.getChildren().addAll(image, label) super.setOnContextMenuRequested { p0 -> contextMenu.show(this@GUIModel, p0.screenX, p0.screenY) } + super.setOnMouseClicked{ gmc.previewSelectedAction(data) } label.paddingTop = 5.0 label.prefWidth = 128.0 @@ -35,6 +40,10 @@ class GUIModel constructor(data: Texture, img: Image) : VBox(){ image.fitWidth = 128.0 image.image = img + exportItem.setOnAction { + gmc.export(data) + } + contextMenu.items.add(exportItem) } diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt new file mode 100644 index 0000000..105b7cf --- /dev/null +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt @@ -0,0 +1,17 @@ +package org.hso.texturesyncclient.model + +import org.hso.texturesyncclient.controller.RootController +import tornadofx.Controller + +class GUIModelController: Controller() { + + private val rootc = find(RootController::class) + + fun export(data: Texture) { + rootc.exportTexture(data) + } + + fun previewSelectedAction(data: Texture) { + rootc.showDetail(data) + } +} \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt index 22ef8d6..e2d48fa 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt @@ -13,7 +13,8 @@ class FolderView : View("FolderView"){ hgap = 10.0 vgap = 10.0 paddingAll = 5.0 - prefWidth = 750.0 + prefWidth = 732.0 + prefHeight = 1000.0 background = Background(BackgroundFill(Paint.valueOf("#cfcfcf"), CornerRadii.EMPTY, Insets.EMPTY)) style { diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt index e2ad7bc..3525b3d 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt @@ -1,11 +1,21 @@ package org.hso.texturesyncclient.view.mainView +import com.jfoenix.controls.JFXChipView +import com.jfoenix.controls.JFXSpinner +import com.jfoenix.controls.JFXTextField import javafx.collections.ListChangeListener +import javafx.geometry.Insets import javafx.scene.image.Image +import javafx.scene.layout.Background +import javafx.scene.layout.BackgroundFill +import javafx.scene.layout.CornerRadii +import javafx.scene.paint.Paint import tornadofx.* class MainView : View() { + val cvSearch = JFXChipView() + val spinnerSearch = JFXSpinner() val folderView = find(FolderView::class) val detailView = find(DetailView::class) @@ -13,21 +23,37 @@ class MainView : View() { override val root = borderpane { minWidth = 1000.0 + maxWidth = 1000.0 minHeight = 500.0 + maxHeight = 500.0 + background = Background(BackgroundFill(Paint.valueOf("#2b2b2b"), CornerRadii.EMPTY, Insets.EMPTY)) + + left = vbox { + prefWidth = 750.0 + add(cvSearch) + scrollpane { + add(folderView.root) + } + } - left = folderView.root right = detailView.root style { - // style options + spinnerSearch.isVisible = false + + cvSearch.paddingAll = 7.0 + cvSearch.style = "-fx-background-color: #3c3f41; -fx-text-inner-color: #b15b2e;" // TODO fix text color + cvSearch.style { + minHeight = Dimension(74.0, Dimension.LinearUnits.px) + } } // actions -// folderView.btn1.setOnAction { -// mvc.setPreview3DTexture(Image("textures/sample_texture_1.jpg")) -// mvc.setMeta("texture 1", "8MP", "Quelle: wikipedia") -// mvc.setTags(observableList("Stein", "Rot", "super")) -// } + cvSearch.chips.addListener { change: ListChangeListener.Change? -> + + mvc.cvSearchAction(cvSearch.chips) + + } detailView.cvTags.chips.addListener { change: ListChangeListener.Change? -> mvc.updateTags() @@ -35,7 +61,4 @@ class MainView : View() { } - - - } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt index 7e6ae7a..a489d74 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt @@ -6,6 +6,8 @@ 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 @@ -13,6 +15,7 @@ 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 @@ -28,7 +31,7 @@ class MainViewController : Controller() { folderView.children.add(element) } - fun addAllElements(elementList: List) { + fun addAllElements(elementList: ArrayList) { folderView.children.addAll(elementList) } @@ -75,9 +78,28 @@ class MainViewController : Controller() { //copy data (bytesarray) with name and extension to dir } + } + fun cvSearchAction(tags: ObservableList) { + var previewList = arrayListOf() + // 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 + } } + } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupViewController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupViewController.kt index 9616b05..11a3e5e 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupViewController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupViewController.kt @@ -1,7 +1,7 @@ package org.hso.texturesyncclient.view.startupView -import kotlinx.coroutines.withTimeout import org.hso.texturesyncclient.controller.RootController +import org.hso.texturesyncclient.view.mainView.MainView import tornadofx.Controller @@ -16,7 +16,7 @@ class StartupViewController : Controller() { sv.btnConnect.isDisable = true sv.spinnerStatus.isVisible = true - runAsync() { + runAsync { rootc.initConnection(name) } ui { // reset for later use @@ -25,6 +25,7 @@ class StartupViewController : Controller() { sv.tfServerIP.isEditable = true sv.btnConnect.isDisable = false sv.tfServerIP.clear() + rootc.switchToMainView() } }