Compare commits

..

76 Commits

Author SHA1 Message Date
1b5c32c320
Improve i18n
All checks were successful
Pull Request / build (pull_request) Successful in 3m35s
2024-10-17 22:18:08 +02:00
e028bed311
Fix horizontal scrollbar showing up on search results listview 2024-10-17 21:33:25 +02:00
6f59af3cde
Cleanup .fxml files 2024-10-17 21:33:04 +02:00
4b84ec5a82
Wrap example sentences 2024-10-17 21:10:27 +02:00
039cb7e0a8
Cleanup details.fxml 2024-10-17 21:10:13 +02:00
c427af15b6
Implement words beginning and refactor words containing
All checks were successful
Pull Request / build (pull_request) Successful in 3m35s
2024-10-14 22:44:48 +02:00
40222f67ed
Refactor DetailsController and fix detekt issues 2024-10-14 22:11:17 +02:00
a4e5b9145f
Refactor sentence listview by showing simplified or traditional and setting correct font family and font size 2024-10-14 21:51:16 +02:00
168d1634a2
Implement find sentence function 2024-10-14 21:46:09 +02:00
50017f45c4
Add slf4j-nop dependency 2024-10-14 21:44:17 +02:00
dbc482bee4
Refactor TatoebaSentence class to just Sentence 2024-10-14 19:17:33 +02:00
8db4c3879f
Improve find character feature by only looking for traditional characters 2024-10-14 17:19:03 +02:00
ea1973a3cf
Improve find characters query to only show characters with the same pronunciation
Some checks failed
Pull Request / build (pull_request) Failing after 2m42s
2024-10-10 23:17:13 +02:00
af3a291536
Fix some detekt issues
Some checks failed
Pull Request / build (pull_request) Failing after 2m46s
2024-10-10 22:38:58 +02:00
eebf3864a9
Add new words from moedict and cross-straits to segmentation dictionary 2024-10-10 22:37:57 +02:00
33402c0fcb
Show definitions of cross-straits or moe in search results, if cedict definitions are not available 2024-10-10 22:26:22 +02:00
898a5d3cc5
Fix preference dialog root to resize with scene and fill stage properly
See: https://stackoverflow.com/a/77470109
2024-10-10 20:32:43 +02:00
1c5b7d9bcc
Disable characters tab for entries that only contain a single character 2024-10-10 12:19:33 +02:00
cf07585361
Add moedict definitions
Some checks failed
Pull Request / build (pull_request) Failing after 2m47s
2024-10-09 23:17:48 +02:00
86aa108e52
Fix detekt issues
All checks were successful
Pull Request / build (pull_request) Successful in 3m25s
2024-10-09 19:54:26 +02:00
2fcdda5ae3
Remove database generation code 2024-10-09 19:53:35 +02:00
f344c8df23
Add cross-straits definitions 2024-10-09 19:52:54 +02:00
eb3beb0dfe
Remove English search mode 2024-10-07 23:00:04 +02:00
7dab46364e
Bump version of chinese-transliteration and cedict parser 2024-10-07 21:06:23 +02:00
3cf4e0f600
Add apache commons csv dependency 2024-10-07 18:11:44 +02:00
2c11a3563f
Rename definitions db column to cedict_definitions 2024-10-07 18:08:43 +02:00
c7bd51408a
Update cedict 2024-10-07 18:08:07 +02:00
06fb624a38
Set definition font size to 14px
All checks were successful
Pull Request / build (pull_request) Successful in 3m29s
2024-10-07 00:22:46 +02:00
48359c0601
Remove unnecessary padding from headword label in details 2024-10-07 00:03:19 +02:00
07cf27863b
Set default details headword font size to 50 2024-10-07 00:02:28 +02:00
b939f23b9f
Set min width for search results list view 2024-10-07 00:02:12 +02:00
9baa66bde9
Use correct font size in words and characters lists 2024-10-06 23:29:29 +02:00
15b2138f77
Do not make the headword bold in search results 2024-10-06 23:25:32 +02:00
6ebdf4051c
More dark theme WIP
All checks were successful
Pull Request / build (pull_request) Successful in 3m22s
2024-10-03 21:33:19 +02:00
ee989b8997
Split preferences dialog into Dialog and Controller 2024-10-03 21:33:07 +02:00
d48c1b2bf2
Split up services into their own files 2024-10-03 16:26:01 +02:00
d473eafe35
Continue WIP work on darkmode 2024-10-03 16:22:51 +02:00
46af4db9f1
Fix detekt issues
All checks were successful
Pull Request / build (pull_request) Successful in 3m26s
2024-10-03 13:40:58 +02:00
630d464916
Polish words and character list 2024-10-03 13:38:40 +02:00
f6f2cfac5c
Refactor details controller 2024-10-03 13:16:51 +02:00
8ada0a5510
Add context menu for details view 2024-10-03 12:50:30 +02:00
12eb98d5b1
Display pronunciation in details view 2024-10-03 12:41:12 +02:00
d9b7b82c60
Implement find characters 2024-10-03 12:11:50 +02:00
cb52240eea
Add ikonli dependency 2024-10-01 20:17:39 +02:00
3939021285
Add application icon 2024-10-01 20:08:08 +02:00
1ab6ef453a
Load dictionary database from resources 2024-09-29 23:29:42 +02:00
7add73fe28
Fix detekt issues
All checks were successful
Pull Request / build (pull_request) Successful in 3m37s
2024-09-28 20:08:18 +02:00
62c57d1e85
Implement segmented phrase search mode 2024-09-28 19:45:57 +02:00
387e10dd50
Add dependency to segment for Chinese word segmentation 2024-09-28 18:27:41 +02:00
6f5b8427e0
Refactor name of search results files 2024-09-28 16:18:25 +02:00
c9c794604b
Move preferences dialog FXML file to sub directory 2024-09-28 16:16:09 +02:00
039efe8b6c
Refactor search results styling 2024-09-28 16:12:40 +02:00
8c5ac438c2
Add initial dark mode style 2024-09-28 16:12:25 +02:00
cb5eb95b04
Implement preferences 2024-09-28 16:12:11 +02:00
6446c2d9c8
Add general tab to preferences and refactor FX IDs 2024-09-27 11:39:55 +02:00
bc9d09c39f
Fix preferences dialog CSS styling
All checks were successful
Pull Request / build (pull_request) Successful in 3m22s
2024-09-26 23:26:45 +02:00
6003bc678e
Rename settings dialog to preferences dialog 2024-09-26 23:14:10 +02:00
fee7cbf260
Fix detekt issues 2024-09-26 23:12:00 +02:00
02257b7e6b
Refactor resource bundle handling 2024-09-26 23:10:40 +02:00
9ac6f51743
Implement preference dialog 2024-09-26 23:10:07 +02:00
cc1da1f7b5
Rename settings to preferences 2024-09-26 23:08:10 +02:00
8350cb3b3d
Refactor ClipboardHelper 2024-09-26 10:33:31 +02:00
efde0dcdb4
Show label for no entries found 2024-09-26 10:09:55 +02:00
9508412427
Refactor listview to its own FXML file and controller 2024-09-26 09:18:40 +02:00
49fe0f65bd
Update JavaFX version to 23
All checks were successful
Pull Request / build (pull_request) Successful in 3m26s
2024-09-25 23:42:14 +02:00
231b4eb0fe
Use different shortcut to copy headword
CTRL+C overwrites the 'Copy' shortcut for every other GUI element, so the user cannot copy the definition of the word.
2024-09-22 23:14:27 +02:00
cdcfd92f60
Refactor HTML definition in detail view
All checks were successful
Pull Request / build (pull_request) Successful in 3m31s
2024-09-21 20:19:00 +02:00
30f88c9e3e
Configure correct cell factory for words containing list 2024-09-21 20:10:44 +02:00
a88b4d409d
Implement find characters query 2024-09-21 18:03:58 +02:00
cfaff6c6b9
Use resource bundle string for context menu 2024-09-21 13:47:35 +02:00
ac182c10c0
Create global resource bundle 2024-09-21 13:47:25 +02:00
47d53d4df8
Add context menu to list entries 2024-09-21 13:41:45 +02:00
573515217e
Execute search when user changes search mode 2024-09-20 20:23:05 +02:00
239d0d7da2
Disable English mode 2024-09-20 20:14:38 +02:00
a65c1db941
Implement Pinyin search 2024-09-20 20:10:12 +02:00
3a159fba76
Update Noto Sans TC font 2024-09-20 20:09:06 +02:00
66 changed files with 238145 additions and 936 deletions

View File

@ -20,14 +20,17 @@ repositories {
dependencies { dependencies {
detektPlugins(libs.detekt.formatting) detektPlugins(libs.detekt.formatting)
implementation(libs.chinese.transliteration)
implementation(libs.cedict.parser)
implementation(libs.sqlite.jdbc) implementation(libs.sqlite.jdbc)
implementation(libs.kotlinx.serialization.json) implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.html.jvm) implementation(libs.kotlinx.html.jvm)
implementation(libs.segment)
implementation(libs.ikonli.javafx)
implementation(libs.slf4j.nop)
testImplementation(libs.kotest.core) testImplementation(libs.kotest.core)
testImplementation(libs.kotest.assertions) testImplementation(libs.kotest.assertions)
} }

View File

@ -2,22 +2,22 @@
kotlin = "2.0.20" kotlin = "2.0.20"
detekt = "1.23.7" detekt = "1.23.7"
jfx-plugin = "0.1.0" jfx-plugin = "0.1.0"
javafx = "22.0.1" javafx = "23"
kotest = "5.9.1" kotest = "5.9.1"
cedict-parser = "1.0.1"
chinese-transliteration = "1.0.1"
sqlite-jdbc = "3.46.0.1" sqlite-jdbc = "3.46.0.1"
kotlinx-serialization-json = "1.7.1" kotlinx-serialization-json = "1.7.1"
kotlinx-html-jvm = "0.11.0" kotlinx-html-jvm = "0.11.0"
[libraries] segment = "0.3.1"
chinese-transliteration = { module = "com.marvinelsen:chinese-transliteration", version.ref = "chinese-transliteration" }
cedict-parser = { module = "com.marvinelsen:cedict-parser", version.ref = "cedict-parser" }
ikonli-javafx = "12.3.1"
slf4j = "2.0.16"
[libraries]
# Kotest # Kotest
# See: https://kotest.io # See: https://kotest.io
kotest-core = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } kotest-core = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
@ -28,6 +28,11 @@ sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite-jdbc" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
kotlinx-html-jvm = { module = "org.jetbrains.kotlinx:kotlinx-html-jvm", version.ref = "kotlinx-html-jvm" } kotlinx-html-jvm = { module = "org.jetbrains.kotlinx:kotlinx-html-jvm", version.ref = "kotlinx-html-jvm" }
segment = { module = "com.github.houbb:segment", version.ref = "segment" }
slf4j-nop = { module = "org.slf4j:slf4j-nop", version.ref = "slf4j" }
ikonli-javafx = { module = "org.kordamp.ikonli:ikonli-javafx", version.ref = "ikonli-javafx" }
# Detekt # Detekt
# See: https://detekt.dev # See: https://detekt.dev
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }

View File

