Refactor resource bundle handling
This commit is contained in:
parent
9ac6f51743
commit
02257b7e6b
@ -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)
|
||||
|
@ -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<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
|
||||
class DictionaryEntryCellFactory(private val resources: ResourceBundle) :
|
||||
Callback<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
|
||||
override fun call(listView: ListView<DictionaryEntryFx?>): ListCell<DictionaryEntryFx?> {
|
||||
val entryCell = EntryCell()
|
||||
val entryCell = EntryCell(resources)
|
||||
entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
|
||||
return entryCell
|
||||
}
|
||||
@ -22,7 +24,7 @@ class DictionaryEntryCellFactory : Callback<ListView<DictionaryEntryFx?>, ListCe
|
||||
}
|
||||
}
|
||||
|
||||
internal class EntryCell : ListCell<DictionaryEntryFx?>() {
|
||||
internal class EntryCell(private val resources: ResourceBundle) : ListCell<DictionaryEntryFx?>() {
|
||||
private val labelHeadword = Label().apply {
|
||||
styleClass.add("list-view-entry")
|
||||
}
|
||||
@ -58,7 +60,7 @@ internal class EntryCell : ListCell<DictionaryEntryFx?>() {
|
||||
val definition = entry.definitions.joinToString(separator = " / ") { it.joinToString(separator = "; ") }
|
||||
labelDefinition.text = definition
|
||||
|
||||
contextMenu = createContextMenuForEntry(entry)
|
||||
contextMenu = createContextMenuForEntry(entry, resources)
|
||||
graphic = root
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
@ -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) }
|
||||
}
|
||||
|
||||
|
@ -22,11 +22,7 @@
|
||||
<ListView fx:id="listviewSentences"/>
|
||||
</Tab>
|
||||
<Tab id="tabWords" closable="false" disable="false" text="%tab.words">
|
||||
<ListView fx:id="listViewWords">
|
||||
<cellFactory>
|
||||
<DictionaryEntryCellFactory/>
|
||||
</cellFactory>
|
||||
</ListView>
|
||||
<ListView fx:id="listViewWords"/>
|
||||
</Tab>
|
||||
<Tab closable="false" disable="false" text="%tab.characters">
|
||||
<ListView fx:id="listViewCharacters"/>
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
@ -9,11 +8,7 @@
|
||||
<StackPane xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.marvinelsen.willow.ui.controllers.ListController"
|
||||
stylesheets="/css/main.css">
|
||||
<ListView fx:id="listViewSearchResults" disable="true">
|
||||
<cellFactory>
|
||||
<DictionaryEntryCellFactory/>
|
||||
</cellFactory>
|
||||
</ListView>
|
||||
<ListView fx:id="listViewSearchResults" disable="true"/>
|
||||
<Label fx:id="labelNoEntriesFound" text="%list.no_entries_found" textAlignment="CENTER"
|
||||
visible="false" wrapText="true">
|
||||
<padding>
|
||||
|
Loading…
Reference in New Issue
Block a user