diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt b/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt index 001eaf7..dc06116 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/cells/SentenceCellFactory.kt @@ -1,16 +1,19 @@ package com.marvinelsen.willow.ui.cells +import com.marvinelsen.willow.config.Config +import com.marvinelsen.willow.config.Script import com.marvinelsen.willow.ui.SentenceFx +import javafx.beans.binding.Bindings import javafx.scene.control.Label import javafx.scene.control.ListCell import javafx.scene.control.ListView import javafx.scene.layout.VBox import javafx.util.Callback -class SentenceCellFactory() : Callback, ListCell> { +class SentenceCellFactory(private val config: Config) : Callback, ListCell> { override fun call(listView: ListView): ListCell { - val sentenceCell = SentenceCell() + val sentenceCell = SentenceCell(config) sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING)) return sentenceCell } @@ -20,12 +23,11 @@ class SentenceCellFactory() : Callback, ListCell() { - private val labelTraditional = Label().apply { - styleClass.add("chinese") - styleClass.add("list-view-sentence-cell") +private class SentenceCell(private val config: Config) : ListCell() { + private val labelSentence = Label().apply { + styleClass.add("sentence") } - private val root = VBox(labelTraditional) + private val root = VBox(labelSentence) init { text = null @@ -36,7 +38,18 @@ internal class SentenceCell() : ListCell() { if (empty || sentence == null) { graphic = null } else { - labelTraditional.text = sentence.traditionalProperty.value + labelSentence.textProperty().bind( + Bindings.createStringBinding( + { + when (config.script.value!!) { + Script.SIMPLIFIED -> sentence.simplifiedProperty.value + Script.TRADITIONAL -> sentence.traditionalProperty.value + } + }, + config.script + ) + ) + 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 cedc68a..fbae74e 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt @@ -182,7 +182,7 @@ class DetailsController(private val model: Model, private val config: Config) { private fun initializeListViewSentences() { listViewSentences.apply { - cellFactory = SentenceCellFactory() + cellFactory = SentenceCellFactory(config) items = model.sentences disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences))) diff --git a/src/main/resources/css/details.css b/src/main/resources/css/details.css index db8b0ea..384f842 100644 --- a/src/main/resources/css/details.css +++ b/src/main/resources/css/details.css @@ -9,3 +9,8 @@ .list-view .headword { -fx-font-family: "Noto Sans TC"; } + +.list-view .sentence { + -fx-font-family: "Noto Sans TC"; + -fx-font-size: 14px; +}