@ -2,9 +2,13 @@ package com.marvinelsen.willow
import com.marvinelsen.willow.domain.SearchMode import com.marvinelsen.willow.domain.SearchMode
import com.marvinelsen.willow.ui.DictionaryEntryFx import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.SentenceFx
import com.marvinelsen.willow.ui.services.FindCharacterService
import com.marvinelsen.willow.ui.services.FindSentencesService
import com.marvinelsen.willow.ui.services.FindWordsBeginningService
import com.marvinelsen.willow.ui.services.FindWordsContainingService
import com.marvinelsen.willow.ui.services.SearchService
import com.marvinelsen.willow.ui.util.ClipboardHelper import com.marvinelsen.willow.ui.util.ClipboardHelper
import com.marvinelsen.willow.ui.util.FindWordsService
import com.marvinelsen.willow.ui.util.SearchService
import javafx.beans.property.ObjectProperty import javafx.beans.property.ObjectProperty
import javafx.beans.property.ReadOnlyBooleanProperty import javafx.beans.property.ReadOnlyBooleanProperty
import javafx.beans.property.ReadOnlyObjectProperty import javafx.beans.property.ReadOnlyObjectProperty
@ -13,27 +17,54 @@ import javafx.collections.FXCollections
import javafx.collections.ObservableList import javafx.collections.ObservableList
import javafx.event.EventHandler import javafx.event.EventHandler
class Model(private val searchService: SearchService, private val findWordsService: FindWordsService) { class Model(
private val searchService: SearchService,
private val findWordsBeginningService: FindWordsBeginningService,
private val findWordsContainingService: FindWordsContainingService,
private val findCharacterService: FindCharacterService,
private val findSentencesService: FindSentencesService,
) {
private val internalSelectedEntry: ObjectProperty<DictionaryEntryFx> = SimpleObjectProperty() private val internalSelectedEntry: ObjectProperty<DictionaryEntryFx> = SimpleObjectProperty()
private val internalSearchResults: ObservableList<DictionaryEntryFx> = FXCollections.observableArrayList() private val internalSearchResults: ObservableList<DictionaryEntryFx> = FXCollections.observableArrayList()
private val internalWordsBeginning: ObservableList<DictionaryEntryFx> = FXCollections.observableArrayList()
private val internalWordsContaining: ObservableList<DictionaryEntryFx> = FXCollections.observableArrayList() private val internalWordsContaining: ObservableList<DictionaryEntryFx> = FXCollections.observableArrayList()
private val internalCharacters: ObservableList<DictionaryEntryFx> = FXCollections.observableArrayList()
private val internalSentences: ObservableList<SentenceFx> = FXCollections.observableArrayList()
val selectedEntry: ReadOnlyObjectProperty<DictionaryEntryFx> = internalSelectedEntry val selectedEntry: ReadOnlyObjectProperty<DictionaryEntryFx> = internalSelectedEntry
val searchResults: ObservableList<DictionaryEntryFx> = val searchResults: ObservableList<DictionaryEntryFx> =
FXCollections.unmodifiableObservableList(internalSearchResults) FXCollections.unmodifiableObservableList(internalSearchResults)
val wordsBeginning: ObservableList<DictionaryEntryFx> =
FXCollections.unmodifiableObservableList(internalWordsBeginning)
val wordsContaining: ObservableList<DictionaryEntryFx> = val wordsContaining: ObservableList<DictionaryEntryFx> =
FXCollections.unmodifiableObservableList(internalWordsContaining) FXCollections.unmodifiableObservableList(internalWordsContaining)
val characters: ObservableList<DictionaryEntryFx> =
FXCollections.unmodifiableObservableList(internalCharacters)
val sentences: ObservableList<SentenceFx> =
FXCollections.unmodifiableObservableList(internalSentences)
val isSearching: ReadOnlyBooleanProperty = searchService.runningProperty() val isSearching: ReadOnlyBooleanProperty = searchService.runningProperty()
val isFindingWords: ReadOnlyBooleanProperty = findWordsService.runningProperty() val isFindingWordsBeginning: ReadOnlyBooleanProperty = findWordsBeginningService.runningProperty()
val isFindingWordsContaining: ReadOnlyBooleanProperty = findWordsContainingService.runningProperty()
val isFindingCharacters: ReadOnlyBooleanProperty = findCharacterService.runningProperty()
val isFindingSentences: ReadOnlyBooleanProperty = findSentencesService.runningProperty()
init { init {
searchService.onSucceeded = EventHandler { searchService.onSucceeded = EventHandler {
internalSearchResults.setAll(searchService.value) internalSearchResults.setAll(searchService.value)
} }
findWordsService.onSucceeded = EventHandler { findWordsBeginningService.onSucceeded = EventHandler {
internalWordsContaining.setAll(findWordsService.value) internalWordsBeginning.setAll(findWordsBeginningService.value)
}
findWordsContainingService.onSucceeded = EventHandler {
internalWordsContaining.setAll(findWordsContainingService.value)
}
findCharacterService.onSucceeded = EventHandler {
internalCharacters.setAll(findCharacterService.value)
}
findSentencesService.onSucceeded = EventHandler {
internalSentences.setAll(findSentencesService.value)
} }
} }
@ -43,20 +74,39 @@ class Model(private val searchService: SearchService, private val findWordsServi
searchService.restart() searchService.restart()
} }
fun findWords() { fun findWordsBeginning() {
findWordsService.entry = internalSelectedEntry.value findWordsBeginningService.entry = internalSelectedEntry.value
findWordsService.restart() findWordsBeginningService.restart()
}
fun findWordsContaining() {
findWordsContainingService.entry = internalSelectedEntry.value
findWordsContainingService.restart()
}
fun findCharacters() {
findCharacterService.entry = internalSelectedEntry.value
findCharacterService.restart()
}
fun findSentences() {
findSentencesService.entry = internalSelectedEntry.value
findSentencesService.restart()
} }
fun selectEntry(entry: DictionaryEntryFx) { fun selectEntry(entry: DictionaryEntryFx) {
internalWordsBeginning.setAll(emptyList())
internalWordsContaining.setAll(emptyList())
internalCharacters.setAll(emptyList())
internalSentences.setAll(emptyList())
internalSelectedEntry.value = entry internalSelectedEntry.value = entry
} }
fun copyHeadwordOfSelectedEntry() { fun copyHeadwordOfSelectedEntry() {
ClipboardHelper.copyHeadword(internalSelectedEntry.get()) ClipboardHelper.copyString(internalSelectedEntry.value.traditionalProperty.value)
} }
fun copyPronunciationOfSelectedEntry() { fun copyPronunciationOfSelectedEntry() {
ClipboardHelper.copyPronunciation(internalSelectedEntry.get()) ClipboardHelper.copyString(internalSelectedEntry.value.pinyinWithToneMarksProperty.value)
} }
} }

View File

@ -1,21 +1,26 @@
package com.marvinelsen.willow package com.marvinelsen.willow
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.domain.SqliteDictionary import com.marvinelsen.willow.domain.SqliteDictionary
import com.marvinelsen.willow.ui.controllers.DetailsController import com.marvinelsen.willow.ui.controllers.DetailsController
import com.marvinelsen.willow.ui.controllers.MainController import com.marvinelsen.willow.ui.controllers.MainController
import com.marvinelsen.willow.ui.controllers.MenuController import com.marvinelsen.willow.ui.controllers.MenuController
import com.marvinelsen.willow.ui.controllers.SearchController import com.marvinelsen.willow.ui.controllers.SearchController
import com.marvinelsen.willow.ui.util.FindWordsService import com.marvinelsen.willow.ui.controllers.SearchResultsController
import com.marvinelsen.willow.ui.util.SearchService import com.marvinelsen.willow.ui.services.FindCharacterService
import com.marvinelsen.willow.ui.services.FindSentencesService
import com.marvinelsen.willow.ui.services.FindWordsBeginningService
import com.marvinelsen.willow.ui.services.FindWordsContainingService
import com.marvinelsen.willow.ui.services.SearchService
import javafx.application.Application import javafx.application.Application
import javafx.fxml.FXMLLoader import javafx.fxml.FXMLLoader
import javafx.scene.Scene import javafx.scene.Scene
import javafx.scene.image.Image
import javafx.scene.layout.BorderPane import javafx.scene.layout.BorderPane
import javafx.scene.text.Font import javafx.scene.text.Font
import javafx.stage.Stage import javafx.stage.Stage
import javafx.util.Callback import javafx.util.Callback
import java.sql.DriverManager import java.sql.DriverManager
import java.util.Locale
import java.util.ResourceBundle import java.util.ResourceBundle
class WillowApplication : Application() { class WillowApplication : Application() {
@ -28,7 +33,7 @@ class WillowApplication : Application() {
private const val FONT_SIZE = 12.0 private const val FONT_SIZE = 12.0
private const val JDBC_CONNECTION_STRING = "jdbc:sqlite:dictionary.db" private const val JDBC_CONNECTION_STRING = "jdbc:sqlite::resource:data/dictionary.db"
} }
override fun init() { override fun init() {
@ -41,17 +46,29 @@ class WillowApplication : Application() {
} }
val dictionary = SqliteDictionary(connection) val dictionary = SqliteDictionary(connection)
val searchService = SearchService(dictionary) val searchService = SearchService(dictionary)
val findWordsService = FindWordsService(dictionary) val findWordsBeginningService = FindWordsBeginningService(dictionary)
val model = Model(searchService, findWordsService) val findWordsContainingService = FindWordsContainingService(dictionary)
val findCharacterService = FindCharacterService(dictionary)
val findSentenceService = FindSentencesService(dictionary)
val model = Model(
searchService,
findWordsBeginningService,
findWordsContainingService,
findCharacterService,
findSentenceService
)
val config = Config()
config.load()
val fxmlLoader = FXMLLoader() val fxmlLoader = FXMLLoader()
fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", Locale.US) fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", config.locale.value)
fxmlLoader.controllerFactory = Callback { type -> fxmlLoader.controllerFactory = Callback { type ->
when (type) { when (type) {
MainController::class.java -> MainController(model) MainController::class.java -> MainController(model)
MenuController::class.java -> MenuController(model) MenuController::class.java -> MenuController(model, config)
DetailsController::class.java -> DetailsController(model) DetailsController::class.java -> DetailsController(model, config)
SearchController::class.java -> SearchController(model) SearchController::class.java -> SearchController(model)
SearchResultsController::class.java -> SearchResultsController(model, config)
else -> error("Trying to instantiate unknown controller type $type") else -> error("Trying to instantiate unknown controller type $type")
} }
} }
@ -59,19 +76,22 @@ class WillowApplication : Application() {
val root = fxmlLoader.load(javaClass.getResourceAsStream("/fxml/main.fxml")) as BorderPane val root = fxmlLoader.load(javaClass.getResourceAsStream("/fxml/main.fxml")) as BorderPane
val primaryScene = Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT) val primaryScene = Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT)
// primaryScene.stylesheets.add(javaClass.getResource("/css/dark.css")?.toExternalForm()!!)
primaryStage.apply { primaryStage.apply {
title = WINDOW_TITLE title = WINDOW_TITLE
minWidth = WINDOW_MIN_WIDTH minWidth = WINDOW_MIN_WIDTH
minHeight = WINDOW_MIN_HEIGHT minHeight = WINDOW_MIN_HEIGHT
scene = primaryScene scene = primaryScene
icons.add(Image(javaClass.getResourceAsStream("/img/icon.png")))
}.show() }.show()
} }
private fun loadFonts() { private fun loadFonts() {
Font.loadFont(javaClass.getResourceAsStream("/fonts/inter.ttf"), FONT_SIZE) Font.loadFont(javaClass.getResourceAsStream("/fonts/inter.ttf"), FONT_SIZE)
Font.loadFont(javaClass.getResourceAsStream("/fonts/tw-kai.ttf"), FONT_SIZE) Font.loadFont(javaClass.getResourceAsStream("/fonts/tw-kai.ttf"), FONT_SIZE)
Font.loadFont(javaClass.getResourceAsStream("/fonts/noto-sans-tc.ttf"), FONT_SIZE) Font.loadFont(javaClass.getResourceAsStream("/fonts/noto-sans-tc-regular.ttf"), FONT_SIZE)
Font.loadFont(javaClass.getResourceAsStream("/fonts/noto-sans-tc-bold.ttf"), FONT_SIZE)
} }
} }

View File

@ -1,93 +0,0 @@
package com.marvinelsen.willow.cedict
import com.marvinelsen.cedict.api.CedictParser
import com.marvinelsen.chinese.transliteration.TransliterationSystem
import com.marvinelsen.chinese.transliteration.Zhuyin
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.Json
import java.sql.DriverManager
import java.util.zip.GZIPInputStream
const val JDBC_CONNECTION_STRING = "jdbc:sqlite:dictionary.db"
@Suppress("MagicNumber", "LongMethod", "MaximumLineLength", "MaxLineLength")
fun main() {
val connection = DriverManager.getConnection(JDBC_CONNECTION_STRING).apply {
autoCommit = false
}
val statement = connection.createStatement()
statement.executeUpdate(
"""
CREATE TABLE IF NOT EXISTS cedict(
id INTEGER PRIMARY KEY,
traditional TEXT NOT NULL,
simplified TEXT NOT NULL,
pinyin_with_tone_marks TEXT NOT NULL,
pinyin_with_tone_numbers TEXT NOT NULL,
zhuyin TEXT NOT NULL,
definitions JSON NOT NULL,
character_count INTEGER NOT NULL,
CONSTRAINT character_count_gte CHECK(character_count > 0)
);
""".trimIndent()
)
statement.executeUpdate("CREATE INDEX IF NOT EXISTS idx_cedict_traditional ON cedict (traditional)")
statement.executeUpdate("CREATE INDEX IF NOT EXISTS idx_cedict_simplified ON cedict (simplified)")
statement.executeUpdate("CREATE INDEX IF NOT EXISTS idx_cedict_character_count ON cedict (character_count)")
val cedictParser = CedictParser.instance
val cedictEntries =
cedictParser.parseCedict(
GZIPInputStream(object {}.javaClass.getResourceAsStream("/data/cedict_1_0_ts_utf-8_mdbg.txt.gz")!!)
)
val insertStatement =
connection.prepareStatement(
"INSERT OR IGNORE INTO cedict(traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions, character_count) VALUES(?,?,?,?,?,?,?)"
)
for (entry in cedictEntries) {
try {
insertStatement.setString(1, entry.traditional)
insertStatement.setString(2, entry.simplified)
insertStatement.setString(
3,
entry.pinyinSyllables.joinToString(
separator = " "
) { it.format(TransliterationSystem.PINYIN_WITH_TONE_MARKS) }
)
insertStatement.setString(
4,
entry.pinyinSyllables.joinToString(
separator = " "
) { it.format(TransliterationSystem.PINYIN_WITH_TONE_NUMBERS) }
)
insertStatement.setString(
5,
entry.pinyinSyllables.joinToString(
separator = Zhuyin.SEPARATOR
) { it.format(TransliterationSystem.ZHUYIN) }
)
insertStatement.setString(
6,
Json.encodeToString(
ListSerializer(ListSerializer(String.serializer())),
entry.definitions.map { it.glosses }
)
)
insertStatement.setInt(7, entry.traditional.length)
} catch (_: Exception) {
// no-op
}
insertStatement.addBatch()
}
insertStatement.executeBatch()
connection.commit()
insertStatement.close()
statement.close()
connection.close()
}

View File

