diff --git a/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt index 9969032..08cdbaf 100644 --- a/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt +++ b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt @@ -30,7 +30,6 @@ class WillowApplication : Application() { private const val FONT_SIZE = 12.0 private const val JDBC_CONNECTION_STRING = "jdbc:sqlite:dictionary.db" - val resourceBundle: ResourceBundle = ResourceBundle.getBundle("i18n/willow", Locale.US) } override fun init() { @@ -49,7 +48,7 @@ class WillowApplication : Application() { config.load() val fxmlLoader = FXMLLoader() - fxmlLoader.resources = resourceBundle + fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", Locale.getDefault()) fxmlLoader.controllerFactory = Callback { type -> when (type) { MainController::class.java -> MainController(model) diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/cells/EntryCellFactory.kt b/src/main/kotlin/com/marvinelsen/willow/ui/cells/EntryCellFactory.kt index 6ead1d8..5312a42 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/cells/EntryCellFactory.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/cells/EntryCellFactory.kt @@ -9,10 +9,12 @@ import javafx.scene.control.ListView import javafx.scene.layout.FlowPane import javafx.scene.layout.VBox import javafx.util.Callback +import java.util.ResourceBundle -class DictionaryEntryCellFactory : Callback, ListCell> { +class DictionaryEntryCellFactory(private val resources: ResourceBundle) : + Callback, ListCell> { override fun call(listView: ListView): ListCell { - val entryCell = EntryCell() + val entryCell = EntryCell(resources) entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING)) return entryCell } @@ -22,7 +24,7 @@ class DictionaryEntryCellFactory : Callback, ListCe } } -internal class EntryCell : ListCell() { +internal class EntryCell(private val resources: ResourceBundle) : ListCell() { private val labelHeadword = Label().apply { styleClass.add("list-view-entry") } @@ -58,7 +60,7 @@ internal class EntryCell : ListCell() { val definition = entry.definitions.joinToString(separator = " / ") { it.joinToString(separator = "; ") } labelDefinition.text = definition - contextMenu = createContextMenuForEntry(entry) + contextMenu = createContextMenuForEntry(entry, resources) graphic = root } } diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt index fa92238..c63fbcc 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt @@ -3,6 +3,7 @@ package com.marvinelsen.willow.ui.controllers import com.marvinelsen.willow.Config import com.marvinelsen.willow.Model import com.marvinelsen.willow.ui.DictionaryEntryFx +import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory import javafx.beans.binding.Bindings import javafx.fxml.FXML import javafx.scene.control.Label @@ -15,8 +16,12 @@ import kotlinx.html.html import kotlinx.html.li import kotlinx.html.ol import kotlinx.html.stream.createHTML +import java.util.ResourceBundle + +class DetailsController(private val model: Model, private val config: Config) { + @FXML + private lateinit var resources: ResourceBundle -class DetailsController(private val model: Model) { @FXML private lateinit var tabPaneDetails: TabPane @@ -56,6 +61,7 @@ class DetailsController(private val model: Model) { tabPaneDetails.disableProperty().bind(Bindings.isNull(model.selectedEntry)) + listViewWords.cellFactory = DictionaryEntryCellFactory(resources) listViewWords.items = model.wordsContaining tabPaneDetails.selectionModel.selectedItemProperty().addListener { _, _, selectedTab -> if (model.selectedEntry.value == null) return@addListener @@ -79,6 +85,13 @@ class DetailsController(private val model: Model) { if (newValue == null) { return@addListener } + when (tabPaneDetails.selectionModel.selectedItem.id) { + "tabWords" -> { + model.findWords() + } + + else -> {} + } webViewDefinition.engine.loadContent( createHTML().html { body { diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/ListController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/ListController.kt index 270f479..e9432a7 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/ListController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/ListController.kt @@ -2,13 +2,18 @@ package com.marvinelsen.willow.ui.controllers import com.marvinelsen.willow.Model import com.marvinelsen.willow.ui.DictionaryEntryFx +import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory import javafx.beans.binding.Bindings import javafx.fxml.FXML import javafx.scene.control.Label import javafx.scene.control.ListView import javafx.scene.control.ProgressIndicator +import java.util.ResourceBundle class ListController(private val model: Model) { + @FXML + private lateinit var resources: ResourceBundle + @FXML private lateinit var progressIndicatorEntries: ProgressIndicator @@ -22,6 +27,7 @@ class ListController(private val model: Model) { @FXML @Suppress("UnusedPrivateMember") private fun initialize() { + listViewSearchResults.cellFactory = DictionaryEntryCellFactory(resources) listViewSearchResults.items = model.searchResults listViewSearchResults .disableProperty() diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt b/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt index 194b4b7..6dcdcb6 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt @@ -1,19 +1,19 @@ package com.marvinelsen.willow.ui.util -import com.marvinelsen.willow.WillowApplication import com.marvinelsen.willow.ui.DictionaryEntryFx import javafx.event.EventHandler import javafx.scene.control.ContextMenu import javafx.scene.control.MenuItem +import java.util.ResourceBundle -fun createContextMenuForEntry(entry: DictionaryEntryFx) = ContextMenu().apply { +fun createContextMenuForEntry(entry: DictionaryEntryFx, resourceBundle: ResourceBundle) = ContextMenu().apply { val menuItemCopyHeadword = - MenuItem(WillowApplication.resourceBundle.getString("menubar.edit.copy.headword")).apply { + MenuItem(resourceBundle.getString("menubar.edit.copy.headword")).apply { onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) } } val menuItemCopyPronunciation = - MenuItem(WillowApplication.resourceBundle.getString("menubar.edit.copy.pronunciation")).apply { + MenuItem(resourceBundle.getString("menubar.edit.copy.pronunciation")).apply { onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarksProperty.value) } } diff --git a/src/main/resources/fxml/details.fxml b/src/main/resources/fxml/details.fxml index a641ffb..2aa60ab 100644 --- a/src/main/resources/fxml/details.fxml +++ b/src/main/resources/fxml/details.fxml @@ -22,11 +22,7 @@ - - - - - + diff --git a/src/main/resources/fxml/list.fxml b/src/main/resources/fxml/list.fxml index 0eaaeb5..2c6a988 100644 --- a/src/main/resources/fxml/list.fxml +++ b/src/main/resources/fxml/list.fxml @@ -1,6 +1,5 @@ - @@ -9,11 +8,7 @@ - - - - - +