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 0794a23..fa5d9a5 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -2,17 +2,21 @@ package org.hso.texturesyncclient.controller import javafx.collections.ObservableList 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 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 -import java.util.* import java.util.Calendar - - +import java.io.File +import javax.imageio.ImageIO +import java.util.UUID +import java.nio.file.Files class RootController : Controller() { @@ -20,7 +24,7 @@ class RootController : Controller() { 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() @@ -48,14 +52,51 @@ class RootController : Controller() { * @param tags all tags for the file */ fun importTexture(path: String, name: String, tags: ObservableList) { + val data = Files.readAllBytes(File(path).toPath()) // this is the image as byte array + val uuid = UUID.randomUUID() + val format = if (File(path).extension.toLowerCase() == "png") TextureFormat.PNG else TextureFormat.JPEG + val bimg = ImageIO.read(File(path)) //image for obtaining resolution + val resolution = Pair(bimg.height, bimg.width) val cal = Calendar.getInstance() //calendar obj with current time + val hash = Sha256(data) - println(cal.time) - - + //Todo free image + val newTexture = Texture(uuid, name, tags.toTypedArray(), format, resolution, cal, hash) + 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) + } + + } + + } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt index e75febd..0e3b270 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/DataModel.kt @@ -5,9 +5,6 @@ import java.util.* import java.security.MessageDigest - -class DataModel - enum class TextureFormat { PNG, JPEG, } diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt index 41e6ad7..6f8d26b 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt @@ -12,8 +12,6 @@ class ImportViewController : Controller() { private val rootc = find(RootController::class) fun btnFileChooserAction() { - println("btn click") - val list = listOf("*.png", "*.PNG", "*.jpg", "*.JPG", "*.jpeg", "*.JPEG") val arrayFilter = arrayOf(ExtensionFilter("Texturen vom Bildformat: PNG oder JPG", list)) val file = chooseFile("Textur auswählen", arrayFilter, FileChooserMode.Single, owner = null) 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 b762f49..7e6ae7a 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 @@ -3,7 +3,12 @@ package org.hso.texturesyncclient.view.mainView import javafx.collections.ObservableList import javafx.scene.image.Image import org.hso.texturesyncclient.model.GUIModel +import org.hso.texturesyncclient.model.TextureFormat import tornadofx.Controller +import javafx.stage.DirectoryChooser +import javax.swing.JColorChooser.showDialog +import java.io.File + class MainViewController : Controller() { @@ -47,4 +52,32 @@ class MainViewController : Controller() { println(cvTags.chips) } + + /** + * save the texture file to r + * @param data the file as a byte array + * @param name name for the file + * @param format specific file format. jpeg or png + */ + fun exportTexture(data: ByteArray, name: String, format : TextureFormat){ + + + val directoryChooser = DirectoryChooser() + + directoryChooser.title = "Export Verzeichnis wählen" + + // TODO directoryChooser.setInitialDirectory(new File(System.getProperty("user.home"))) + + val dir = directoryChooser.showDialog(primaryStage) + + if (dir != null) { + + //copy data (bytesarray) with name and extension to dir + + } + + + } + + } \ No newline at end of file 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() + } } } diff --git a/client/src/main/resources/textures/sample_texture_3.PNG b/client/src/main/resources/textures/sample_texture_3.PNG new file mode 100644 index 0000000..714b9b8 Binary files /dev/null and b/client/src/main/resources/textures/sample_texture_3.PNG differ diff --git a/client/src/main/resources/textures/sample_texture_4.png b/client/src/main/resources/textures/sample_texture_4.png new file mode 100644 index 0000000..714b9b8 Binary files /dev/null and b/client/src/main/resources/textures/sample_texture_4.png differ diff --git a/client/src/main/resources/textures/sample_texture_5.JPG b/client/src/main/resources/textures/sample_texture_5.JPG new file mode 100644 index 0000000..5f98215 Binary files /dev/null and b/client/src/main/resources/textures/sample_texture_5.JPG differ diff --git a/client/src/main/resources/textures/sample_texture_6.JPEG b/client/src/main/resources/textures/sample_texture_6.JPEG new file mode 100644 index 0000000..5f98215 Binary files /dev/null and b/client/src/main/resources/textures/sample_texture_6.JPEG differ