@ -0,0 +1,166 @@
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 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 details = DetailsConfig(preferences)
val locale: ObjectProperty<Locale> = SimpleObjectProperty(DEFAULT_LOCALE)
val theme: ObjectProperty<Theme> = SimpleObjectProperty(DEFAULT_THEME)
val script: ObjectProperty<Script> = SimpleObjectProperty(DEFAULT_SCRIPT)
fun save() {
preferences.put(LOCALE_KEY, locale.value.toLanguageTag())
preferences.put(THEME_KEY, theme.value.name)
preferences.put(SCRIPT_KEY, script.value.name)
searchResults.save()
details.save()
preferences.flush()
}
fun load() {
preferences.sync()
theme.value = Theme.valueOf(
preferences.get(
THEME_KEY,
DEFAULT_THEME.name
)
)
script.value = Script.valueOf(
preferences.get(
SCRIPT_KEY,
DEFAULT_SCRIPT.name
)
)
locale.value = Locale.forLanguageTag(preferences.get(LOCALE_KEY, DEFAULT_LOCALE.toLanguageTag()))
searchResults.load()
details.load()
}
}
class SearchResultsConfig(private val preferences: Preferences) {
companion object {
private const val PRONUNCIATION_KEY = "searchResultsPronunciation"
private const val HEADWORD_FONT_SIZE_KEY = "searchResultsHeadwordFontSize"
private const val PRONUNCIATION_FONT_SIZE_KEY = "searchResultsPronunciationFontSize"
private const val DEFINITION_FONT_SIZE_KEY = "searchResultsDefinitionFontSize"
private const val SHOULD_SHOW_PRONUNCIATION_KEY = "searchResultsShouldShowPronunciation"
private const val SHOULD_SHOW_DEFINITION_KEY = "searchResultsShouldShowDefinition"
private val DEFAULT_PRONUNCIATION = Pronunciation.PINYIN_WITH_TONE_MARKS
private const val DEFAULT_HEADWORD_FONT_SIZE = 20
private const val DEFAULT_PRONUNCIATION_FONT_SIZE = 14
private const val DEFAULT_DEFINITION_FONT_SIZE = 14
private const val DEFAULT_SHOULD_SHOW_PRONUNCIATION = true
private const val DEFAULT_SHOULD_SHOW_DEFINITION = true
}
val pronunciation: ObjectProperty<Pronunciation> = SimpleObjectProperty(DEFAULT_PRONUNCIATION)
val headwordFontSize: IntegerProperty = SimpleIntegerProperty(DEFAULT_HEADWORD_FONT_SIZE)
val pronunciationFontSize: IntegerProperty = SimpleIntegerProperty(DEFAULT_PRONUNCIATION_FONT_SIZE)
val definitionFontSize: IntegerProperty = SimpleIntegerProperty(DEFAULT_DEFINITION_FONT_SIZE)
val shouldShowPronunciation: BooleanProperty = SimpleBooleanProperty(DEFAULT_SHOULD_SHOW_PRONUNCIATION)
val shouldShowDefinition: BooleanProperty = SimpleBooleanProperty(DEFAULT_SHOULD_SHOW_DEFINITION)
fun save() {
preferences.put(PRONUNCIATION_KEY, pronunciation.value.name)
preferences.putInt(HEADWORD_FONT_SIZE_KEY, headwordFontSize.value)
preferences.putInt(PRONUNCIATION_FONT_SIZE_KEY, pronunciationFontSize.value)
preferences.putInt(DEFINITION_FONT_SIZE_KEY, definitionFontSize.value)
preferences.putBoolean(SHOULD_SHOW_PRONUNCIATION_KEY, shouldShowPronunciation.value)
preferences.putBoolean(SHOULD_SHOW_DEFINITION_KEY, shouldShowDefinition.value)
}
fun load() {
headwordFontSize.value = preferences.getInt(
HEADWORD_FONT_SIZE_KEY,
DEFAULT_HEADWORD_FONT_SIZE
)
pronunciationFontSize.value = preferences.getInt(
PRONUNCIATION_FONT_SIZE_KEY,
DEFAULT_PRONUNCIATION_FONT_SIZE
)
definitionFontSize.value = preferences.getInt(
DEFINITION_FONT_SIZE_KEY,
DEFAULT_DEFINITION_FONT_SIZE
)
shouldShowPronunciation.value = preferences.getBoolean(
SHOULD_SHOW_PRONUNCIATION_KEY,
DEFAULT_SHOULD_SHOW_PRONUNCIATION
)
shouldShowDefinition.value = preferences.getBoolean(
SHOULD_SHOW_DEFINITION_KEY,
DEFAULT_SHOULD_SHOW_DEFINITION
)
pronunciation.value = Pronunciation.valueOf(
preferences.get(
PRONUNCIATION_KEY,
DEFAULT_PRONUNCIATION.name
)
)
}
}
class DetailsConfig(private val preferences: Preferences) {
companion object {
private const val PRONUNCIATION_KEY = "detailsPronunciation"
private const val HEADWORD_FONT_SIZE_KEY = "detailsHeadwordFontSize"
private const val PRONUNCIATION_FONT_SIZE_KEY = "detailsPronunciationFontSize"
private val DEFAULT_PRONUNCIATION = Pronunciation.PINYIN_WITH_TONE_MARKS
private const val DEFAULT_HEADWORD_FONT_SIZE = 50
private const val DEFAULT_PRONUNCIATION_FONT_SIZE = 16
}
val pronunciation: ObjectProperty<Pronunciation> = SimpleObjectProperty(DEFAULT_PRONUNCIATION)
val headwordFontSize: IntegerProperty = SimpleIntegerProperty(DEFAULT_HEADWORD_FONT_SIZE)
val pronunciationFontSize: IntegerProperty = SimpleIntegerProperty(DEFAULT_PRONUNCIATION_FONT_SIZE)
fun save() {
preferences.put(PRONUNCIATION_KEY, pronunciation.value.name)
preferences.putInt(HEADWORD_FONT_SIZE_KEY, headwordFontSize.value)
preferences.putInt(PRONUNCIATION_FONT_SIZE_KEY, pronunciationFontSize.value)
}
fun load() {
headwordFontSize.value = preferences.getInt(
HEADWORD_FONT_SIZE_KEY,
DEFAULT_HEADWORD_FONT_SIZE
)
pronunciationFontSize.value = preferences.getInt(
PRONUNCIATION_FONT_SIZE_KEY,
DEFAULT_PRONUNCIATION_FONT_SIZE
)
pronunciation.value = Pronunciation.valueOf(
preferences.get(
PRONUNCIATION_KEY,
DEFAULT_PRONUNCIATION.name
)
)
}
}

View File

@ -0,0 +1,7 @@
package com.marvinelsen.willow.config
enum class Pronunciation {
PINYIN_WITH_TONE_MARKS,
PINYIN_WITH_TONE_NUMBERS,
ZHUYIN
}

View File

@ -0,0 +1,5 @@
package com.marvinelsen.willow.config
enum class Script {
SIMPLIFIED, TRADITIONAL
}

View File

@ -0,0 +1,5 @@
package com.marvinelsen.willow.config
enum class Theme {
SYSTEM, LIGHT, DARK
}

View File

@ -0,0 +1,9 @@
package com.marvinelsen.willow.domain
import kotlinx.serialization.Serializable
@Serializable
data class CrossStraitsDefinition(
val definition: String,
val examples: List<String>,
)

View File

@ -1,28 +0,0 @@
package com.marvinelsen.willow.domain
import java.sql.DriverManager
import kotlin.time.measureTimedValue
const val JDBC_CONNECTION_STRING = "jdbc:sqlite:dictionary.db"
fun main() {
val connection = DriverManager.getConnection(JDBC_CONNECTION_STRING).apply {
autoCommit = false
}
val sqliteDictionary = SqliteDictionary(connection)
val (searchResults, time) = measureTimedValue {
sqliteDictionary.search("", SearchMode.TRADITIONAL)
}
val (shang, time2) = measureTimedValue {
sqliteDictionary.search("", SearchMode.TRADITIONAL).first()
}
val (shangWords, time3) = measureTimedValue {
sqliteDictionary.findWordsContaining(shang)
}
println(searchResults)
println(shangWords)
println(time)
println(time2)
println(time3)
}

View File

@ -2,7 +2,11 @@ package com.marvinelsen.willow.domain
interface Dictionary { interface Dictionary {
fun search(query: String, searchMode: SearchMode): List<DictionaryEntry> fun search(query: String, searchMode: SearchMode): List<DictionaryEntry>
fun findWordsBeginning(entry: DictionaryEntry): List<DictionaryEntry>
fun findWordsContaining(entry: DictionaryEntry): List<DictionaryEntry> fun findWordsContaining(entry: DictionaryEntry): List<DictionaryEntry>
fun findSentencesContaining(entry: DictionaryEntry): List<DictionaryEntry>
fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry>
fun findSentencesContaining(entry: DictionaryEntry): List<Sentence>
} }

View File

@ -6,5 +6,7 @@ data class DictionaryEntry(
val pinyinWithToneMarks: String, val pinyinWithToneMarks: String,
val pinyinWithToneNumbers: String, val pinyinWithToneNumbers: String,
val zhuyin: String, val zhuyin: String,
val definitions: List<List<String>> val cedictDefinitions: List<List<String>>,
val crossStraitsDefinitions: List<CrossStraitsDefinition>,
val moedictDefinitions: List<MoedictDefinition>,
) )

View File

@ -0,0 +1,15 @@
package com.marvinelsen.willow.domain
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class MoedictDefinition(
@SerialName("def") val definition: String,
@SerialName("example") val examples: List<String> = emptyList(),
@SerialName("quote") val quotes: List<String> = emptyList(),
val type: String? = null,
@SerialName("link") val links: List<String> = emptyList(),
val synonyms: String? = null,
val antonyms: String? = null,
)

View File

@ -1,5 +1,5 @@
package com.marvinelsen.willow.domain package com.marvinelsen.willow.domain
enum class SearchMode { enum class SearchMode {
PINYIN, SIMPLIFIED, TRADITIONAL, ENGLISH PINYIN, SIMPLIFIED, TRADITIONAL, SEGMENTS
} }

View File

@ -0,0 +1,6 @@
package com.marvinelsen.willow.domain
data class Sentence(
val traditional: String,
val simplified: String,
)

View File

@ -1,17 +1,34 @@
package com.marvinelsen.willow.domain package com.marvinelsen.willow.domain
import com.github.houbb.segment.bs.SegmentBs
import com.github.houbb.segment.data.phrase.core.data.SegmentPhraseDatas
import com.github.houbb.segment.data.pos.core.data.SegmentPosDatas
import com.github.houbb.segment.support.format.impl.SegmentFormats
import com.github.houbb.segment.support.segment.impl.Segments
import com.github.houbb.segment.support.segment.mode.impl.SegmentModes
import com.github.houbb.segment.support.segment.result.impl.SegmentResultHandlers
import com.github.houbb.segment.support.tagging.pos.tag.impl.SegmentPosTaggings
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import java.sql.Connection import java.sql.Connection
import java.sql.PreparedStatement import java.sql.PreparedStatement
import java.sql.ResultSet import java.sql.ResultSet
class SqliteDictionary(private val connection: Connection) : Dictionary { class SqliteDictionary(private val connection: Connection) : Dictionary {
private val whitespaceRegex = """\s+""".toRegex()
private val segmentBs = SegmentBs.newInstance()
.segment(Segments.defaults())
.segmentData(SegmentPhraseDatas.define())
.segmentMode(SegmentModes.dict())
.segmentFormat(SegmentFormats.chineseSimple())
.posTagging(SegmentPosTaggings.simple())
.posData(SegmentPosDatas.define())
private val searchSimplifiedPreparedStatement: PreparedStatement by lazy { private val searchSimplifiedPreparedStatement: PreparedStatement by lazy {
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM cedict FROM entry
WHERE simplified GLOB ? WHERE simplified GLOB ?
ORDER BY character_count ASC ORDER BY character_count ASC
""".trimIndent() """.trimIndent()
@ -21,8 +38,39 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val searchTraditionalPreparedStatement: PreparedStatement by lazy { private val searchTraditionalPreparedStatement: PreparedStatement by lazy {
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM cedict FROM entry
WHERE traditional GLOB ?
ORDER BY character_count ASC
""".trimIndent()
)
}
private val searchPinyinPreparedStatement: PreparedStatement by lazy {
connection.prepareStatement(
"""
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry
WHERE searchable_pinyin GLOB ?
OR searchable_pinyin_with_tone_numbers GLOB ?
ORDER BY character_count ASC
""".trimIndent()
)
}
private val searchSegments = """
WITH cte(id, segment) AS (VALUES ?)
SELECT entry.traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry INNER JOIN cte
ON cte.segment = entry.traditional OR cte.segment = entry.simplified
ORDER BY cte.id
""".trimIndent()
private val findWordsBeginning: PreparedStatement by lazy {
connection.prepareStatement(
"""
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry
WHERE traditional GLOB ? WHERE traditional GLOB ?
ORDER BY character_count ASC ORDER BY character_count ASC
""".trimIndent() """.trimIndent()
@ -32,8 +80,28 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val findWordsContaining: PreparedStatement by lazy { private val findWordsContaining: PreparedStatement by lazy {
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM cedict FROM entry
WHERE traditional LIKE ?
ORDER BY character_count ASC
""".trimIndent()
)
}
private val findCharacters = """
WITH cte(id, character, syllable) AS (VALUES ?)
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry INNER JOIN cte
ON cte.character = entry.traditional
WHERE cte.syllable = entry.pinyin_with_tone_numbers
ORDER BY cte.id
""".trimIndent()
private val findSentences: PreparedStatement by lazy {
connection.prepareStatement(
"""
SELECT traditional, simplified
FROM sentence
WHERE traditional LIKE ? WHERE traditional LIKE ?
ORDER BY character_count ASC ORDER BY character_count ASC
""".trimIndent() """.trimIndent()
@ -41,26 +109,10 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
} }
override fun search(query: String, searchMode: SearchMode) = when (searchMode) { override fun search(query: String, searchMode: SearchMode) = when (searchMode) {
SearchMode.PINYIN -> TODO()
SearchMode.SIMPLIFIED -> searchSimplified(query) SearchMode.SIMPLIFIED -> searchSimplified(query)
SearchMode.TRADITIONAL -> searchTraditional(query) SearchMode.TRADITIONAL -> searchTraditional(query)
SearchMode.ENGLISH -> TODO() SearchMode.PINYIN -> searchPinyin(query)
} SearchMode.SEGMENTS -> searchSegments(query)
override fun findWordsContaining(entry: DictionaryEntry): List<DictionaryEntry> {
findWordsContaining.setString(1, "_%${entry.traditional}%")
val resultSet: ResultSet = findWordsContaining.executeQuery()
return resultSet.toListOfDictionaryEntries()
}
override fun findSentencesContaining(entry: DictionaryEntry): List<DictionaryEntry> {
return emptyList()
}
override fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> {
return emptyList()
} }
private fun searchSimplified(query: String): List<DictionaryEntry> { private fun searchSimplified(query: String): List<DictionaryEntry> {
@ -78,6 +130,80 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
return resultSet.toListOfDictionaryEntries() return resultSet.toListOfDictionaryEntries()
} }
private fun searchPinyin(query: String): List<DictionaryEntry> {
val sanitizedQuery = query.lowercase().replace(whitespaceRegex, "")
searchPinyinPreparedStatement.setString(1, "$sanitizedQuery*")
searchPinyinPreparedStatement.setString(2, "$sanitizedQuery*")
val resultSet: ResultSet = searchPinyinPreparedStatement.executeQuery()
return resultSet.toListOfDictionaryEntries()
}
private fun searchSegments(phrase: String): List<DictionaryEntry> {
val segments = segmentBs.segment(phrase, SegmentResultHandlers.word())
val segmentsListString = segments
.mapIndexed { index, s -> "($index, '$s')" }
.joinToString(",")
val query = searchSegments.replace("?", segmentsListString)
val resultSet: ResultSet = connection.createStatement().executeQuery(query)
return resultSet.toListOfDictionaryEntries()
}
override fun findWordsContaining(entry: DictionaryEntry): List<DictionaryEntry> {
findWordsContaining.setString(1, "_%${entry.traditional}%")
val resultSet: ResultSet = findWordsContaining.executeQuery()
return resultSet.toListOfDictionaryEntries()
}
override fun findWordsBeginning(entry: DictionaryEntry): List<DictionaryEntry> {
findWordsBeginning.setString(1, "${entry.traditional}?*")
val resultSet: ResultSet = findWordsBeginning.executeQuery()
return resultSet.toListOfDictionaryEntries()
}
override fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> {
val pinyinSyllablesWithToneNumbers = entry.pinyinWithToneNumbers
.lowercase()
.split(" ")
.filter { it.isNotBlank() }
val characters = entry.traditional
.split("")
.filter { it.isNotBlank() }
.filter { it != "" }
.filter { it != "·" }
val charactersWithSyllables = characters.zip(pinyinSyllablesWithToneNumbers)
val queryInput = charactersWithSyllables
.mapIndexed { index, s -> "($index, '${s.first}', '${s.second}')" }
.joinToString(",")
val query = findCharacters.replace("?", queryInput)
val resultSet: ResultSet = connection.createStatement().executeQuery(query)
return resultSet.toListOfDictionaryEntries()
}
override fun findSentencesContaining(entry: DictionaryEntry): List<Sentence> {
findSentences.setString(1, "_%${entry.traditional}%")
val resultSet: ResultSet = findSentences.executeQuery()
return resultSet.toListOfSentences()
}
} }
@Suppress("MagicNumber") @Suppress("MagicNumber")
@ -87,7 +213,9 @@ private fun ResultSet.toDictionaryEntry() = DictionaryEntry(
pinyinWithToneMarks = this.getString(3), pinyinWithToneMarks = this.getString(3),
pinyinWithToneNumbers = this.getString(4), pinyinWithToneNumbers = this.getString(4),
zhuyin = this.getString(5), zhuyin = this.getString(5),
definitions = Json.decodeFromString(this.getString(6)) cedictDefinitions = Json.decodeFromString(this.getString(6)),
crossStraitsDefinitions = Json.decodeFromString(this.getString(7)),
moedictDefinitions = Json.decodeFromString(this.getString(8)),
) )
private fun ResultSet.toListOfDictionaryEntries() = buildList { private fun ResultSet.toListOfDictionaryEntries() = buildList {
@ -97,3 +225,16 @@ private fun ResultSet.toListOfDictionaryEntries() = buildList {
} }
} }
} }
private fun ResultSet.toSentence() = Sentence(
traditional = this.getString(1),
simplified = this.getString(2),
)
private fun ResultSet.toListOfSentences() = buildList {
this@toListOfSentences.use {
while (it.next()) {
add(it.toSentence())
}
}
}

