New Features #1
@ -25,36 +25,31 @@ import java.util.ResourceBundle
|
||||
|
||||
class DetailsController(private val model: Model, private val config: Config) {
|
||||
@FXML
|
||||
private lateinit var flowPaneSelectedEntry: FlowPane
|
||||
private lateinit var resources: ResourceBundle
|
||||
|
||||
@FXML
|
||||
private lateinit var flowPaneHeader: FlowPane
|
||||
|
||||
@FXML
|
||||
private lateinit var labelHeadword: Label
|
||||
|
||||
@FXML
|
||||
private lateinit var labelPronunciation: Label
|
||||
|
||||
@FXML
|
||||
private lateinit var resources: ResourceBundle
|
||||
|
||||
@FXML
|
||||
private lateinit var tabPaneDetails: TabPane
|
||||
|
||||
@FXML
|
||||
private lateinit var webViewDefinition: WebView
|
||||
|
||||
@FXML
|
||||
@Suppress("UnusedPrivateProperty")
|
||||
private lateinit var listviewSentences: ListView<DictionaryEntryFx>
|
||||
|
||||
@FXML
|
||||
private lateinit var listViewWords: ListView<DictionaryEntryFx>
|
||||
|
||||
@FXML
|
||||
@Suppress("UnusedPrivateProperty")
|
||||
private lateinit var listViewCharacters: ListView<DictionaryEntryFx>
|
||||
|
||||
@FXML
|
||||
private lateinit var labelHeadword: Label
|
||||
|
||||
@FXML
|
||||
@Suppress("UnusedPrivateMember")
|
||||
private fun initialize() {
|
||||
initializeLabelHeadword()
|
||||
initializeLabelPronunciation()
|
||||
@ -62,28 +57,74 @@ class DetailsController(private val model: Model, private val config: Config) {
|
||||
initializeListViewWords()
|
||||
initializeListViewCharacters()
|
||||
initializeWebViewDefinition()
|
||||
}
|
||||
|
||||
private fun initializeLabelHeadword() {
|
||||
labelHeadword.apply {
|
||||
textProperty().bind(
|
||||
Bindings.createStringBinding(
|
||||
{
|
||||
val selectedEntry = model.selectedEntry.value
|
||||
when (config.script.value!!) {
|
||||
Script.SIMPLIFIED -> selectedEntry?.simplifiedProperty?.value
|
||||
Script.TRADITIONAL -> selectedEntry?.traditionalProperty?.value
|
||||
}
|
||||
},
|
||||
config.script,
|
||||
model.selectedEntry
|
||||
)
|
||||
)
|
||||
styleProperty().bind(
|
||||
Bindings.concat(
|
||||
"-fx-font-size: ",
|
||||
config.details.headwordFontSize.asString(),
|
||||
"px;"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeLabelPronunciation() {
|
||||
labelPronunciation.apply {
|
||||
textProperty().bind(
|
||||
Bindings.createStringBinding(
|
||||
{
|
||||
val selectedEntry = model.selectedEntry.value
|
||||
when (config.details.pronunciation.value!!) {
|
||||
Pronunciation.PINYIN_WITH_TONE_MARKS -> selectedEntry?.pinyinWithToneMarksProperty?.value
|
||||
Pronunciation.PINYIN_WITH_TONE_NUMBERS -> selectedEntry?.pinyinWithToneNumbersProperty?.value
|
||||
Pronunciation.ZHUYIN -> selectedEntry?.zhuyinProperty?.value
|
||||
}
|
||||
},
|
||||
config.details.pronunciation,
|
||||
model.selectedEntry
|
||||
)
|
||||
)
|
||||
styleProperty().bind(
|
||||
Bindings.concat(
|
||||
"-fx-font-size: ",
|
||||
config.details.pronunciationFontSize.asString(),
|
||||
"px;"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeTabPaneDetails() {
|
||||
tabPaneDetails.apply {
|
||||
disableProperty().bind(Bindings.isNull(model.selectedEntry))
|
||||
|
||||
selectionModel.selectedItemProperty().addListener { _, _, selectedTab ->
|
||||
if (model.selectedEntry.value == null) return@addListener
|
||||
|
||||
lazyUpdateTabContent(selectedTab.id)
|
||||
}
|
||||
}
|
||||
|
||||
model.selectedEntry.addListener { _, _, newEntry ->
|
||||
if (newEntry == null) return@addListener
|
||||
|
||||
when (tabPaneDetails.selectionModel.selectedItem.id) {
|
||||
"tabWords" -> {
|
||||
model.findWords()
|
||||
}
|
||||
|
||||
"tabCharacters" -> {
|
||||
model.findCharacters()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
webViewDefinition.engine.loadContent(newEntry.createCedictDefinitionHtml())
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeWebViewDefinition() {
|
||||
webViewDefinition.apply {
|
||||
engine.userStyleSheetLocation = this::class.java.getResource("/css/definitions.css")!!.toExternalForm()
|
||||
lazyUpdateTabContent(tabPaneDetails.selectionModel.selectedItem.id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,68 +142,15 @@ class DetailsController(private val model: Model, private val config: Config) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeTabPaneDetails() {
|
||||
tabPaneDetails.apply {
|
||||
disableProperty().bind(Bindings.isNull(model.selectedEntry))
|
||||
|
||||
selectionModel.selectedItemProperty().addListener { _, _, selectedTab ->
|
||||
if (model.selectedEntry.value == null) return@addListener
|
||||
|
||||
when (selectedTab.id) {
|
||||
"tabWords" -> {
|
||||
model.findWords()
|
||||
}
|
||||
|
||||
"tabCharacters" -> {
|
||||
model.findCharacters()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
private fun initializeWebViewDefinition() {
|
||||
webViewDefinition.apply {
|
||||
engine.userStyleSheetLocation = this::class.java.getResource("/css/definitions.css")!!.toExternalForm()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeLabelHeadword() {
|
||||
labelHeadword.apply {
|
||||
textProperty().bind(
|
||||
Bindings.createStringBinding(
|
||||
{
|
||||
when (config.script.value!!) {
|
||||
Script.SIMPLIFIED -> model.selectedEntry.value?.simplifiedProperty?.value
|
||||
Script.TRADITIONAL -> model.selectedEntry.value?.traditionalProperty?.value
|
||||
}
|
||||
},
|
||||
config.script,
|
||||
model.selectedEntry
|
||||
)
|
||||
)
|
||||
styleProperty().bind(Bindings.concat("-fx-font-size: ", config.details.headwordFontSize.asString(), "px;"))
|
||||
}
|
||||
}
|
||||
model.selectedEntry.addListener { _, _, newEntry ->
|
||||
if (newEntry == null) return@addListener
|
||||
|
||||
private fun initializeLabelPronunciation() {
|
||||
labelPronunciation.apply {
|
||||
textProperty().bind(
|
||||
Bindings.createStringBinding(
|
||||
{
|
||||
when (config.details.pronunciation.value!!) {
|
||||
Pronunciation.PINYIN_WITH_TONE_MARKS -> model.selectedEntry.value?.pinyinWithToneMarksProperty?.value
|
||||
Pronunciation.PINYIN_WITH_TONE_NUMBERS -> model.selectedEntry.value?.pinyinWithToneNumbersProperty?.value
|
||||
Pronunciation.ZHUYIN -> model.selectedEntry.value?.zhuyinProperty?.value
|
||||
}
|
||||
},
|
||||
config.details.pronunciation,
|
||||
model.selectedEntry
|
||||
)
|
||||
)
|
||||
styleProperty().bind(
|
||||
Bindings.concat(
|
||||
"-fx-font-size: ",
|
||||
config.details.pronunciationFontSize.asString(),
|
||||
"px;"
|
||||
)
|
||||
)
|
||||
webViewDefinition.engine.loadContent(newEntry.createCedictDefinitionHtml())
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,13 +169,26 @@ class DetailsController(private val model: Model, private val config: Config) {
|
||||
}
|
||||
}
|
||||
|
||||
fun showSelectedEntryContextMenu(contextMenuEvent: ContextMenuEvent) {
|
||||
@FXML
|
||||
private fun headerOnContextMenuRequested(contextMenuEvent: ContextMenuEvent) {
|
||||
if (model.selectedEntry.value == null) return
|
||||
|
||||
createContextMenuForEntry(model.selectedEntry.value, resources).show(
|
||||
flowPaneSelectedEntry.scene.window,
|
||||
flowPaneHeader.scene.window,
|
||||
contextMenuEvent.screenX,
|
||||
contextMenuEvent.screenY
|
||||
)
|
||||
}
|
||||
|
||||
private fun lazyUpdateTabContent(selectedTabId: String?) = when (selectedTabId) {
|
||||
"tabWords" -> {
|
||||
model.findWords()
|
||||
}
|
||||
|
||||
"tabCharacters" -> {
|
||||
model.findCharacters()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
<VBox xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="com.marvinelsen.willow.ui.controllers.DetailsController"
|
||||
stylesheets="/css/details.css">
|
||||
<FlowPane fx:id="flowPaneSelectedEntry" hgap="8.0" onContextMenuRequested="#showSelectedEntryContextMenu"
|
||||
<FlowPane fx:id="flowPaneHeader" hgap="8.0" onContextMenuRequested="#headerOnContextMenuRequested"
|
||||
prefHeight="38.0" prefWidth="412.0" rowValignment="BASELINE" vgap="8.0" VBox.vgrow="NEVER">
|
||||
<padding>
|
||||
<Insets bottom="6.0" left="6.0" right="6.0" top="6.0"/>
|
||||
@ -26,7 +26,7 @@
|
||||
<WebView fx:id="webViewDefinition" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0"/>
|
||||
</Tab>
|
||||
<Tab id="tabSentences" closable="false" text="%tab.sentences">
|
||||
<ListView fx:id="listviewSentences"/>
|
||||
<ListView fx:id="listViewSentences"/>
|
||||
</Tab>
|
||||
<Tab id="tabWords" closable="false" text="%tab.words">
|
||||
<ListView fx:id="listViewWords"/>
|
||||
|
Loading…
Reference in New Issue
Block a user