From 88b04f7aea0eedd5b2f2c3a342578372e9412c81 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 4 Jun 2019 16:05:47 +0200 Subject: [PATCH] startup view connection --- client/build.gradle | 1 + .../org/hso/texturesyncclient/app/Main.kt | 10 +++-- .../controller/Controller.kt | 45 ++++++++++++++----- .../view/startupView/StartupView.kt | 13 ++---- .../view/startupView/StartupViewController.kt | 30 ++++++++----- 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/client/build.gradle b/client/build.gradle index e3b66ee..d74478e 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -26,6 +26,7 @@ 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 9820e52..a2b0341 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt @@ -6,8 +6,12 @@ import org.hso.texturesyncclient.view.mainView.MainView import org.hso.texturesyncclient.view.startupView.StartupView import tornadofx.App -class Main: App(ImportView::class){ +class Main: App(StartupView::class){ + + val controller = RootController() + + init { + // TODO get saved IP address, if found try to connect, else show StartupView + } - //val controller = RootController() - } \ No newline at end of file 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 d163176..fa5d9a5 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -6,7 +6,9 @@ import org.hso.texturesyncclient.model.Sha256 import org.hso.texturesyncclient.model.Texture import org.hso.texturesyncclient.model.TextureFormat import org.hso.texturesyncclient.view.importView.ImportViewController +import org.hso.texturesyncclient.view.mainView.MainView 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 java.net.InetAddress @@ -16,22 +18,13 @@ import javax.imageio.ImageIO import java.util.UUID import java.nio.file.Files - - - - - - - - - class RootController : Controller() { private val mvc: MainViewController by inject() private val svc: StartupViewController by inject() private val ivc: ImportViewController by inject() - private val con = Connection(InetAddress.getByName("127.0.0.1")) + private lateinit var con: Connection init { /*var data = Texture() @@ -72,7 +65,37 @@ class RootController : Controller() { val newTexture = Texture(uuid, name, tags.toTypedArray(), format, resolution, cal, hash) - con.uploadTexture(newTexture, data) + try { + con.uploadTexture(newTexture, data) + println("Texture upload successful") + } catch (e: Exception) { + println(e) + } + + } + + /** + * Initialize connection to server + * @param name server name as IP or domain + */ + fun initConnection(name: String) { + try { + con = Connection(InetAddress.getByName(name)) + println("ausgabe") + 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) + } + } diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupView.kt index 28abb3a..dc4b04f 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/startupView/StartupView.kt @@ -17,7 +17,6 @@ class StartupView : View("StartupView") { val labelStatus = Label("Verbindung zum Server einrichten") val spinnerStatus = JFXSpinner() - val labelServerIP = Label("Server-Adresse") val tfServerIP = JFXTextField() val btnConnect = JFXButton("Manuell Verbinden") @@ -38,7 +37,9 @@ class StartupView : View("StartupView") { vbox(10) { alignment = Pos.CENTER - add(labelServerIP) + label("Server-Adresse") { + style = "-fx-font: 15px Verdana; -fx-text-fill: #2b7bbb;" + } add(tfServerIP) add(btnConnect) } @@ -49,12 +50,11 @@ class StartupView : View("StartupView") { spinnerStatus.isVisible = false labelStatus.style = "-fx-font: 20px Verdana; -fx-text-fill: #2b7bbb;" - labelServerIP.style = "-fx-font: 15px Verdana; -fx-text-fill: #2b7bbb;" btnConnect.style = "-fx-button-type: RAISED; -fx-background-color: #3c3f41; -fx-text-fill: #2b7bbb;" //tfServerIP.style = "-fx-text-fill: #b15b2e;" - tfServerIP.style { //TODO without .style + tfServerIP.style { textFill = Paint.valueOf("#b15b2e") alignment = Pos.BASELINE_CENTER } @@ -62,17 +62,12 @@ class StartupView : View("StartupView") { } btnConnect.setOnAction { - spinnerStatus.isVisible = true svc.btnConnectAction(tfServerIP.text) - //spinnerStatus.isVisible = false - } tfServerIP.setOnKeyPressed { if (it.code == KeyCode.ENTER) { - spinnerStatus.isVisible = true svc.btnConnectAction(tfServerIP.text) - //spinnerStatus.isVisible = false } } 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 01328f8..9616b05 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,23 +1,31 @@ package org.hso.texturesyncclient.view.startupView +import kotlinx.coroutines.withTimeout +import org.hso.texturesyncclient.controller.RootController import tornadofx.Controller class StartupViewController : Controller() { - fun btnConnectAction(txt:String){ - println("Connect BTN: $txt") + private val sv = find(StartupView::class) + private val rootc = find(RootController::class) - } + fun btnConnectAction(name: String) { + sv.labelStatus.text = "Verbinden ..." + sv.tfServerIP.isEditable = false + sv.btnConnect.isDisable = true + sv.spinnerStatus.isVisible = true - fun labelStatusSetText (txt:String){ - val startupView = find(StartupView::class) - startupView.labelStatus.text = txt - } - - fun tfServerIPClear (){ - val startupView = find(StartupView::class) - startupView.tfServerIP.clear() + runAsync() { + rootc.initConnection(name) + } ui { + // reset for later use + sv.spinnerStatus.isVisible = false + sv.labelStatus.text = "Verbindung zum Server einrichten" + sv.tfServerIP.isEditable = true + sv.btnConnect.isDisable = false + sv.tfServerIP.clear() + } } }