View File

@ -1,3 +0,0 @@
package com.marvinelsen.willow.ui
class Configuration

View File

@ -1,6 +1,8 @@
package com.marvinelsen.willow.ui package com.marvinelsen.willow.ui
import com.marvinelsen.willow.domain.CrossStraitsDefinition
import com.marvinelsen.willow.domain.DictionaryEntry import com.marvinelsen.willow.domain.DictionaryEntry
import com.marvinelsen.willow.domain.MoedictDefinition
import javafx.beans.property.SimpleStringProperty import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty import javafx.beans.property.StringProperty
import javafx.collections.FXCollections import javafx.collections.FXCollections
@ -12,7 +14,9 @@ data class DictionaryEntryFx(
val pinyinWithToneMarksProperty: StringProperty, val pinyinWithToneMarksProperty: StringProperty,
val pinyinWithToneNumbersProperty: StringProperty, val pinyinWithToneNumbersProperty: StringProperty,
val zhuyinProperty: StringProperty, val zhuyinProperty: StringProperty,
val definitions: ObservableList<List<String>>, val cedictDefinitions: ObservableList<List<String>>,
val crossStraitsDefinitions: ObservableList<CrossStraitsDefinition>,
val moedictDefinitions: ObservableList<MoedictDefinition>,
) )
fun DictionaryEntry.toFx() = DictionaryEntryFx( fun DictionaryEntry.toFx() = DictionaryEntryFx(
@ -21,7 +25,9 @@ fun DictionaryEntry.toFx() = DictionaryEntryFx(
pinyinWithToneMarksProperty = SimpleStringProperty(this.pinyinWithToneMarks), pinyinWithToneMarksProperty = SimpleStringProperty(this.pinyinWithToneMarks),
pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers), pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers),
zhuyinProperty = SimpleStringProperty(this.zhuyin), zhuyinProperty = SimpleStringProperty(this.zhuyin),
definitions = FXCollections.observableList(this.definitions) cedictDefinitions = FXCollections.observableList(this.cedictDefinitions),
crossStraitsDefinitions = FXCollections.observableList(this.crossStraitsDefinitions),
moedictDefinitions = FXCollections.observableList(this.moedictDefinitions),
) )
fun DictionaryEntryFx.toDomain() = DictionaryEntry( fun DictionaryEntryFx.toDomain() = DictionaryEntry(
@ -30,5 +36,7 @@ fun DictionaryEntryFx.toDomain() = DictionaryEntry(
pinyinWithToneMarks = this.pinyinWithToneMarksProperty.value, pinyinWithToneMarks = this.pinyinWithToneMarksProperty.value,
pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value, pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value,
zhuyin = this.zhuyinProperty.value, zhuyin = this.zhuyinProperty.value,
definitions = this.definitions.toList() cedictDefinitions = this.cedictDefinitions.toList(),
crossStraitsDefinitions = this.crossStraitsDefinitions.toList(),
moedictDefinitions = this.moedictDefinitions.toList(),
) )

View File

@ -0,0 +1,20 @@
package com.marvinelsen.willow.ui
import com.marvinelsen.willow.domain.Sentence
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty
data class SentenceFx(
val traditionalProperty: StringProperty,
val simplifiedProperty: StringProperty,
)
fun Sentence.toFx() = SentenceFx(
traditionalProperty = SimpleStringProperty(this.traditional),
simplifiedProperty = SimpleStringProperty(this.simplified),
)
fun SentenceFx.toDomain() = Sentence(
traditional = this.traditionalProperty.value,
simplified = this.simplifiedProperty.value,
)

View File

@ -0,0 +1,136 @@
package com.marvinelsen.willow.ui.cells
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.config.Pronunciation
import com.marvinelsen.willow.config.Script
import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
import javafx.beans.binding.Bindings
import javafx.geometry.VPos
import javafx.scene.control.Label
import javafx.scene.control.ListCell
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(private val resources: ResourceBundle, private val config: Config) :
Callback<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
override fun call(listView: ListView<DictionaryEntryFx?>): ListCell<DictionaryEntryFx?> {
val entryCell = EntryCell(resources, config)
entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
return entryCell
}
companion object {
private const val CELL_PADDING = 24
}
}
private class EntryCell(private val resources: ResourceBundle, private val config: Config) :
ListCell<DictionaryEntryFx?>() {
private val labelHeadword = Label().apply {
styleClass.add("headword")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.headwordFontSize.asString(),
"px;"
)
)
}
private val labelDefinition = Label().apply {
styleClass.add("definition")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.definitionFontSize.asString(),
"px;"
)
)
visibleProperty().bind(config.searchResults.shouldShowDefinition)
managedProperty().bind(config.searchResults.shouldShowDefinition)
}
private val labelPronunciation = Label().apply {
styleClass.add("pronunciation")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.pronunciationFontSize.asString(),
"px;"
)
)
visibleProperty().bind(config.searchResults.shouldShowPronunciation)
managedProperty().bind(config.searchResults.shouldShowPronunciation)
}
private val flowPane = FlowPane(labelHeadword, labelPronunciation).apply {
hgap = FLOW_PANE_HGAP
rowValignment = VPos.BASELINE
}
private val root = VBox(flowPane, labelDefinition).apply {
styleClass.add("search-result")
}
init {
text = null
}
override fun updateItem(entry: DictionaryEntryFx?, empty: Boolean) {
super.updateItem(entry, empty)
if (empty || entry == null) {
graphic = null
contextMenu = null
} else {
labelHeadword.textProperty().bind(
Bindings.createStringBinding(
{
when (config.script.value!!) {
Script.SIMPLIFIED -> entry.simplifiedProperty.value
Script.TRADITIONAL -> entry.traditionalProperty.value
}
},
config.script
)
)
labelPronunciation.textProperty().bind(
Bindings.createStringBinding(
{
when (config.searchResults.pronunciation.value!!) {
Pronunciation.PINYIN_WITH_TONE_MARKS -> entry.pinyinWithToneMarksProperty.value
Pronunciation.PINYIN_WITH_TONE_NUMBERS -> entry.pinyinWithToneNumbersProperty.value
Pronunciation.ZHUYIN -> entry.zhuyinProperty.value
}
},
config.searchResults.pronunciation
)
)
val definition = when {
entry.cedictDefinitions.isNotEmpty() -> entry.cedictDefinitions.joinToString(
separator = " / "
) { it.joinToString(separator = "; ") }
entry.crossStraitsDefinitions.isNotEmpty() -> entry.crossStraitsDefinitions.joinToString(
separator = " / "
) { it.definition }
entry.moedictDefinitions.isNotEmpty() -> entry.moedictDefinitions.joinToString(
separator = " / "
) { it.definition }
else -> error("No definition for entry")
}
labelDefinition.text = definition
contextMenu = createContextMenuForEntry(entry, resources)
graphic = root
}
}
companion object {
private const val FLOW_PANE_HGAP = 8.0
}
}

View File

@ -1,70 +0,0 @@
package com.marvinelsen.willow.ui.cells
import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
import javafx.geometry.VPos
import javafx.scene.control.Label
import javafx.scene.control.ListCell
import javafx.scene.control.ListView
import javafx.scene.layout.FlowPane
import javafx.scene.layout.VBox
import javafx.util.Callback
class DictionaryEntryCellFactory : Callback<ListView<DictionaryEntryFx?>, ListCell<DictionaryEntryFx?>> {
override fun call(listView: ListView<DictionaryEntryFx?>): ListCell<DictionaryEntryFx?> {
val entryCell = EntryCell()
entryCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
return entryCell
}
companion object {
private const val CELL_PADDING = 16
}
}
internal class EntryCell : ListCell<DictionaryEntryFx?>() {
private val labelHeadword = Label().apply {
styleClass.add("list-view-entry")
}
private val labelDefinition = Label().apply {
styleClass.add("list-view-definition")
}
private val labelPronunciation = Label().apply {
styleClass.add("list-view-pronunciation")
}
private val flowPane = FlowPane(labelHeadword, labelPronunciation).apply {
hgap = FLOW_PANE_HGAP
rowValignment = VPos.BASELINE
}
private val root = VBox(flowPane, labelDefinition)
init {
text = null
if (item != null) {
contextMenu = createContextMenuForEntry(item!!)
}
}
override fun updateItem(entry: DictionaryEntryFx?, empty: Boolean) {
super.updateItem(entry, empty)
if (empty || entry == null) {
graphic = null
} else {
labelHeadword.text = entry.traditionalProperty.value
labelPronunciation.text = entry.pinyinWithToneMarksProperty.value
val definition = entry.definitions.joinToString(separator = " / ") { it.joinToString(separator = "; ") }
labelDefinition.text = definition
graphic = root
}
}
companion object {
private const val FLOW_PANE_HGAP = 8.0
}
}

View File

@ -0,0 +1,57 @@
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(private val config: Config) : Callback<ListView<SentenceFx?>, ListCell<SentenceFx?>> {
override fun call(listView: ListView<SentenceFx?>): ListCell<SentenceFx?> {
val sentenceCell = SentenceCell(config)
sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
return sentenceCell
}
companion object {
private const val CELL_PADDING = 16
}
}
private class SentenceCell(private val config: Config) : ListCell<SentenceFx?>() {
private val labelSentence = Label().apply {
styleClass.add("sentence")
isWrapText = true
}
private val root = VBox(labelSentence)
init {
text = null
}
override fun updateItem(sentence: SentenceFx?, empty: Boolean) {
super.updateItem(sentence, empty)
if (empty || sentence == null) {
graphic = null
} else {
labelSentence.textProperty().bind(
Bindings.createStringBinding(
{
when (config.script.value!!) {
Script.SIMPLIFIED -> sentence.simplifiedProperty.value
Script.TRADITIONAL -> sentence.traditionalProperty.value
}
},
config.script
)
)
graphic = root
}
}
}

View File

