query images and show result
This commit is contained in:
parent
d5853d7006
commit
e78e7e3a59
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<String>): ArrayList<GUIModel> {
|
||||
val previewList = arrayListOf<GUIModel>()
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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<String>()
|
||||
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<out String>? ->
|
||||
|
||||
mvc.cvSearchAction(cvSearch.chips)
|
||||
|
||||
}
|
||||
|
||||
detailView.cvTags.chips.addListener { change: ListChangeListener.Change<out String>? ->
|
||||
mvc.updateTags()
|
||||
|
@ -35,7 +61,4 @@ class MainView : View() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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<GUIModel>) {
|
||||
fun addAllElements(elementList: ArrayList<GUIModel>) {
|
||||
folderView.children.addAll(elementList)
|
||||
}
|
||||
|
||||
|
@ -75,9 +78,28 @@ class MainViewController : Controller() {
|
|||
//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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue