Merge branch 'master' of git.mosad.xyz:localhorst/TextureSync
@ -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'
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
@ -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<String>) {
 | 
			
		||||
        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)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -5,9 +5,6 @@ import java.util.*
 | 
			
		||||
import java.security.MessageDigest
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DataModel
 | 
			
		||||
 | 
			
		||||
enum class TextureFormat {
 | 
			
		||||
    PNG, JPEG,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -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
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								client/src/main/resources/textures/sample_texture_3.PNG
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 85 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								client/src/main/resources/textures/sample_texture_4.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 85 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								client/src/main/resources/textures/sample_texture_5.JPG
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 6.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								client/src/main/resources/textures/sample_texture_6.JPEG
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 6.2 KiB  |