@ -1,84 +1,396 @@
package com.marvinelsen.willow.ui.controllers package com.marvinelsen.willow.ui.controllers
import com.marvinelsen.willow.Model import com.marvinelsen.willow.Model
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.config.Pronunciation
import com.marvinelsen.willow.config.Script
import com.marvinelsen.willow.ui.DictionaryEntryFx import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.SentenceFx
import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory
import com.marvinelsen.willow.ui.cells.SentenceCellFactory
import com.marvinelsen.willow.ui.util.createContextMenuForEntry
import javafx.beans.binding.Bindings import javafx.beans.binding.Bindings
import javafx.fxml.FXML import javafx.fxml.FXML
import javafx.scene.control.Label import javafx.scene.control.Label
import javafx.scene.control.ListView import javafx.scene.control.ListView
import javafx.scene.control.ProgressIndicator
import javafx.scene.control.Tab
import javafx.scene.control.TabPane import javafx.scene.control.TabPane
import javafx.scene.input.ContextMenuEvent
import javafx.scene.layout.FlowPane
import javafx.scene.web.WebView import javafx.scene.web.WebView
import kotlinx.html.DIV
import kotlinx.html.body
import kotlinx.html.div
import kotlinx.html.h1
import kotlinx.html.html
import kotlinx.html.li
import kotlinx.html.ol
import kotlinx.html.span
import kotlinx.html.stream.createHTML
import java.util.ResourceBundle
class DetailsController(private val model: Model) { @Suppress("UnusedPrivateMember", "TooManyFunctions")
class DetailsController(private val model: Model, private val config: Config) {
@FXML @FXML
private lateinit var tabPaneDetails: TabPane private lateinit var resources: ResourceBundle
@FXML @FXML
private lateinit var webViewDefinition: WebView private lateinit var flowPaneHeader: FlowPane
@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 @FXML
private lateinit var labelHeadword: Label private lateinit var labelHeadword: Label
@FXML @FXML
@Suppress("UnusedPrivateMember") private lateinit var labelPronunciation: Label
@FXML
private lateinit var tabPaneDetails: TabPane
@FXML
private lateinit var tabCharacters: Tab
@FXML
private lateinit var webViewDefinition: WebView
@FXML
private lateinit var listViewWordsContaining: ListView<DictionaryEntryFx>
@FXML
private lateinit var listViewWordsBeginning: ListView<DictionaryEntryFx>
@FXML
private lateinit var listViewCharacters: ListView<DictionaryEntryFx>
@FXML
private lateinit var progressIndicatorCharacters: ProgressIndicator
@FXML
private lateinit var progressIndicatorWordsContaining: ProgressIndicator
@FXML
private lateinit var progressIndicatorWordsBeginning: ProgressIndicator
@FXML
private lateinit var labelNoCharactersFound: Label
@FXML
private lateinit var labelNoWordsContainingFound: Label
@FXML
private lateinit var labelNoWordsBeginningFound: Label
@FXML
private lateinit var listViewSentences: ListView<SentenceFx>
@FXML
private lateinit var progressIndicatorSentences: ProgressIndicator
@FXML
private lateinit var labelNoSentencesFound: Label
@FXML
private fun initialize() { private fun initialize() {
val headwordObjectBinding = initializeLabelHeadword()
Bindings.createStringBinding({ model.selectedEntry.value?.traditionalProperty?.value }, model.selectedEntry) initializeLabelPronunciation()
initializeTabPaneDetails()
initializeListViewWordsContaining()
initializeListViewWordsBeginning()
initializeListViewCharacters()
initializeListViewSentences()
initializeWebViewDefinition()
}
labelHeadword.textProperty().bind(headwordObjectBinding) private fun initializeLabelHeadword() {
labelHeadword.apply {
tabPaneDetails.disableProperty().bind(Bindings.isNull(model.selectedEntry)) textProperty().bind(
Bindings.createStringBinding(
listViewWords.items = model.wordsContaining {
tabPaneDetails.selectionModel.selectedItemProperty().addListener { _, _, selectedTab -> val selectedEntry = model.selectedEntry.value
if (model.selectedEntry.value == null) return@addListener when (config.script.value!!) {
Script.SIMPLIFIED -> selectedEntry?.simplifiedProperty?.value
when (selectedTab.id) { Script.TRADITIONAL -> selectedEntry?.traditionalProperty?.value
"tabWords" -> { }
model.findWords() },
} config.script,
model.selectedEntry
else -> {} )
} )
} styleProperty().bind(
Bindings.concat(
webViewDefinition.apply { "-fx-font-size: ",
isContextMenuEnabled = false config.details.headwordFontSize.asString(),
engine.userStyleSheetLocation = "px;"
this::class.java.getResource("/css/definitions.css")!!.toExternalForm() )
}
model.selectedEntry.addListener { _, _, newValue ->
if (newValue == null) {
return@addListener
}
webViewDefinition.engine.loadContent(
buildString {
append("<html>")
append("<body>")
append("<h1>CC-CEDICT</h1>")
append("<ol>")
for (definition in newValue.definitions) {
append("<li>")
append(definition.joinToString(separator = "; "))
append("</li>")
}
append("</ol>")
append("</body>")
append("</html>")
}
) )
} }
} }
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
lazyUpdateTabContent(tabPaneDetails.selectionModel.selectedItem.id)
}
tabCharacters.disableProperty().bind(
Bindings.createBooleanBinding(
{
(model.selectedEntry.value?.traditionalProperty?.value?.length ?: 0) < 2
},
model.selectedEntry
)
)
}
private fun initializeListViewSentences() {
listViewSentences.apply {
cellFactory = SentenceCellFactory(config)
items = model.sentences
disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences)))
}
progressIndicatorSentences.visibleProperty().bind(model.isFindingSentences)
labelNoSentencesFound
.visibleProperty()
.bind(Bindings.and(Bindings.isEmpty(model.sentences), Bindings.not(model.isFindingSentences)))
}
private fun initializeListViewWordsContaining() {
listViewWordsContaining.apply {
cellFactory = DictionaryEntryCellFactory(resources, config)
items = model.wordsContaining
disableProperty().bind(Bindings.or(model.isFindingWordsContaining, Bindings.isEmpty(model.wordsContaining)))
}
progressIndicatorWordsContaining.visibleProperty().bind(model.isFindingWordsContaining)
labelNoWordsContainingFound
.visibleProperty()
.bind(Bindings.and(Bindings.isEmpty(model.wordsContaining), Bindings.not(model.isFindingWordsContaining)))
}
private fun initializeListViewWordsBeginning() {
listViewWordsBeginning.apply {
cellFactory = DictionaryEntryCellFactory(resources, config)
items = model.wordsBeginning
disableProperty().bind(Bindings.or(model.isFindingWordsBeginning, Bindings.isEmpty(model.wordsBeginning)))
}
progressIndicatorWordsBeginning.visibleProperty().bind(model.isFindingWordsBeginning)
labelNoWordsBeginningFound
.visibleProperty()
.bind(Bindings.and(Bindings.isEmpty(model.wordsBeginning), Bindings.not(model.isFindingWordsBeginning)))
}
private fun initializeListViewCharacters() {
listViewCharacters.apply {
cellFactory = DictionaryEntryCellFactory(resources, config)
items = model.characters
disableProperty().bind(Bindings.or(model.isFindingCharacters, Bindings.isEmpty(model.characters)))
}
progressIndicatorCharacters.visibleProperty().bind(model.isFindingCharacters)
labelNoCharactersFound
.visibleProperty()
.bind(Bindings.and(Bindings.isEmpty(model.characters), Bindings.not(model.isFindingCharacters)))
}
private fun initializeWebViewDefinition() {
webViewDefinition.apply {
engine.userStyleSheetLocation = this::class.java.getResource("/css/definitions.css")!!.toExternalForm()
}
model.selectedEntry.addListener { _, _, newEntry ->
if (newEntry == null) return@addListener
webViewDefinition.engine.loadContent(createDefinitionHtml(newEntry))
}
}
@FXML
private fun headerOnContextMenuRequested(contextMenuEvent: ContextMenuEvent) {
if (model.selectedEntry.value == null) return
createContextMenuForEntry(model.selectedEntry.value, resources).show(
flowPaneHeader.scene.window,
contextMenuEvent.screenX,
contextMenuEvent.screenY
)
}
@Suppress("ReturnCount")
private fun lazyUpdateTabContent(selectedTabId: String?) {
when (selectedTabId) {
"tabWords" -> {
if (model.wordsContaining.isEmpty()) {
model.findWordsContaining()
}
if (model.wordsBeginning.isEmpty()) {
model.findWordsBeginning()
}
}
"tabCharacters" -> {
if (model.characters.isNotEmpty()) return
model.findCharacters()
}
"tabSentences" -> {
if (model.sentences.isNotEmpty()) return
model.findSentences()
}
else -> {}
}
}
private fun createDefinitionHtml(entry: DictionaryEntryFx) = createHTML().html {
body {
if (entry.cedictDefinitions.isNotEmpty()) {
div(classes = "cedict-definition") {
h1 {
+"CC-CEDICT"
}
cedictDefinition(entry)
}
}
if (entry.crossStraitsDefinitions.isNotEmpty()) {
div(classes = "cross-straits-definition") {
h1 {
+"Cross-Straits"
}
crossStraitsDefinition(entry)
}
}
if (entry.moedictDefinitions.isNotEmpty()) {
div(classes = "moe-definition") {
h1 {
+"MOE"
}
moeDefinition(entry)
}
}
}
}
} }
private fun DIV.cedictDefinition(entry: DictionaryEntryFx) = ol {
for (definition in entry.cedictDefinitions) {
li {
+definition.joinToString(separator = "; ")
}
}
}
private fun DIV.crossStraitsDefinition(entry: DictionaryEntryFx) = ol {
entry.crossStraitsDefinitions.forEach { definition ->
li {
span(classes = "definition") {
+definition.definition
}
if (definition.examples.isNotEmpty()) {
span(classes = "example") {
+definition.examples.joinToString(
prefix = "如:",
separator = "",
postfix = ""
) { "$it" }
}
}
}
}
}
private fun DIV.moeDefinition(entry: DictionaryEntryFx) =
entry.moedictDefinitions.groupBy { it.type ?: "" }.entries.forEach { (type, definitions) ->
if (type != "") {
span(classes = "type") {
+type
}
}
ol {
definitions.forEach { definition ->
li {
span(classes = "definition") {
+definition.definition
}
definition.examples.forEach { example ->
span(classes = "example") {
+example
}
}
definition.quotes.forEach { quote ->
span(classes = "quote") {
+quote
}
}
definition.synonyms?.let {
span(classes = "synonyms") {
+"似:${it.replace(",", "、")}"
}
}
definition.antonyms?.let {
span(classes = "antonyms") {
+"反:${it.replace(",", "、")}"
}
}
}
}
}
}

View File

@ -1,39 +1,12 @@
package com.marvinelsen.willow.ui.controllers package com.marvinelsen.willow.ui.controllers
import com.marvinelsen.willow.Model import com.marvinelsen.willow.Model
import com.marvinelsen.willow.ui.DictionaryEntryFx
import javafx.beans.binding.Bindings
import javafx.fxml.FXML import javafx.fxml.FXML
import javafx.scene.control.Label
import javafx.scene.control.ListView
import javafx.scene.control.ProgressIndicator
@Suppress("UnusedPrivateProperty", "UnusedPrivateMember")
class MainController(private val model: Model) { class MainController(private val model: Model) {
@FXML @FXML
private lateinit var progressIndicatorEntries: ProgressIndicator
@FXML
@Suppress("UnusedPrivateProperty")
private lateinit var labelNoEntriesFound: Label
@FXML
private lateinit var listViewSearchResults: ListView<DictionaryEntryFx>
@FXML
@Suppress("UnusedPrivateMember")
private fun initialize() { private fun initialize() {
listViewSearchResults.items = model.searchResults // no-op
listViewSearchResults
.disableProperty()
.bind(Bindings.or(model.isSearching, Bindings.isEmpty(model.searchResults)))
progressIndicatorEntries.visibleProperty().bind(model.isSearching)
listViewSearchResults.selectionModel.selectedItemProperty().addListener { _, _, newValue: DictionaryEntryFx? ->
if (newValue == null) {
return@addListener
}
model.selectEntry(newValue)
}
} }
} }

View File

@ -1,13 +1,23 @@
package com.marvinelsen.willow.ui.controllers package com.marvinelsen.willow.ui.controllers
import com.marvinelsen.willow.Model import com.marvinelsen.willow.Model
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.ui.dialogs.PreferencesDialog
import javafx.application.Platform import javafx.application.Platform
import javafx.beans.binding.Bindings import javafx.beans.binding.Bindings
import javafx.fxml.FXML import javafx.fxml.FXML
import javafx.scene.control.MenuBar
import javafx.scene.control.MenuItem import javafx.scene.control.MenuItem
import java.util.ResourceBundle
@Suppress("UnusedPrivateMember") @Suppress("UnusedPrivateMember")
class MenuController(private val model: Model) { class MenuController(private val model: Model, private val config: Config) {
@FXML
private lateinit var resources: ResourceBundle
@FXML
private lateinit var menuBar: MenuBar
@FXML @FXML
private lateinit var menuItemCopyHeadword: MenuItem private lateinit var menuItemCopyHeadword: MenuItem
@ -20,6 +30,16 @@ class MenuController(private val model: Model) {
menuItemCopyHeadword.disableProperty().bind(Bindings.isNull(model.selectedEntry)) menuItemCopyHeadword.disableProperty().bind(Bindings.isNull(model.selectedEntry))
} }
@FXML
private fun onMenuItemPreferencesAction() {
PreferencesDialog(menuBar.scene.window, config, resources).showAndWait().ifPresent { result ->
when (result) {
PreferencesDialog.Result.SAVE_CHANGES -> config.save()
PreferencesDialog.Result.DO_NOT_SAVE_CHANGES -> config.load()
}
}
}
@FXML @FXML
private fun onMenuItemQuitAction() { private fun onMenuItemQuitAction() {
Platform.exit() Platform.exit()

View File

@ -24,5 +24,14 @@ class SearchController(private val model: Model) {
val searchMode = searchModeToggleGroup.selectedToggle.userData as SearchMode val searchMode = searchModeToggleGroup.selectedToggle.userData as SearchMode
model.search(newValue, searchMode) model.search(newValue, searchMode)
} }
searchModeToggleGroup.selectedToggleProperty().addListener { _, _, newValue ->
if (textFieldSearch.text.isNullOrBlank()) {
return@addListener
}
val searchMode = newValue.userData as SearchMode
model.search(textFieldSearch.text, searchMode)
}
} }
} }

View File

@ -0,0 +1,49 @@
package com.marvinelsen.willow.ui.controllers
import com.marvinelsen.willow.Model
import com.marvinelsen.willow.config.Config
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 SearchResultsController(private val model: Model, private val config: Config) {
@FXML
private lateinit var resources: ResourceBundle
@FXML
private lateinit var progressIndicatorEntries: ProgressIndicator
@FXML
@Suppress("UnusedPrivateProperty")
private lateinit var labelNoEntriesFound: Label
@FXML
private lateinit var listViewSearchResults: ListView<DictionaryEntryFx>
@FXML
@Suppress("UnusedPrivateMember")
private fun initialize() {
listViewSearchResults.cellFactory = DictionaryEntryCellFactory(resources, config)
listViewSearchResults.items = model.searchResults
listViewSearchResults
.disableProperty()
.bind(Bindings.or(model.isSearching, Bindings.isEmpty(model.searchResults)))
progressIndicatorEntries.visibleProperty().bind(model.isSearching)
labelNoEntriesFound
.visibleProperty()
.bind(Bindings.and(Bindings.isEmpty(model.searchResults), Bindings.not(model.isSearching)))
listViewSearchResults.selectionModel.selectedItemProperty().addListener { _, _, newValue: DictionaryEntryFx? ->
if (newValue == null) {
return@addListener
}
model.selectEntry(newValue)
}
}
}

View File

@ -0,0 +1,108 @@
package com.marvinelsen.willow.ui.controllers.dialogs
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.config.Pronunciation
import com.marvinelsen.willow.config.Script
import com.marvinelsen.willow.config.Theme
import com.marvinelsen.willow.ui.formatters.FontSizeTextFormatter
import javafx.fxml.FXML
import javafx.scene.control.CheckBox
import javafx.scene.control.ComboBox
import javafx.scene.control.Spinner
import java.util.Locale
@Suppress("UnusedPrivateMember")
class PreferencesDialogController(private val config: Config) {
@FXML
private lateinit var comboBoxLocale: ComboBox<Locale>
@FXML
private lateinit var comboBoxTheme: ComboBox<Theme>
@FXML
private lateinit var comboBoxScript: ComboBox<Script>
@FXML
private lateinit var comboBoxPronunciationSearchResults: ComboBox<Pronunciation>
@FXML
private lateinit var comboBoxPronunciationDetails: ComboBox<Pronunciation>
@FXML
private lateinit var checkBoxShowPronunciationSearchResults: CheckBox
@FXML
private lateinit var checkBoxShowDefinitionSearchResults: CheckBox
@FXML
private lateinit var spinnerHeadwordFontSizeDetails: Spinner<Int>
@FXML
private lateinit var spinnerPronunciationFontSizeDetails: Spinner<Int>
@FXML
private lateinit var spinnerHeadwordFontSizeSearchResults: Spinner<Int>
@FXML
private lateinit var spinnerPronunciationFontSizeSearchResults: Spinner<Int>
@FXML
private lateinit var spinnerDefinitionFontSizeSearchResults: Spinner<Int>
private val entryHeadwordFontSizeObjectProperty = config.details.headwordFontSize.asObject()
private val entryPronunciationFontSizeObjectProperty = config.details.pronunciationFontSize.asObject()
private val searchResultHeadwordFontSizeObjectProperty = config.searchResults.headwordFontSize.asObject()
private val searchResultPronunciationFontSizeObjectProperty = config.searchResults.pronunciationFontSize.asObject()
private val searchResultDefinitionFontSizeObjectProperty = config.searchResults.definitionFontSize.asObject()
@FXML
private fun initialize() {
comboBoxLocale.items.addAll(
setOf(
Locale.ENGLISH,
Locale.GERMAN,
Locale.CHINA,
Locale.TAIWAN
)
)
comboBoxTheme.valueProperty().bindBidirectional(config.theme)
comboBoxScript.valueProperty().bindBidirectional(config.script)
comboBoxLocale.valueProperty().bindBidirectional(config.locale)
comboBoxPronunciationSearchResults.valueProperty().bindBidirectional(config.searchResults.pronunciation)
comboBoxPronunciationDetails.valueProperty().bindBidirectional(config.details.pronunciation)
checkBoxShowDefinitionSearchResults
.selectedProperty()
.bindBidirectional(config.searchResults.shouldShowDefinition)
checkBoxShowPronunciationSearchResults
.selectedProperty()
.bindBidirectional(config.searchResults.shouldShowPronunciation)
with(spinnerHeadwordFontSizeDetails) {
editor.textFormatter = FontSizeTextFormatter()
valueFactory.valueProperty().bindBidirectional(entryHeadwordFontSizeObjectProperty)
}
with(spinnerPronunciationFontSizeDetails) {
editor.textFormatter = FontSizeTextFormatter()
valueFactory.valueProperty().bindBidirectional(entryPronunciationFontSizeObjectProperty)
}
with(spinnerHeadwordFontSizeSearchResults) {
editor.textFormatter = FontSizeTextFormatter()
valueFactory.valueProperty().bindBidirectional(searchResultHeadwordFontSizeObjectProperty)
}
with(spinnerPronunciationFontSizeSearchResults) {
editor.textFormatter = FontSizeTextFormatter()
valueFactory.valueProperty().bindBidirectional(searchResultPronunciationFontSizeObjectProperty)
}
with(spinnerDefinitionFontSizeSearchResults) {
editor.textFormatter = FontSizeTextFormatter()
valueFactory.valueProperty().bindBidirectional(searchResultDefinitionFontSizeObjectProperty)
}
}
}

View File

@ -0,0 +1,9 @@
package com.marvinelsen.willow.ui.converters
import javafx.util.StringConverter
import java.util.Locale
class LocaleStringConverter : StringConverter<Locale>() {
override fun toString(locale: Locale): String = locale.displayName
override fun fromString(string: String) = null
}

View File

@ -0,0 +1,14 @@
package com.marvinelsen.willow.ui.converters
import com.marvinelsen.willow.config.Pronunciation
import javafx.util.StringConverter
class PronunciationStringConverter : StringConverter<Pronunciation>() {
override fun toString(pronunciation: Pronunciation) = when (pronunciation) {
Pronunciation.PINYIN_WITH_TONE_MARKS -> "Pinyin with tone marks"
Pronunciation.PINYIN_WITH_TONE_NUMBERS -> "Pinyin with tone numbers"
Pronunciation.ZHUYIN -> "Zhuyin"
}
override fun fromString(string: String) = null
}

View File

@ -0,0 +1,13 @@
package com.marvinelsen.willow.ui.converters
import com.marvinelsen.willow.config.Script
import javafx.util.StringConverter
class ScriptStringConverter : StringConverter<Script>() {
override fun toString(script: Script): String = when (script) {
Script.SIMPLIFIED -> "Simplified"
Script.TRADITIONAL -> "Traditional"
}
override fun fromString(string: String) = null
}

View File

@ -0,0 +1,14 @@
package com.marvinelsen.willow.ui.converters
import com.marvinelsen.willow.config.Theme
import javafx.util.StringConverter
class ThemeStringConverter : StringConverter<Theme>() {
override fun toString(theme: Theme): String = when (theme) {
Theme.SYSTEM -> "System"
Theme.LIGHT -> "Light"
Theme.DARK -> "Dark"
}
override fun fromString(string: String) = null
}

View File

@ -0,0 +1,63 @@
package com.marvinelsen.willow.ui.dialogs
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.ui.controllers.dialogs.PreferencesDialogController
import javafx.fxml.FXMLLoader
import javafx.scene.control.ButtonType
import javafx.scene.control.Dialog
import javafx.scene.control.DialogPane
import javafx.stage.Modality
import javafx.stage.Stage
import javafx.stage.Window
import javafx.util.Callback
import java.util.ResourceBundle
class PreferencesDialog(
owner: Window?,
config: Config,
resources: ResourceBundle,
) : Dialog<PreferencesDialog.Result>() {
companion object {
private const val MIN_HEIGHT = 400.0
private const val MIN_WIDTH = 400.0
}
enum class Result {
SAVE_CHANGES, DO_NOT_SAVE_CHANGES
}
init {
val fxmlLoader = FXMLLoader()
fxmlLoader.resources = resources
fxmlLoader.controllerFactory = Callback { type ->
when (type) {
PreferencesDialogController::class.java -> PreferencesDialogController(config)
else -> error("Trying to instantiate unknown controller type $type")
}
}
val root = fxmlLoader.load(javaClass.getResourceAsStream("/fxml/dialogs/preferences.fxml")) as DialogPane
root.prefHeightProperty().bind(dialogPane.scene.heightProperty())
root.prefWidthProperty().bind(dialogPane.scene.widthProperty())
dialogPane = root
title = "Settings"
isResizable = true
initOwner(owner)
initModality(Modality.APPLICATION_MODAL)
(dialogPane.scene.window as Stage).apply {
minWidth = MIN_WIDTH
minHeight = MIN_HEIGHT
}
resultConverter = Callback(::convertToResult)
}
private fun convertToResult(buttonType: ButtonType) =
when (buttonType) {
ButtonType.APPLY -> Result.SAVE_CHANGES
else -> Result.DO_NOT_SAVE_CHANGES
}
}

View File

@ -0,0 +1,13 @@
package com.marvinelsen.willow.ui.formatters
import javafx.scene.control.TextFormatter
import javafx.util.converter.IntegerStringConverter
import java.util.function.UnaryOperator
private val digitRegex = """\d*""".toRegex()
class FontSizeTextFormatter : TextFormatter<Int>(
IntegerStringConverter(),
1,
UnaryOperator { if (digitRegex.matches(it.text)) it else null }
)

View File

@ -0,0 +1,20 @@
package com.marvinelsen.willow.ui.services
import com.marvinelsen.willow.domain.Dictionary
import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.toDomain
import com.marvinelsen.willow.ui.toFx
import com.marvinelsen.willow.ui.util.task
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.concurrent.Service
class FindCharacterService(private val dictionary: Dictionary) : Service<ObservableList<DictionaryEntryFx>>() {
lateinit var entry: DictionaryEntryFx
override fun createTask() = task {
if (!this::entry.isInitialized) error("Entry is not initialized")
FXCollections.observableList(dictionary.findCharacters(entry.toDomain()).map { it.toFx() })
}
}

View File

@ -0,0 +1,21 @@
package com.marvinelsen.willow.ui.services
import com.marvinelsen.willow.domain.Dictionary
import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.SentenceFx
import com.marvinelsen.willow.ui.toDomain
import com.marvinelsen.willow.ui.toFx
import com.marvinelsen.willow.ui.util.task
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.concurrent.Service
class FindSentencesService(private val dictionary: Dictionary) : Service<ObservableList<SentenceFx>>() {
lateinit var entry: DictionaryEntryFx
override fun createTask() = task {
if (!this::entry.isInitialized) error("Entry is not initialized")
FXCollections.observableList(dictionary.findSentencesContaining(entry.toDomain()).map { it.toFx() })
}
}

View File

@ -0,0 +1,20 @@
package com.marvinelsen.willow.ui.services
import com.marvinelsen.willow.domain.Dictionary
import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.toDomain
import com.marvinelsen.willow.ui.toFx
import com.marvinelsen.willow.ui.util.task
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.concurrent.Service
class FindWordsBeginningService(private val dictionary: Dictionary) : Service<ObservableList<DictionaryEntryFx>>() {
lateinit var entry: DictionaryEntryFx
override fun createTask() = task {
if (!this::entry.isInitialized) error("Entry is not initialized")
FXCollections.observableList(dictionary.findWordsBeginning(entry.toDomain()).map { it.toFx() })
}
}

View File

@ -0,0 +1,20 @@
package com.marvinelsen.willow.ui.services
import com.marvinelsen.willow.domain.Dictionary
import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.toDomain
import com.marvinelsen.willow.ui.toFx
import com.marvinelsen.willow.ui.util.task
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.concurrent.Service
class FindWordsContainingService(private val dictionary: Dictionary) : Service<ObservableList<DictionaryEntryFx>>() {
lateinit var entry: DictionaryEntryFx
override fun createTask() = task {
if (!this::entry.isInitialized) error("Entry is not initialized")
FXCollections.observableList(dictionary.findWordsContaining(entry.toDomain()).map { it.toFx() })
}
}

View File

@ -1,10 +1,10 @@
package com.marvinelsen.willow.ui.util package com.marvinelsen.willow.ui.services
import com.marvinelsen.willow.domain.Dictionary import com.marvinelsen.willow.domain.Dictionary
import com.marvinelsen.willow.domain.SearchMode import com.marvinelsen.willow.domain.SearchMode
import com.marvinelsen.willow.ui.DictionaryEntryFx import com.marvinelsen.willow.ui.DictionaryEntryFx
import com.marvinelsen.willow.ui.toDomain
import com.marvinelsen.willow.ui.toFx import com.marvinelsen.willow.ui.toFx
import com.marvinelsen.willow.ui.util.task
import javafx.collections.FXCollections import javafx.collections.FXCollections
import javafx.collections.ObservableList import javafx.collections.ObservableList
import javafx.concurrent.Service import javafx.concurrent.Service
@ -20,13 +20,3 @@ class SearchService(private val dictionary: Dictionary) : Service<ObservableList
FXCollections.observableList(dictionary.search(searchQuery, searchMode).map { it.toFx() }) FXCollections.observableList(dictionary.search(searchQuery, searchMode).map { it.toFx() })
} }
} }
class FindWordsService(private val dictionary: Dictionary) : Service<ObservableList<DictionaryEntryFx>>() {
lateinit var entry: DictionaryEntryFx
override fun createTask() = task {
if (!this::entry.isInitialized) error("Entry is not initialized")
FXCollections.observableList(dictionary.findWordsContaining(entry.toDomain()).map { it.toFx() })
}
}

View File

@ -1,21 +1,14 @@
package com.marvinelsen.willow.ui.util package com.marvinelsen.willow.ui.util
import com.marvinelsen.willow.ui.DictionaryEntryFx
import javafx.scene.input.Clipboard import javafx.scene.input.Clipboard
import javafx.scene.input.ClipboardContent import javafx.scene.input.ClipboardContent
object ClipboardHelper { object ClipboardHelper {
private val systemClipboard = Clipboard.getSystemClipboard() private val systemClipboard = Clipboard.getSystemClipboard()
fun copyHeadword(entry: DictionaryEntryFx) { fun copyString(string: String) {
val clipboardContent = ClipboardContent() val clipboardContent = ClipboardContent()
clipboardContent.putString(entry.traditionalProperty.value) clipboardContent.putString(string)
systemClipboard.setContent(clipboardContent)
}
fun copyPronunciation(entry: DictionaryEntryFx) {
val clipboardContent = ClipboardContent()
clipboardContent.putString(entry.pinyinWithToneMarksProperty.value)
systemClipboard.setContent(clipboardContent) systemClipboard.setContent(clipboardContent)
} }
} }

View File

@ -4,15 +4,18 @@ import com.marvinelsen.willow.ui.DictionaryEntryFx
import javafx.event.EventHandler import javafx.event.EventHandler
import javafx.scene.control.ContextMenu import javafx.scene.control.ContextMenu
import javafx.scene.control.MenuItem 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("Copy Headword").apply { val menuItemCopyHeadword =
onAction = EventHandler { ClipboardHelper.copyHeadword(entry) } MenuItem(resourceBundle.getString("menubar.edit.copy.headword")).apply {
} onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) }
}
val menuItemCopyPronunciation = MenuItem("Copy Pronunciation").apply { val menuItemCopyPronunciation =
onAction = EventHandler { ClipboardHelper.copyPronunciation(entry) } MenuItem(resourceBundle.getString("menubar.edit.copy.pronunciation")).apply {
} onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarksProperty.value) }
}
items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation) items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation)
} }

View File

