From 53dcebecde417eb9eb66feda1ba0f32ee735381d Mon Sep 17 00:00:00 2001 From: Seil0 Date: Wed, 5 Jun 2019 15:44:12 +0200 Subject: [PATCH 1/4] correctly placed the spinnerSearch, adjusted FolderView hGap and vGap --- .../org/hso/texturesyncclient/app/Main.kt | 2 +- .../controller/Controller.kt | 4 +++ .../view/mainView/FolderView.kt | 8 +++--- .../view/mainView/MainView.kt | 19 ++++++++++--- .../view/mainView/MainViewController.kt | 27 ------------------- 5 files changed, 25 insertions(+), 35 deletions(-) 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 3d0584c..838d174 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt @@ -7,7 +7,7 @@ import org.hso.texturesyncclient.view.mainView.MainViewController import org.hso.texturesyncclient.view.startupView.StartupView import tornadofx.App -class Main: App(MainView::class){ +class Main: App(StartupView::class){ val controller = RootController() 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 2124bc3..ecd7c8d 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -116,6 +116,10 @@ class RootController : Controller() { find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) } + /** + * save the texture file to a local directory + * @param data the texture as meta element + */ fun exportTexture(data: Texture) { val directoryChooser = DirectoryChooser() directoryChooser.title = "Export Verzeichnis wählen" diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt index 673f041..f878dd0 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/FolderView.kt @@ -10,11 +10,11 @@ import tornadofx.* class FolderView : View("FolderView"){ override val root = flowpane { - hgap = 10.0 - vgap = 10.0 - paddingAll = 5.0 + hgap = 15.0 + vgap = 15.0 + paddingAll = 12.0 prefWidth = 732.0 - prefHeight = 1000.0 + prefHeight = 401.0 background = Background(BackgroundFill(Paint.valueOf("#cfcfcf"), CornerRadii.EMPTY, Insets.EMPTY)) //background = Background(BackgroundFill(Paint.valueOf("#2b2b2b"), CornerRadii.EMPTY, Insets.EMPTY)) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt index 2bcc874..052cc6e 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt @@ -3,6 +3,7 @@ package org.hso.texturesyncclient.view.mainView import com.jfoenix.controls.JFXChipView import com.jfoenix.controls.JFXSpinner import javafx.geometry.Insets +import javafx.scene.control.ScrollPane import javafx.scene.layout.Background import javafx.scene.layout.BackgroundFill @@ -26,17 +27,29 @@ class MainView : View() { maxHeight = 500.0 left = vbox { - prefWidth = 750.0 + background = Background(BackgroundFill(Paint.valueOf("#2b2b2b"), CornerRadii.EMPTY, Insets.EMPTY)) add(cvSearch) - scrollpane { - add(folderView.root) + anchorpane { + scrollpane { + this.fitToParentSize() + this.vbarPolicy = ScrollPane.ScrollBarPolicy.ALWAYS + add(folderView.root) + } + add(spinnerSearch) } + } right = detailView.root style { spinnerSearch.isVisible = false + spinnerSearch.anchorpaneConstraints { + topAnchor = 150 + bottomAnchor = 150 + leftAnchor = 150 + rightAnchor = 150 + } cvSearch.paddingAll = 7.0 cvSearch.minHeight = 70.0 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 a489d74..b30a3c9 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 @@ -55,37 +55,11 @@ 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 - - } - } - fun cvSearchAction(tags: ObservableList) { var previewList = arrayListOf() // show spinner, block ui folderView.children.clear() - folderView.children.add(mv.spinnerSearch) mv.spinnerSearch.isVisible = true mv.cvSearch.isDisable = true @@ -93,7 +67,6 @@ class MainViewController : Controller() { previewList = rootc.search(tags) } ui { // when search finished - folderView.children.clear() addAllElements(previewList) mv.spinnerSearch.isVisible = false mv.cvSearch.isDisable = false From e32766e58102c6a27be441358c628e791488ceb0 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 5 Jun 2019 16:05:10 +0200 Subject: [PATCH 2/4] save and load server address --- .../org/hso/texturesyncclient/app/Main.kt | 17 +++- .../controller/Controller.kt | 23 ++++-- .../controller/SettingsController.kt | 79 +++++++++++++++++++ .../view/startupView/StartupViewController.kt | 6 +- 4 files changed, 114 insertions(+), 11 deletions(-) create mode 100644 client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt 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 3d0584c..c6292e8 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/app/Main.kt @@ -1,18 +1,31 @@ package org.hso.texturesyncclient.app import org.hso.texturesyncclient.controller.RootController +import org.hso.texturesyncclient.controller.SettingsController 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 org.hso.texturesyncclient.view.startupView.StartupViewController import tornadofx.App -class Main: App(MainView::class){ +class Main: App(StartupView::class){ val controller = RootController() + private val svc: StartupViewController by inject() + init { - // TODO get saved IP address, if found try to connect, else show StartupView + SettingsController.init() + + if (SettingsController.serverAddressIsSet()) { + //load settings in ui and try to connect + println("serverAddress is set") + svc.setServerAddress(SettingsController.getServerAddress()) + svc.btnConnectAction(SettingsController.getServerAddress()) + } else { + println("serverAddress is not set") + } } } \ 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 2124bc3..88d25a9 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -1,5 +1,7 @@ package org.hso.texturesyncclient.controller +import com.sun.scenario.Settings +import javafx.application.Platform import javafx.collections.ObservableList import javafx.stage.DirectoryChooser import org.hso.texturesyncclient.controller.net.Connection @@ -30,6 +32,7 @@ class RootController : Controller() { private lateinit var con: Connection + init { /*var data = Texture() var img = con.getTexturePreview(data.textureHash) @@ -46,9 +49,9 @@ class RootController : Controller() { } mvc.addElement(test)*/ - } + /** * calculate the resolution, get today's date -> upload to server * @param path the absolute path of the file on the client's system @@ -63,7 +66,7 @@ class RootController : Controller() { 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) + val hash = Sha256(data) //Todo free image @@ -79,18 +82,20 @@ class RootController : Controller() { } /** - * Initialize connection to server + * Initialize connection to server and switch to MainView if connected * @param name server name as IP or domain */ fun initConnection(name: String) { try { con = Connection(InetAddress.getByName(name)) con.ping() - println("Connection successful") - - // TODO store server ip for next start + println("Connection to Server successful") + SettingsController.setServerAddress(name) + switchToMainView() + println("swithing to MainView @ initCon") } catch (e: Exception) { println(e) + println("Connection to Server NOT successful") } } @@ -112,8 +117,10 @@ class RootController : Controller() { } - fun switchToMainView(){ - find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + fun switchToMainView() { + Platform.runLater { //avoid the exception that occurs then this is called from an not tornadoFx thread + find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + } } fun exportTexture(data: Texture) { diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt new file mode 100644 index 0000000..5b90e65 --- /dev/null +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt @@ -0,0 +1,79 @@ +package org.hso.texturesyncclient.controller + +import java.io.* +import java.util.Properties; + + +class SettingsController { + + companion object { + + private lateinit var serverAddress: String + + private lateinit var props: Properties + + private val userHome = System.getProperty("user.home") + private val osName = System.getProperty("os.name") + + private lateinit var dirPath: String //path to settings file + private lateinit var settingsFile: File //settings file + + private val defautAddressValue: String = " " + + fun init() { + props = Properties() + + if (osName.contains("Windows")) { + dirPath = userHome + "/Documents/TextureSync"; + } else { + dirPath = userHome + "/.TextureSync"; + } + + settingsFile = File(dirPath + "/config.xml"); //open Settings file + + if (!settingsFile.exists()) { + println("settings not found! Will create new one") + File(dirPath).mkdir() + settingsFile.createNewFile() + serverAddress = defautAddressValue //load default value + saveSettings() + } else { + println("settings found") + loadSettings() + } + } + + fun serverAddressIsSet(): Boolean { + if (serverAddress == defautAddressValue) { + return false + } + return true + } + + private fun loadSettings() { + val inputStream: InputStream + inputStream = FileInputStream(settingsFile); + props.loadFromXML(inputStream); + serverAddress = props.getProperty("serverAddress") + inputStream.close(); + } + + private fun saveSettings() { + val outputStream: OutputStream + props.setProperty("serverAddress", serverAddress); + outputStream = FileOutputStream(settingsFile); + props.storeToXML(outputStream, "TextureSync settings"); + outputStream.close(); + println("settings saved") + } + + fun getServerAddress(): String { + return serverAddress; + } + + fun setServerAddress(serverAddress: String) { + this.serverAddress = serverAddress + saveSettings() + } + } +} \ No newline at end of file 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 11a3e5e..71e0234 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 @@ -10,6 +10,11 @@ class StartupViewController : Controller() { private val sv = find(StartupView::class) private val rootc = find(RootController::class) + fun setServerAddress(address: String){ + sv.tfServerIP.text = address + sv.tfServerIP.isFocusTraversable = false + } + fun btnConnectAction(name: String) { sv.labelStatus.text = "Verbinden ..." sv.tfServerIP.isEditable = false @@ -25,7 +30,6 @@ class StartupViewController : Controller() { sv.tfServerIP.isEditable = true sv.btnConnect.isDisable = false sv.tfServerIP.clear() - rootc.switchToMainView() } } From d7a67c497e648126131b165e247673908f16913c Mon Sep 17 00:00:00 2001 From: Seil0 Date: Wed, 5 Jun 2019 16:23:45 +0200 Subject: [PATCH 3/4] added import Button --- .../controller/Controller.kt | 24 +++++++-------- .../view/importView/ImportViewController.kt | 1 + .../view/mainView/DetailView.kt | 29 +++++++++++++++++++ .../view/mainView/MainView.kt | 4 +++ .../view/mainView/MainViewController.kt | 14 ++++----- 5 files changed, 50 insertions(+), 22 deletions(-) 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 6bdc16c..0468b5d 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -9,6 +9,7 @@ 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.ImportView import org.hso.texturesyncclient.view.importView.ImportViewController import org.hso.texturesyncclient.view.mainView.MainView import org.hso.texturesyncclient.view.mainView.MainViewController @@ -16,7 +17,6 @@ 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 @@ -39,14 +39,6 @@ class RootController : Controller() { var test = GUIModel(data, img) test.exportItem.setOnAction { - } - mvc.addElement(test) - - data = Texture() - img = con.getTexturePreview(data.textureHash) - test = GUIModel(data, img) - test.exportItem.setOnAction { - } mvc.addElement(test)*/ } @@ -117,10 +109,16 @@ class RootController : Controller() { } - fun switchToMainView() { - Platform.runLater { //avoid the exception that occurs then this is called from an not tornadoFx thread - find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) - } + fun switchStartupToMain() { + find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + } + + fun switchMainToImport() { + find(MainView::class).replaceWith(ImportView::class, sizeToScene = true, centerOnScreen = true) + } + + fun switchImportToMain() { + find(ImportView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) } /** 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 6f8d26b..83df2cc 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 @@ -24,6 +24,7 @@ class ImportViewController : Controller() { fun btnImportAction() { rootc.importTexture(iv.tfFilePath.text, iv.tfName.text, iv.cvTags.chips) + rootc.switchImportToMain() } fun validateImport() { diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt index 785d85a..ee0e546 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/DetailView.kt @@ -1,8 +1,10 @@ package org.hso.texturesyncclient.view.mainView +import com.jfoenix.controls.JFXButton import com.jfoenix.controls.JFXChipView import javafx.geometry.Insets import javafx.geometry.Orientation +import javafx.geometry.Pos import javafx.scene.control.Label import javafx.scene.image.Image import javafx.scene.layout.Background @@ -16,6 +18,7 @@ class DetailView: View() { val preview = Preview3D() val metaLabel = Label("Auflösung: 8MP\nName: Texture.png\nAndere: was anderes") val cvTags = JFXChipView() + val btnImport = JFXButton("+") init { // set a default texture @@ -39,14 +42,40 @@ class DetailView: View() { } field { + minHeight = 145.0 add(cvTags) + + } + + field { + hbox(alignment = Pos.CENTER_RIGHT) { + add(btnImport) + } } // TODO add "Import" Btn } style { + cvTags.minHeight = 135.0 + cvTags.paddingAll = 3.0 cvTags.style = "-fx-background-color: #3c3f41; -fx-text-inner-color: #b15b2e;" + + btnImport.buttonType = JFXButton.ButtonType.RAISED + // TODO move this to a css file + btnImport.style = "-fx-background-color: #F1F1F1;\n" + + " -fx-background-radius: 50px;\n" + + " -fx-pref-height: 50px;\n" + + " -fx-pref-width: 50px;\n" + + " -fx-min-width: -fx-pref-width;\n" + + " -fx-max-width: -fx-pref-width;\n" + + " -fx-min-height: -fx-pref-height;\n" + + " -fx-max-height: -fx-pref-height;\n" + + "-jfx-button-type: RAISED;" + } + + btnImport.setOnAction { + } } diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt index 052cc6e..deda90f 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainView.kt @@ -65,6 +65,10 @@ class MainView : View() { mvc.updateTags() } + detailView.btnImport.setOnAction { + mvc.btnImportAction() + } + } } \ No newline at end of file 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 b30a3c9..a98e54b 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,14 +3,8 @@ 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 org.hso.texturesyncclient.controller.RootController -import tornadofx.clear -import javax.swing.JColorChooser.showDialog -import java.io.File - class MainViewController : Controller() { @@ -25,7 +19,6 @@ class MainViewController : Controller() { private val metaLabel = mv.detailView.metaLabel private val cvTags = mv.detailView.cvTags - // FolderView functions fun addElement(element: GUIModel) { folderView.children.add(element) @@ -50,11 +43,12 @@ class MainViewController : Controller() { cvTags.chips.addAll(chips) } - // update the tags for the selected element fun updateTags() { println(cvTags.chips) } + // DetailView actions + fun cvSearchAction(tags: ObservableList) { var previewList = arrayListOf() @@ -73,6 +67,8 @@ class MainViewController : Controller() { } } - + fun btnImportAction() { + rootc.switchMainToImport() + } } \ No newline at end of file From de47e998528d82e96ed016ecde9fe43ac33e5e3c Mon Sep 17 00:00:00 2001 From: Seil0 Date: Wed, 5 Jun 2019 16:31:10 +0200 Subject: [PATCH 4/4] clean up SettingsController * don't use ";" * use proper kotlin syntax * make all switch View calls use runLater --- .../controller/Controller.kt | 16 +++++++--- .../controller/SettingsController.kt | 32 +++++++++---------- 2 files changed, 27 insertions(+), 21 deletions(-) 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 0468b5d..e0ceb73 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/Controller.kt @@ -1,6 +1,5 @@ package org.hso.texturesyncclient.controller -import com.sun.scenario.Settings import javafx.application.Platform import javafx.collections.ObservableList import javafx.stage.DirectoryChooser @@ -83,7 +82,7 @@ class RootController : Controller() { con.ping() println("Connection to Server successful") SettingsController.setServerAddress(name) - switchToMainView() + switchStartupToMain() println("swithing to MainView @ initCon") } catch (e: Exception) { println(e) @@ -110,15 +109,22 @@ class RootController : Controller() { fun switchStartupToMain() { - find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + Platform.runLater { + find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + } } + // These runLater calls should be unnecessary fun switchMainToImport() { - find(MainView::class).replaceWith(ImportView::class, sizeToScene = true, centerOnScreen = true) + Platform.runLater { + find(MainView::class).replaceWith(ImportView::class, sizeToScene = true, centerOnScreen = true) + } } fun switchImportToMain() { - find(ImportView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + Platform.runLater { + find(ImportView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) + } } /** diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt index 5b90e65..f815fa9 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/SettingsController.kt @@ -1,7 +1,7 @@ package org.hso.texturesyncclient.controller import java.io.* -import java.util.Properties; +import java.util.Properties class SettingsController { @@ -18,24 +18,24 @@ class SettingsController { private lateinit var dirPath: String //path to settings file private lateinit var settingsFile: File //settings file - private val defautAddressValue: String = " " + private const val defaultAddressValue: String = " " fun init() { props = Properties() - if (osName.contains("Windows")) { - dirPath = userHome + "/Documents/TextureSync"; + dirPath = if (osName.contains("Windows")) { + "$userHome/Documents/TextureSync" } else { - dirPath = userHome + "/.TextureSync"; + "$userHome/.TextureSync" } - settingsFile = File(dirPath + "/config.xml"); //open Settings file + settingsFile = File("$dirPath/config.xml") //open Settings file if (!settingsFile.exists()) { println("settings not found! Will create new one") File(dirPath).mkdir() settingsFile.createNewFile() - serverAddress = defautAddressValue //load default value + serverAddress = defaultAddressValue //load default value saveSettings() } else { println("settings found") @@ -44,7 +44,7 @@ class SettingsController { } fun serverAddressIsSet(): Boolean { - if (serverAddress == defautAddressValue) { + if (serverAddress == defaultAddressValue) { return false } return true @@ -52,23 +52,23 @@ class SettingsController { private fun loadSettings() { val inputStream: InputStream - inputStream = FileInputStream(settingsFile); - props.loadFromXML(inputStream); + inputStream = FileInputStream(settingsFile) + props.loadFromXML(inputStream) serverAddress = props.getProperty("serverAddress") - inputStream.close(); + inputStream.close() } private fun saveSettings() { val outputStream: OutputStream - props.setProperty("serverAddress", serverAddress); - outputStream = FileOutputStream(settingsFile); - props.storeToXML(outputStream, "TextureSync settings"); - outputStream.close(); + props.setProperty("serverAddress", serverAddress) + outputStream = FileOutputStream(settingsFile) + props.storeToXML(outputStream, "TextureSync settings") + outputStream.close() println("settings saved") } fun getServerAddress(): String { - return serverAddress; + return serverAddress } fun setServerAddress(serverAddress: String) {