clean up SettingsController

* don't use ";"
* use proper kotlin syntax
* make all switch View calls use runLater
This commit is contained in:
Jannik 2019-06-05 16:31:10 +02:00
parent d7a67c497e
commit de47e99852
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
2 changed files with 27 additions and 21 deletions

View File

@ -1,6 +1,5 @@
package org.hso.texturesyncclient.controller package org.hso.texturesyncclient.controller
import com.sun.scenario.Settings
import javafx.application.Platform import javafx.application.Platform
import javafx.collections.ObservableList import javafx.collections.ObservableList
import javafx.stage.DirectoryChooser import javafx.stage.DirectoryChooser
@ -83,7 +82,7 @@ class RootController : Controller() {
con.ping() con.ping()
println("Connection to Server successful") println("Connection to Server successful")
SettingsController.setServerAddress(name) SettingsController.setServerAddress(name)
switchToMainView() switchStartupToMain()
println("swithing to MainView @ initCon") println("swithing to MainView @ initCon")
} catch (e: Exception) { } catch (e: Exception) {
println(e) println(e)
@ -110,15 +109,22 @@ class RootController : Controller() {
fun switchStartupToMain() { 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() { 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() { fun switchImportToMain() {
find(ImportView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) Platform.runLater {
find(ImportView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true)
}
} }
/** /**

View File

@ -1,7 +1,7 @@
package org.hso.texturesyncclient.controller package org.hso.texturesyncclient.controller
import java.io.* import java.io.*
import java.util.Properties; import java.util.Properties
class SettingsController { class SettingsController {
@ -18,24 +18,24 @@ class SettingsController {
private lateinit var dirPath: String //path to settings file private lateinit var dirPath: String //path to settings file
private lateinit var settingsFile: File //settings file private lateinit var settingsFile: File //settings file
private val defautAddressValue: String = " " private const val defaultAddressValue: String = " "
fun init() { fun init() {
props = Properties() props = Properties()
if (osName.contains("Windows")) { dirPath = if (osName.contains("Windows")) {
dirPath = userHome + "/Documents/TextureSync"; "$userHome/Documents/TextureSync"
} else { } 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()) { if (!settingsFile.exists()) {
println("settings not found! Will create new one") println("settings not found! Will create new one")
File(dirPath).mkdir() File(dirPath).mkdir()
settingsFile.createNewFile() settingsFile.createNewFile()
serverAddress = defautAddressValue //load default value serverAddress = defaultAddressValue //load default value
saveSettings() saveSettings()
} else { } else {
println("settings found") println("settings found")
@ -44,7 +44,7 @@ class SettingsController {
} }
fun serverAddressIsSet(): Boolean { fun serverAddressIsSet(): Boolean {
if (serverAddress == defautAddressValue) { if (serverAddress == defaultAddressValue) {
return false return false
} }
return true return true
@ -52,23 +52,23 @@ class SettingsController {
private fun loadSettings() { private fun loadSettings() {
val inputStream: InputStream val inputStream: InputStream
inputStream = FileInputStream(settingsFile); inputStream = FileInputStream(settingsFile)
props.loadFromXML(inputStream); props.loadFromXML(inputStream)
serverAddress = props.getProperty("serverAddress") serverAddress = props.getProperty("serverAddress")
inputStream.close(); inputStream.close()
} }
private fun saveSettings() { private fun saveSettings() {
val outputStream: OutputStream val outputStream: OutputStream
props.setProperty("serverAddress", serverAddress); props.setProperty("serverAddress", serverAddress)
outputStream = FileOutputStream(settingsFile); outputStream = FileOutputStream(settingsFile)
props.storeToXML(outputStream, "TextureSync settings"); props.storeToXML(outputStream, "TextureSync settings")
outputStream.close(); outputStream.close()
println("settings saved") println("settings saved")
} }
fun getServerAddress(): String { fun getServerAddress(): String {
return serverAddress; return serverAddress
} }
fun setServerAddress(serverAddress: String) { fun setServerAddress(serverAddress: String) {