@ -0,0 +1,38 @@
/*
JavaFX CSS Reference Guide
https://openjfx.io/javadoc/23/javafx.graphics/javafx/scene/doc-files/cssref.html
*/
.root {
willow-background: #282828;
willow-foreground: #dfdfdf;
-fx-base: willow-background;
-fx-accent: #5c7654;
-fx-focus-color: #3e8f25;
-fx-background-color: willow-background;
-fx-text-fill: willow-foreground;
}
/*.split-pane {
-fx-background-color: willow-background;
}*/
.label {
-fx-text-fill: willow-foreground;
}
.radio-button {
-fx-text-fill: willow-foreground;
}
.list-cell:even {
-fx-text-fill: willow-foreground;
-fx-background: #1e1e1e;
}
.list-cell:odd {
-fx-text-fill: willow-foreground;
-fx-background: #292929;
}

View File

@ -1,6 +1,6 @@
html { html {
font-family: "Noto Sans TC"; font-family: "Noto Sans TC";
font-size: 16px; font-size: 14px;
line-height: 1.7em; line-height: 1.7em;
border: 1px solid #B5B5B5; border: 1px solid #B5B5B5;
@ -15,6 +15,11 @@ h1 {
font-size: 1.25em; font-size: 1.25em;
} }
ol {
padding-left: 0;
list-style-position: inside;
}
ol li:only-child { ol li:only-child {
list-style: none; list-style: none;
} }

View File

@ -1,4 +1,16 @@
.headword { .headword {
-fx-font-family: TW-Kai; -fx-font-family: TW-Kai;
-fx-font-size: 40; }
.pronunciation {
-fx-font-family: "Noto Sans TC";
}
.list-view .headword {
-fx-font-family: "Noto Sans TC";
}
.list-view .sentence {
-fx-font-family: "Noto Sans TC";
-fx-font-size: 14px;
} }

View File

@ -1,42 +1,3 @@
.root { .root {
-fx-font-family: "Inter Variable"; -fx-font-family: "Inter Variable";
} }
.chinese {
-fx-font-family: "Noto Sans CJK TC";
}
.list-view {
-fx-selection-bar: #B8EEFF;
-fx-font-family: "Noto Sans CJK TC";
/*-fx-selection-bar-non-focused: green;*/
}
.list-view-entry {
-fx-font-size: 20;
-fx-font-weight: bold;
}
.list-view-definition {
-fx-font-size: 14;
}
.list-view-pronunciation {
-fx-font-size: 14;
}
.list-view-sentence-cell {
-fx-font-size: 16;
}
.moe-definition {
-fx-font-size: 16;
}
.pronunciation {
-fx-font: 16 "Noto Sans CJK TC";
}
.settings-dialog .content {
-fx-padding: 0;
}

View File

@ -0,0 +1,3 @@
.preferences-dialog .content {
-fx-padding: 0;
}

View File

@ -0,0 +1,17 @@
.list-view:focused .list-cell:filled:focused:selected .search-result {
/*-fx-text-fill: red;*/
}
.headword {
-fx-font-family: "Noto Sans TC";
/*-fx-font-weight: bold;*/
/*-fx-text-fill: inherit;*/
}
.pronunciation {
/*-fx-text-fill: inherit;*/
}
.definition {
/*-fx-text-fill: inherit;*/
}

View File

@ -1,428 +0,0 @@
Attribution-ShareAlike 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution-ShareAlike 4.0 International Public
License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution-ShareAlike 4.0 International Public License ("Public
License"). To the extent this Public License may be interpreted as a
contract, You are granted the Licensed Rights in consideration of Your
acceptance of these terms and conditions, and the Licensor grants You
such rights in consideration of benefits the Licensor receives from
making the Licensed Material available under these terms and
conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.
c. BY-SA Compatible License means a license listed at
creativecommons.org/compatiblelicenses, approved by Creative
Commons as essentially the equivalent of this Public License.
d. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
e. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
f. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
g. License Elements means the license attributes listed in the name
of a Creative Commons Public License. The License Elements of this
Public License are Attribution and ShareAlike.
h. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
i. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
j. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
k. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
l. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
m. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part; and
b. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. Additional offer from the Licensor -- Adapted Material.
Every recipient of Adapted Material from You
automatically receives an offer from the Licensor to
exercise the Licensed Rights in the Adapted Material
under the conditions of the Adapter's License You apply.
c. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified
form), You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
b. ShareAlike.
In addition to the conditions in Section 3(a), if You Share
Adapted Material You produce, the following conditions also apply.
1. The Adapter's License You apply must be a Creative Commons
license with the same License Elements, this version or
later, or a BY-SA Compatible License.
2. You must include the text of, or the URI or hyperlink to, the
Adapter's License You apply. You may satisfy this condition
in any reasonable manner based on the medium, means, and
context in which You Share Adapted Material.
3. You may not offer or impose any additional or different terms
or conditions on, or apply any Effective Technological
Measures to, Adapted Material that restrict exercise of the
rights granted under the Adapter's License You apply.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material,
including for purposes of Section 3(b); and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

Binary file not shown.

Binary file not shown.

View File

@ -1,30 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.*?>
<?import javafx.scene.web.WebView?> <?import javafx.scene.web.WebView?>
<?import javafx.geometry.Insets?> <VBox stylesheets="/css/details.css" xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
<VBox xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.marvinelsen.willow.ui.controllers.DetailsController">
fx:controller="com.marvinelsen.willow.ui.controllers.DetailsController" <FlowPane fx:id="flowPaneHeader" hgap="8.0" vgap="8.0" rowValignment="BASELINE" VBox.vgrow="NEVER"
stylesheets="/css/details.css"> onContextMenuRequested="#headerOnContextMenuRequested">
<Label fx:id="labelHeadword" styleClass="headword" text="Label">
<padding> <padding>
<Insets left="8" right="8" top="8" bottom="8"/> <Insets bottom="6.0" left="6.0" right="6.0" top="6.0"/>
</padding> </padding>
</Label> <Label fx:id="labelHeadword" styleClass="headword"/>
<TabPane fx:id="tabPaneDetails" tabClosingPolicy="UNAVAILABLE" disable="true" VBox.vgrow="ALWAYS"> <Label fx:id="labelPronunciation" styleClass="pronunciation"/>
<Tab closable="false" disable="false" text="%tab.definition"> </FlowPane>
<WebView fx:id="webViewDefinition" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" <TabPane fx:id="tabPaneDetails" tabClosingPolicy="UNAVAILABLE" VBox.vgrow="ALWAYS">
prefWidth="-1.0"/> <Tab closable="false" text="%details.tab.definition">
<WebView fx:id="webViewDefinition"/>
</Tab> </Tab>
<Tab id="tabSentences" closable="false" disable="false" text="%tab.sentences"> <Tab id="tabSentences" closable="false" text="%details.tab.sentences">
<ListView fx:id="listviewSentences"/> <StackPane>
<ProgressIndicator fx:id="progressIndicatorSentences" visible="false"/>
<Label fx:id="labelNoSentencesFound" text="%details.list.no_sentences_found" textAlignment="CENTER"
visible="false" wrapText="true">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
</Label>
<ListView fx:id="listViewSentences"/>
</StackPane>
</Tab> </Tab>
<Tab id="tabWords" closable="false" disable="false" text="%tab.words"> <Tab id="tabWords" closable="false" text="%details.tab.words">
<ListView fx:id="listViewWords"/> <VBox maxHeight="1.7976931348623157E308">
<TitledPane animated="false" maxHeight="-Infinity" text="%details.list.words_beginning" VBox.vgrow="ALWAYS">
<StackPane>
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="0.0"/>
</padding>
<ProgressIndicator fx:id="progressIndicatorWordsBeginning" visible="false"/>
<Label fx:id="labelNoWordsBeginningFound" text="%details.list.no_words_found" textAlignment="CENTER"
visible="false" wrapText="true">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
</Label>
<ListView fx:id="listViewWordsBeginning" prefHeight="4000"/>
</StackPane>
</TitledPane>
<TitledPane animated="false" maxHeight="-Infinity" text="%details.list.words_containing" VBox.vgrow="ALWAYS">
<StackPane>
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="0.0"/>
</padding>
<ProgressIndicator fx:id="progressIndicatorWordsContaining" visible="false"/>
<Label fx:id="labelNoWordsContainingFound" text="%details.list.no_words_found" textAlignment="CENTER"
visible="false" wrapText="true">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
</Label>
<ListView fx:id="listViewWordsContaining" prefHeight="4000"/>
</StackPane>
</TitledPane>
</VBox>
</Tab> </Tab>
<Tab closable="false" disable="false" text="%tab.characters"> <Tab fx:id="tabCharacters" id="tabCharacters" closable="false" text="%details.tab.characters">
<ListView fx:id="listViewCharacters"/> <StackPane>
<ListView fx:id="listViewCharacters"/>
<Label fx:id="labelNoCharactersFound" text="%details.list.no_characters_found" textAlignment="CENTER"
visible="false" wrapText="true">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
</Label>
<ProgressIndicator fx:id="progressIndicatorCharacters" visible="false"/>
</StackPane>
</Tab> </Tab>
</TabPane> </TabPane>
</VBox> </VBox>

View File

@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.marvinelsen.willow.config.*?>
<?import com.marvinelsen.willow.ui.converters.*?>
<?import javafx.collections.FXCollections?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<DialogPane styleClass="preferences-dialog" xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
stylesheets="/css/preferences.css"
fx:controller="com.marvinelsen.willow.ui.controllers.dialogs.PreferencesDialogController">
<fx:define>
<FXCollections fx:factory="observableArrayList" fx:id="phoneticAlphabets">
<Pronunciation fx:value="PINYIN_WITH_TONE_MARKS"/>
<Pronunciation fx:value="PINYIN_WITH_TONE_NUMBERS"/>
<Pronunciation fx:value="ZHUYIN"/>
</FXCollections>
<FXCollections fx:factory="observableArrayList" fx:id="themes">
<Theme fx:value="SYSTEM"/>
<Theme fx:value="LIGHT"/>
<Theme fx:value="DARK"/>
</FXCollections>
<FXCollections fx:factory="observableArrayList" fx:id="scripts">
<Script fx:value="SIMPLIFIED"/>
<Script fx:value="TRADITIONAL"/>
</FXCollections>
</fx:define>
<content>
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
tabClosingPolicy="UNAVAILABLE">
<Tab closable="false" text="General">
<GridPane alignment="TOP_CENTER" hgap="8.0" vgap="8.0">
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="ALWAYS"/>
<ColumnConstraints halignment="LEFT" hgrow="ALWAYS"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="BASELINE" vgrow="NEVER"/>
</rowConstraints>
<padding>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0"/>
</padding>
<Label text="Script:" GridPane.rowIndex="3"/>
<ComboBox fx:id="comboBoxScript" items="$scripts" GridPane.columnIndex="1" GridPane.rowIndex="3">
<value>
<Script fx:value="SIMPLIFIED"/>
</value>
<converter>
<ScriptStringConverter/>
</converter>
</ComboBox>
<Separator prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="2"/>
<Label text="Language:" GridPane.rowIndex="0"/>
<ComboBox fx:id="comboBoxLocale" GridPane.rowIndex="0" GridPane.columnIndex="1">
<converter>
<LocaleStringConverter/>
</converter>
</ComboBox>
<Label text="Theme:" GridPane.rowIndex="1"/>
<ComboBox fx:id="comboBoxTheme" items="$themes" GridPane.rowIndex="1" GridPane.columnIndex="1">
<value>
<Theme fx:value="SYSTEM"/>
</value>
<converter>
<ThemeStringConverter/>
</converter>
</ComboBox>
</GridPane>
</Tab>
<Tab closable="false" text="Details View">
<GridPane alignment="TOP_CENTER" hgap="8.0" vgap="8.0">
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="ALWAYS"/>
<ColumnConstraints halignment="LEFT" hgrow="ALWAYS"/>
</columnConstraints>
<rowConstraints>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
</rowConstraints>
<padding>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0"/>
</padding>
<Label text="Pronunciation:"/>
<ComboBox fx:id="comboBoxPronunciationDetails" items="$phoneticAlphabets" GridPane.columnIndex="1">
<value>
<Pronunciation fx:value="PINYIN_WITH_TONE_MARKS"/>
</value>
<converter>
<PronunciationStringConverter/>
</converter>
</ComboBox>
<Label text="Headword font size:" GridPane.rowIndex="2"/>
<Label text="Pronunciation font size:" GridPane.rowIndex="3"/>
<Spinner fx:id="spinnerPronunciationFontSizeDetails" editable="true" GridPane.columnIndex="1"
GridPane.rowIndex="3">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory amountToStepBy="1" max="300" min="1"/>
</valueFactory>
</Spinner>
<Spinner fx:id="spinnerHeadwordFontSizeDetails" editable="true" GridPane.columnIndex="1"
GridPane.rowIndex="2">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory amountToStepBy="1" max="300" min="1"/>
</valueFactory>
</Spinner>
<Separator prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="1"/>
</GridPane>
</Tab>
<Tab closable="false" text="Search Results">
<GridPane alignment="TOP_CENTER" hgap="8.0" vgap="8.0">
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="ALWAYS"/>
<ColumnConstraints halignment="LEFT" hgrow="ALWAYS"/>
</columnConstraints>
<rowConstraints>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
<RowConstraints valignment="BASELINE" vgrow="NEVER"/>
</rowConstraints>
<padding>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0"/>
</padding>
<Label text="Pronunciation:"/>
<ComboBox fx:id="comboBoxPronunciationSearchResults" items="$phoneticAlphabets"
GridPane.columnIndex="1">
<value>
<Pronunciation fx:value="PINYIN_WITH_TONE_MARKS"/>
</value>
<converter>
<PronunciationStringConverter/>
</converter>
</ComboBox>
<Label text="Headword font size:" GridPane.rowIndex="5"/>
<Label text="Pronunciation font size:" GridPane.rowIndex="6"/>
<Spinner fx:id="spinnerPronunciationFontSizeSearchResults" editable="true" GridPane.columnIndex="1"
GridPane.rowIndex="6">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory amountToStepBy="1" max="300" min="1"/>
</valueFactory>
</Spinner>
<Spinner fx:id="spinnerHeadwordFontSizeSearchResults" editable="true" GridPane.columnIndex="1"
GridPane.rowIndex="5">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory amountToStepBy="1" max="300" min="1"/>
</valueFactory>
</Spinner>
<Spinner fx:id="spinnerDefinitionFontSizeSearchResults" editable="true" GridPane.columnIndex="1"
GridPane.rowIndex="7">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory amountToStepBy="1" max="300" min="1"/>
</valueFactory>
</Spinner>
<Separator prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="4"/>
<Label text="Definition font size:" GridPane.rowIndex="7"/>
<Label text="Display:" GridPane.rowIndex="2"/>
<CheckBox fx:id="checkBoxShowPronunciationSearchResults" mnemonicParsing="false" selected="true"
text="Show pronunciation" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<CheckBox fx:id="checkBoxShowDefinitionSearchResults" mnemonicParsing="false" selected="true"
text="Show definition" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Separator prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="1"/>
</GridPane>
</Tab>
</TabPane>
</content>
<ButtonType fx:constant="APPLY"/>
<ButtonType fx:constant="CANCEL"/>
</DialogPane>

View File

@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.control.SplitPane?> <?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<BorderPane xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" <BorderPane xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.marvinelsen.willow.ui.controllers.MainController" fx:controller="com.marvinelsen.willow.ui.controllers.MainController"
stylesheets="/css/main.css"> stylesheets="/css/main.css">
<top> <top>
@ -20,22 +16,9 @@
</BorderPane.margin> </BorderPane.margin>
<fx:include source="/fxml/search.fxml"/> <fx:include source="/fxml/search.fxml"/>
<SplitPane dividerPositions="0.33" VBox.vgrow="ALWAYS"> <SplitPane dividerPositions="0.33" VBox.vgrow="ALWAYS">
<StackPane> <fx:include source="/fxml/search-results.fxml"/>
<ListView fx:id="listViewSearchResults" disable="true">
<cellFactory>
<DictionaryEntryCellFactory/>
</cellFactory>
</ListView>
<Label fx:id="labelNoEntriesFound" text="%list.no_entries_found" textAlignment="CENTER"
visible="false" wrapText="true">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
</Label>
<ProgressIndicator fx:id="progressIndicatorEntries" visible="false"/>
</StackPane>
<fx:include source="/fxml/details.fxml"/> <fx:include source="/fxml/details.fxml"/>
</SplitPane> </SplitPane>
</VBox> </VBox>
</center> </center>
</BorderPane> </BorderPane>

View File

@ -3,11 +3,12 @@
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.input.KeyCodeCombination?> <?import javafx.scene.input.KeyCodeCombination?>
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.BorderPane?>
<MenuBar xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" <MenuBar xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
fx:id="menuBar"
fx:controller="com.marvinelsen.willow.ui.controllers.MenuController" BorderPane.alignment="CENTER" fx:controller="com.marvinelsen.willow.ui.controllers.MenuController" BorderPane.alignment="CENTER"
useSystemMenuBar="true"> useSystemMenuBar="true">
<Menu text="%menubar.file"> <Menu text="%menubar.file">
<MenuItem text="%menubar.file.settings"> <MenuItem text="%menubar.file.preferences" onAction="#onMenuItemPreferencesAction">
<accelerator> <accelerator>
<KeyCodeCombination alt="UP" code="COMMA" control="UP" meta="UP" shift="UP" <KeyCodeCombination alt="UP" code="COMMA" control="UP" meta="UP" shift="UP"
shortcut="DOWN"/> shortcut="DOWN"/>
@ -23,7 +24,7 @@
<Menu text="%menubar.edit"> <Menu text="%menubar.edit">
<MenuItem fx:id="menuItemCopyHeadword" text="%menubar.edit.copy.headword" onAction="#onMenuItemCopyHeadwordAction"> <MenuItem fx:id="menuItemCopyHeadword" text="%menubar.edit.copy.headword" onAction="#onMenuItemCopyHeadwordAction">
<accelerator> <accelerator>
<KeyCodeCombination alt="UP" code="C" control="UP" meta="UP" shift="UP" <KeyCodeCombination alt="UP" code="H" control="UP" meta="UP" shift="UP"
shortcut="DOWN"/> shortcut="DOWN"/>
</accelerator> </accelerator>
</MenuItem> </MenuItem>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.layout.StackPane?>
<StackPane minWidth="100" xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.marvinelsen.willow.ui.controllers.SearchResultsController"
stylesheets="/css/search-results.css">
<ListView fx:id="listViewSearchResults" disable="true"/>
<Label fx:id="labelNoEntriesFound" text="%search.results.list.no_entries_found" textAlignment="CENTER" visible="false"
wrapText="true">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
</Label>
<ProgressIndicator fx:id="progressIndicatorEntries" visible="false"/>
</StackPane>

View File

@ -5,7 +5,7 @@
<?import javafx.scene.layout.FlowPane?> <?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" <VBox xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.marvinelsen.willow.ui.controllers.SearchController" spacing="8"> fx:controller="com.marvinelsen.willow.ui.controllers.SearchController" spacing="8">
<TextField fx:id="textFieldSearch" promptText="%search.prompt" HBox.hgrow="ALWAYS"/> <TextField fx:id="textFieldSearch" promptText="%search.prompt" HBox.hgrow="ALWAYS"/>
<FlowPane hgap="8.0" vgap="8.0"> <FlowPane hgap="8.0" vgap="8.0">
@ -18,22 +18,19 @@
<SearchMode fx:value="SIMPLIFIED"/> <SearchMode fx:value="SIMPLIFIED"/>
</userData> </userData>
</RadioButton> </RadioButton>
<RadioButton mnemonicParsing="false" text="%search.mode.traditional" <RadioButton mnemonicParsing="false" text="%search.mode.traditional" toggleGroup="$searchModeToggleGroup">
toggleGroup="$searchModeToggleGroup">
<userData> <userData>
<SearchMode fx:value="TRADITIONAL"/> <SearchMode fx:value="TRADITIONAL"/>
</userData> </userData>
</RadioButton> </RadioButton>
<RadioButton mnemonicParsing="false" text="%search.mode.pinyin" <RadioButton mnemonicParsing="false" text="%search.mode.pinyin" toggleGroup="$searchModeToggleGroup">
toggleGroup="$searchModeToggleGroup">
<userData> <userData>
<SearchMode fx:value="PINYIN"/> <SearchMode fx:value="PINYIN"/>
</userData> </userData>
</RadioButton> </RadioButton>
<RadioButton mnemonicParsing="false" text="%search.mode.english" <RadioButton mnemonicParsing="false" text="%search.mode.phrase" toggleGroup="$searchModeToggleGroup">
toggleGroup="$searchModeToggleGroup">
<userData> <userData>
<SearchMode fx:value="ENGLISH"/> <SearchMode fx:value="SEGMENTS"/>
</userData> </userData>
</RadioButton> </RadioButton>
</FlowPane> </FlowPane>

View File

@ -1,19 +1,32 @@
# Search
search.prompt=Search dictionary… search.prompt=Search dictionary…
search.mode=Searching: search.mode=Search mode:
search.mode.pinyin=Pinyin search.mode.pinyin=Pinyin
search.mode.traditional=Traditional Chinese search.mode.traditional=Traditional
search.mode.simplified=Simplified Chinese search.mode.simplified=Simplified
search.mode.english=English search.mode.phrase=Phrase
tab.definition=Definition
tab.sentences=Sentences # Details
tab.words=Words details.tab.definition=Definition
tab.characters=Characters details.tab.sentences=Sentences
details.tab.words=Words
details.tab.characters=Characters
details.list.no_characters_found=No characters found
details.list.no_words_found=No words found
details.list.no_sentences_found=No sentences found.
details.list.words_beginning=Words beginning
details.list.words_containing=Words containing
# Menubar
menubar.file=_File menubar.file=_File
menubar.file.quit=_Quit menubar.file.quit=_Quit
menubar.file.settings=_Settings… menubar.file.preferences=_Preferences…
menubar.edit=_Edit menubar.edit=_Edit
menubar.edit.copy.headword=Copy Headword menubar.edit.copy.headword=Copy Headword
menubar.edit.copy.pronunciation=Copy Pronunciation menubar.edit.copy.pronunciation=Copy Pronunciation
menubar.help=_Help menubar.help=_Help
menubar.help.about=_About… menubar.help.about=_About…
list.no_entries_found=No matching entries found
# Search results
search.results.list.no_entries_found=No matching entries found

View File

@ -1,19 +1,32 @@
# Search
search.prompt=Durchsuche Wörterbuch… search.prompt=Durchsuche Wörterbuch…
search.mode=Suche: search.mode=Suchmodus:
search.mode.pinyin=Pinyin search.mode.pinyin=Pinyin
search.mode.traditional=Langzeichen search.mode.traditional=Langzeichen
search.mode.simplified=Kurzzeichen search.mode.simplified=Kurzzeichen
search.mode.english=Englisch search.mode.phrase=Satz
tab.definition=Definition
tab.sentences=Sätze # Details
tab.words=Wörter details.tab.definition=Definition
tab.characters=Schriftzeichen details.tab.sentences=Sätze
details.tab.words=Wörter
details.tab.characters=Schriftzeichen
details.list.no_characters_found=Keine Schriftzeichen gefunden
details.list.no_words_found=Keine Wörter gefunden
details.list.no_sentences_found=Keine Sätze gefunden
details.list.words_beginning=Am Wortanfang
details.list.words_containing=Im Wort
# Menubar
menubar.file=_Datei menubar.file=_Datei
menubar.file.quit=_Beenden menubar.file.quit=_Beenden
menubar.file.settings=_Einstellungen… menubar.file.preferences=_Einstellungen…
menubar.edit=_Bearbeiten menubar.edit=_Bearbeiten
menubar.edit.copy.headword=Kopiere Wort menubar.edit.copy.headword=Kopiere Wort
menubar.edit.copy.pronunciation=Kopiere Aussprache menubar.edit.copy.pronunciation=Kopiere Aussprache
menubar.help=_Hilfe menubar.help=_Hilfe
menubar.help.about=_Über… menubar.help.about=_Über…
list.no_entries_found=No matching entries found
# Search results
search.results.list.no_entries_found=Keine passenden Einträge gefunden

View File

@ -1,19 +1,32 @@
# Search
search.prompt=Search dictionary… search.prompt=Search dictionary…
search.mode=Searching: search.mode=Search mode:
search.mode.pinyin=Pinyin search.mode.pinyin=Pinyin
search.mode.traditional=Traditional Chinese search.mode.traditional=Traditional
search.mode.simplified=Simplified Chinese search.mode.simplified=Simplified
search.mode.english=English search.mode.phrase=Phrase
tab.definition=Definition
tab.sentences=Sentences # Details
tab.words=Words details.tab.definition=Definition
tab.characters=Characters details.tab.sentences=Sentences
details.tab.words=Words
details.tab.characters=Characters
details.list.no_characters_found=No characters found
details.list.no_words_found=No words found
details.list.no_sentences_found=No sentences found.
details.list.words_beginning=Words beginning
details.list.words_containing=Words containing
# Menubar
menubar.file=_File menubar.file=_File
menubar.file.quit=_Quit menubar.file.quit=_Quit
menubar.file.settings=_Settings… menubar.file.preferences=_Preferences…
menubar.edit=_Edit menubar.edit=_Edit
menubar.edit.copy.headword=Copy Headword menubar.edit.copy.headword=Copy Headword
menubar.edit.copy.pronunciation=Copy Pronunciation menubar.edit.copy.pronunciation=Copy Pronunciation
menubar.help=_Help menubar.help=_Help
menubar.help.about=_About… menubar.help.about=_About…
list.no_entries_found=No matching entries found
# Search results
search.results.list.no_entries_found=No matching entries found

View File

@ -1,19 +1,32 @@
#Search
search.prompt=搜尋… search.prompt=搜尋…
search.mode=搜尋: search.mode=搜尋模式:
search.mode.pinyin=漢語拼音 search.mode.pinyin=漢語拼音
search.mode.traditional=繁體字 search.mode.traditional=繁體字
search.mode.simplified=簡體字 search.mode.simplified=簡體字
search.mode.english=英文 search.mode.phrase=句子
tab.definition=Definition
tab.sentences=例句 # Details
tab.words= details.tab.definition=釋義
tab.characters= details.tab.sentences=例句
details.tab.words=
details.tab.characters=
details.list.no_characters_found=No characters found
details.list.no_words_found=No words found
details.list.no_sentences_found=No sentences found.
details.list.words_beginning=Words beginning
details.list.words_containing=Words containing
# Menubar
menubar.file=_檔案 menubar.file=_檔案
menubar.file.quit=_結束 Willow menubar.file.quit=_結束 Willow
menubar.file.settings=_設定… menubar.file.preferences=_設定…
menubar.edit=_編輯 menubar.edit=_編輯
menubar.edit.copy.headword=複製 Wort menubar.edit.copy.headword=複製 Wort
menubar.edit.copy.pronunciation=複製 Aussprache menubar.edit.copy.pronunciation=複製 Aussprache
menubar.help=_說明 menubar.help=_說明
menubar.help.about=_關於 Willow… menubar.help.about=_關於 Willow…
list.no_entries_found=No matching entries found
# Search results
search.results.list.no_entries_found=No matching entries found

View File

@ -1,19 +1,32 @@
# Search
search.prompt=搜尋… search.prompt=搜尋…
search.mode=搜尋: search.mode=搜尋模式:
search.mode.pinyin=漢語拼音 search.mode.pinyin=漢語拼音
search.mode.traditional=繁體字 search.mode.traditional=繁體字
search.mode.simplified=簡體字 search.mode.simplified=簡體字
search.mode.english=英文 search.mode.phrase=句子
tab.definition=Definition
tab.sentences=例句 # Details
tab.words= details.tab.definition=釋義
tab.characters= details.tab.sentences=例句
details.tab.words=
details.tab.characters=
details.list.no_characters_found=No characters found
details.list.no_words_found=No words found
details.list.no_sentences_found=No sentences found
details.list.words_beginning=Words beginning
details.list.words_containing=Words containing
# Menubar
menubar.file=_檔案 menubar.file=_檔案
menubar.file.quit=_結束 Willow menubar.file.quit=_結束 Willow
menubar.file.settings=_設定… menubar.file.preferences=_設定…
menubar.edit=_編輯 menubar.edit=_編輯
menubar.edit.copy.headword=複製 Wort menubar.edit.copy.headword=複製 Wort
menubar.edit.copy.pronunciation=複製 Aussprache menubar.edit.copy.pronunciation=複製 Aussprache
menubar.help=_說明 menubar.help=_說明
menubar.help.about=_關於 Willow… menubar.help.about=_關於 Willow…
list.no_entries_found=No matching entries found
# Search results
search.results.list.no_entries_found=No matching entries found

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff