startup view connection

This commit is contained in:
Hendrik Schutter 2019-06-04 16:05:47 +02:00
parent 83e4f10aaa
commit 88b04f7aea
5 changed files with 65 additions and 34 deletions

View File

@ -26,6 +26,7 @@ repositories {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 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 "no.tornado:tornadofx:$tornadofx_version"
implementation "com.jfoenix:jfoenix:8.0.8" implementation "com.jfoenix:jfoenix:8.0.8"
implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.google.code.gson:gson:2.8.5'

View File

@ -6,8 +6,12 @@ import org.hso.texturesyncclient.view.mainView.MainView
import org.hso.texturesyncclient.view.startupView.StartupView import org.hso.texturesyncclient.view.startupView.StartupView
import tornadofx.App import tornadofx.App
class Main: App(ImportView::class){ class Main: App(StartupView::class){
//val controller = RootController() val controller = RootController()
init {
// TODO get saved IP address, if found try to connect, else show StartupView
}
} }

View File

@ -6,7 +6,9 @@ import org.hso.texturesyncclient.model.Sha256
import org.hso.texturesyncclient.model.Texture import org.hso.texturesyncclient.model.Texture
import org.hso.texturesyncclient.model.TextureFormat import org.hso.texturesyncclient.model.TextureFormat
import org.hso.texturesyncclient.view.importView.ImportViewController 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.mainView.MainViewController
import org.hso.texturesyncclient.view.startupView.StartupView
import org.hso.texturesyncclient.view.startupView.StartupViewController import org.hso.texturesyncclient.view.startupView.StartupViewController
import tornadofx.Controller import tornadofx.Controller
import java.net.InetAddress import java.net.InetAddress
@ -16,22 +18,13 @@ import javax.imageio.ImageIO
import java.util.UUID import java.util.UUID
import java.nio.file.Files import java.nio.file.Files
class RootController : Controller() { class RootController : Controller() {
private val mvc: MainViewController by inject() private val mvc: MainViewController by inject()
private val svc: StartupViewController by inject() private val svc: StartupViewController by inject()
private val ivc: ImportViewController by inject() private val ivc: ImportViewController by inject()
private val con = Connection(InetAddress.getByName("127.0.0.1")) private lateinit var con: Connection
init { init {
/*var data = Texture() /*var data = Texture()
@ -72,7 +65,37 @@ class RootController : Controller() {
val newTexture = Texture(uuid, name, tags.toTypedArray(), format, resolution, cal, hash) val newTexture = Texture(uuid, name, tags.toTypedArray(), format, resolution, cal, hash)
try {
con.uploadTexture(newTexture, data) 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)
}
} }

View File

@ -17,7 +17,6 @@ class StartupView : View("StartupView") {
val labelStatus = Label("Verbindung zum Server einrichten") val labelStatus = Label("Verbindung zum Server einrichten")
val spinnerStatus = JFXSpinner() val spinnerStatus = JFXSpinner()
val labelServerIP = Label("Server-Adresse")
val tfServerIP = JFXTextField() val tfServerIP = JFXTextField()
val btnConnect = JFXButton("Manuell Verbinden") val btnConnect = JFXButton("Manuell Verbinden")
@ -38,7 +37,9 @@ class StartupView : View("StartupView") {
vbox(10) { vbox(10) {
alignment = Pos.CENTER alignment = Pos.CENTER
add(labelServerIP) label("Server-Adresse") {
style = "-fx-font: 15px Verdana; -fx-text-fill: #2b7bbb;"
}
add(tfServerIP) add(tfServerIP)
add(btnConnect) add(btnConnect)
} }
@ -49,12 +50,11 @@ class StartupView : View("StartupView") {
spinnerStatus.isVisible = false spinnerStatus.isVisible = false
labelStatus.style = "-fx-font: 20px Verdana; -fx-text-fill: #2b7bbb;" 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;" btnConnect.style = "-fx-button-type: RAISED; -fx-background-color: #3c3f41; -fx-text-fill: #2b7bbb;"
//tfServerIP.style = "-fx-text-fill: #b15b2e;" //tfServerIP.style = "-fx-text-fill: #b15b2e;"
tfServerIP.style { //TODO without .style tfServerIP.style {
textFill = Paint.valueOf("#b15b2e") textFill = Paint.valueOf("#b15b2e")
alignment = Pos.BASELINE_CENTER alignment = Pos.BASELINE_CENTER
} }
@ -62,17 +62,12 @@ class StartupView : View("StartupView") {
} }
btnConnect.setOnAction { btnConnect.setOnAction {
spinnerStatus.isVisible = true
svc.btnConnectAction(tfServerIP.text) svc.btnConnectAction(tfServerIP.text)
//spinnerStatus.isVisible = false
} }
tfServerIP.setOnKeyPressed { tfServerIP.setOnKeyPressed {
if (it.code == KeyCode.ENTER) { if (it.code == KeyCode.ENTER) {
spinnerStatus.isVisible = true
svc.btnConnectAction(tfServerIP.text) svc.btnConnectAction(tfServerIP.text)
//spinnerStatus.isVisible = false
} }
} }

View File

@ -1,23 +1,31 @@
package org.hso.texturesyncclient.view.startupView package org.hso.texturesyncclient.view.startupView
import kotlinx.coroutines.withTimeout
import org.hso.texturesyncclient.controller.RootController
import tornadofx.Controller import tornadofx.Controller
class StartupViewController : Controller() { class StartupViewController : Controller() {
fun btnConnectAction(txt:String){ private val sv = find(StartupView::class)
println("Connect BTN: $txt") 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
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()
} }
fun labelStatusSetText (txt:String){
val startupView = find(StartupView::class)
startupView.labelStatus.text = txt
}
fun tfServerIPClear (){
val startupView = find(StartupView::class)
startupView.tfServerIP.clear()
} }
} }