clean up SettingsController
* don't use ";" * use proper kotlin syntax * make all switch View calls use runLater
This commit is contained in:
parent
d7a67c497e
commit
de47e99852
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue