diff --git a/src/main/kotlin/com/marvinelsen/willow/Config.kt b/src/main/kotlin/com/marvinelsen/willow/Config.kt deleted file mode 100644 index b3b13b4..0000000 --- a/src/main/kotlin/com/marvinelsen/willow/Config.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.marvinelsen.willow - -import javafx.beans.property.IntegerProperty -import javafx.beans.property.SimpleIntegerProperty -import java.util.prefs.Preferences - -class Config { - companion object { - private const val DETAIL_HEADWORD_FONT_SIZE_KEY = "detailHeadwordFontSize" - - private const val DEFAULT_DETAIL_HEADWORD_FONT_SIZE = 16 - } - - private val preferences = Preferences.userNodeForPackage(this::class.java) - - val detailHeadwordFontSize: IntegerProperty = SimpleIntegerProperty(DEFAULT_DETAIL_HEADWORD_FONT_SIZE) - - fun save() { - preferences.putInt(DETAIL_HEADWORD_FONT_SIZE_KEY, detailHeadwordFontSize.value) - } - - fun load() { - detailHeadwordFontSize.value = preferences.getInt( - DETAIL_HEADWORD_FONT_SIZE_KEY, - DEFAULT_DETAIL_HEADWORD_FONT_SIZE - ) - } - - fun reset() { - detailHeadwordFontSize.value = DEFAULT_DETAIL_HEADWORD_FONT_SIZE - } -} diff --git a/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt index 08cdbaf..a47f176 100644 --- a/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt +++ b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt @@ -1,5 +1,6 @@ package com.marvinelsen.willow +import com.marvinelsen.willow.config.Config import com.marvinelsen.willow.domain.SqliteDictionary import com.marvinelsen.willow.ui.controllers.DetailsController import com.marvinelsen.willow.ui.controllers.ListController @@ -16,7 +17,6 @@ import javafx.scene.text.Font import javafx.stage.Stage import javafx.util.Callback import java.sql.DriverManager -import java.util.Locale import java.util.ResourceBundle class WillowApplication : Application() { @@ -48,14 +48,14 @@ class WillowApplication : Application() { config.load() val fxmlLoader = FXMLLoader() - fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", Locale.getDefault()) + fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", config.locale.value) fxmlLoader.controllerFactory = Callback { type -> when (type) { MainController::class.java -> MainController(model) MenuController::class.java -> MenuController(model, config) DetailsController::class.java -> DetailsController(model, config) SearchController::class.java -> SearchController(model) - ListController::class.java -> ListController(model) + ListController::class.java -> ListController(model, config) else -> error("Trying to instantiate unknown controller type $type") } } diff --git a/src/main/kotlin/com/marvinelsen/willow/config/Config.kt b/src/main/kotlin/com/marvinelsen/willow/config/Config.kt new file mode 100644 index 0000000..e8c4b4e --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/config/Config.kt @@ -0,0 +1,146 @@ +package com.marvinelsen.willow.config + +import javafx.beans.property.BooleanProperty +import javafx.beans.property.IntegerProperty +import javafx.beans.property.ObjectProperty +import javafx.beans.property.SimpleBooleanProperty +import javafx.beans.property.SimpleIntegerProperty +import javafx.beans.property.SimpleObjectProperty +import java.util.Locale +import java.util.prefs.Preferences + +class Config { + companion object { + private const val LOCALE_KEY = "locale" + private const val THEME_KEY = "theme" + private const val SCRIPT_KEY = "script" + private const val DETAIL_HEADWORD_FONT_SIZE_KEY = "detailHeadwordFontSize" + private const val DETAIL_PRONUNCIATION_FONT_SIZE_KEY = "detailPronunciationFontSize" + + private const val DEFAULT_DETAIL_HEADWORD_FONT_SIZE = 40 + private const val DEFAULT_DETAIL_PRONUNCIATION_FONT_SIZE = 16 + private val DEFAULT_THEME = Theme.SYSTEM + private val DEFAULT_SCRIPT = Script.SIMPLIFIED + private val DEFAULT_LOCALE = Locale.ENGLISH + } + + private val preferences = Preferences.userNodeForPackage(this::class.java) + val searchResults = SearchResultsConfig(preferences) + + val locale: ObjectProperty = SimpleObjectProperty(DEFAULT_LOCALE) + val theme: ObjectProperty = SimpleObjectProperty(DEFAULT_THEME) + val script: ObjectProperty