Compare commits

..

No commits in common. "develop" and "main" have entirely different histories.

66 changed files with 916 additions and 238125 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,93 @@
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

@ -1,166 +0,0 @@
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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,15 +0,0 @@
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
enum class SearchMode {
PINYIN, SIMPLIFIED, TRADITIONAL, SEGMENTS
PINYIN, SIMPLIFIED, TRADITIONAL, ENGLISH
}

View File

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

View File

@ -1,34 +1,17 @@
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 java.sql.Connection
import java.sql.PreparedStatement
import java.sql.ResultSet
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 {
connection.prepareStatement(
"""
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, cedict_definitions, cross_straits_definitions, moe_definitions
FROM entry
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions
FROM cedict
WHERE simplified GLOB ?
ORDER BY character_count ASC
""".trimIndent()
@ -38,39 +21,8 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val searchTraditionalPreparedStatement: 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 ?
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
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions
FROM cedict
WHERE traditional GLOB ?
ORDER BY character_count ASC
""".trimIndent()
@ -80,28 +32,8 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
private val findWordsContaining: 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 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
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions
FROM cedict
WHERE traditional LIKE ?
ORDER BY character_count ASC
""".trimIndent()
@ -109,10 +41,26 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
}
override fun search(query: String, searchMode: SearchMode) = when (searchMode) {
SearchMode.PINYIN -> TODO()
SearchMode.SIMPLIFIED -> searchSimplified(query)
SearchMode.TRADITIONAL -> searchTraditional(query)
SearchMode.PINYIN -> searchPinyin(query)
SearchMode.SEGMENTS -> searchSegments(query)
SearchMode.ENGLISH -> TODO()
}
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> {
@ -130,80 +78,6 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
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")
@ -213,9 +87,7 @@ private fun ResultSet.toDictionaryEntry() = DictionaryEntry(
pinyinWithToneMarks = this.getString(3),
pinyinWithToneNumbers = this.getString(4),
zhuyin = this.getString(5),
cedictDefinitions = Json.decodeFromString(this.getString(6)),
crossStraitsDefinitions = Json.decodeFromString(this.getString(7)),
moedictDefinitions = Json.decodeFromString(this.getString(8)),
definitions = Json.decodeFromString(this.getString(6))
)
private fun ResultSet.toListOfDictionaryEntries() = buildList {
@ -225,16 +97,3 @@ 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

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

View File

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

View File

@ -1,20 +0,0 @@
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

@ -1,136 +0,0 @@
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

@ -0,0 +1,70 @@
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

@ -1,57 +0,0 @@
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,396 +1,84 @@
package com.marvinelsen.willow.ui.controllers
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.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.fxml.FXML
import javafx.scene.control.Label
import javafx.scene.control.ListView
import javafx.scene.control.ProgressIndicator
import javafx.scene.control.Tab
import javafx.scene.control.TabPane
import javafx.scene.input.ContextMenuEvent
import javafx.scene.layout.FlowPane
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
@Suppress("UnusedPrivateMember", "TooManyFunctions")
class DetailsController(private val model: Model, private val config: Config) {
@FXML
private lateinit var resources: ResourceBundle
@FXML
private lateinit var flowPaneHeader: FlowPane
@FXML
private lateinit var labelHeadword: Label
@FXML
private lateinit var labelPronunciation: Label
class DetailsController(private val model: Model) {
@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>
@Suppress("UnusedPrivateProperty")
private lateinit var listviewSentences: ListView<DictionaryEntryFx>
@FXML
private lateinit var listViewWordsBeginning: ListView<DictionaryEntryFx>
private lateinit var listViewWords: ListView<DictionaryEntryFx>
@FXML
@Suppress("UnusedPrivateProperty")
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
private lateinit var labelHeadword: Label
@FXML
@Suppress("UnusedPrivateMember")
private fun initialize() {
initializeLabelHeadword()
initializeLabelPronunciation()
initializeTabPaneDetails()
initializeListViewWordsContaining()
initializeListViewWordsBeginning()
initializeListViewCharacters()
initializeListViewSentences()
initializeWebViewDefinition()
}
val headwordObjectBinding =
Bindings.createStringBinding({ model.selectedEntry.value?.traditionalProperty?.value }, model.selectedEntry)
private fun initializeLabelHeadword() {
labelHeadword.apply {
textProperty().bind(
Bindings.createStringBinding(
{
val selectedEntry = model.selectedEntry.value
when (config.script.value!!) {
Script.SIMPLIFIED -> selectedEntry?.simplifiedProperty?.value
Script.TRADITIONAL -> selectedEntry?.traditionalProperty?.value
}
},
config.script,
model.selectedEntry
)
)
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.details.headwordFontSize.asString(),
"px;"
)
)
}
}
labelHeadword.textProperty().bind(headwordObjectBinding)
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
tabPaneDetails.disableProperty().bind(Bindings.isNull(model.selectedEntry))
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 ->
listViewWords.items = model.wordsContaining
tabPaneDetails.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) {
when (selectedTab.id) {
"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()
model.findWords()
}
else -> {}
}
}
private fun createDefinitionHtml(entry: DictionaryEntryFx) = createHTML().html {
body {
if (entry.cedictDefinitions.isNotEmpty()) {
div(classes = "cedict-definition") {
h1 {
+"CC-CEDICT"
}
cedictDefinition(entry)
}
webViewDefinition.apply {
isContextMenuEnabled = false
engine.userStyleSheetLocation =
this::class.java.getResource("/css/definitions.css")!!.toExternalForm()
}
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(",", "、")}"
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>")
}
)
}
}
}

View File

@ -1,12 +1,39 @@
package com.marvinelsen.willow.ui.controllers
import com.marvinelsen.willow.Model
import com.marvinelsen.willow.ui.DictionaryEntryFx
import javafx.beans.binding.Bindings
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) {
@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() {
// no-op
listViewSearchResults.items = model.searchResults
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,23 +1,13 @@
package com.marvinelsen.willow.ui.controllers
import com.marvinelsen.willow.Model
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.ui.dialogs.PreferencesDialog
import javafx.application.Platform
import javafx.beans.binding.Bindings
import javafx.fxml.FXML
import javafx.scene.control.MenuBar
import javafx.scene.control.MenuItem
import java.util.ResourceBundle
@Suppress("UnusedPrivateMember")
class MenuController(private val model: Model, private val config: Config) {
@FXML
private lateinit var resources: ResourceBundle
@FXML
private lateinit var menuBar: MenuBar
class MenuController(private val model: Model) {
@FXML
private lateinit var menuItemCopyHeadword: MenuItem
@ -30,16 +20,6 @@ class MenuController(private val model: Model, private val config: Config) {
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
private fun onMenuItemQuitAction() {
Platform.exit()

View File

@ -24,14 +24,5 @@ class SearchController(private val model: Model) {
val searchMode = searchModeToggleGroup.selectedToggle.userData as 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

@ -1,49 +0,0 @@
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

@ -1,108 +0,0 @@
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

@ -1,9 +0,0 @@
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

@ -1,14 +0,0 @@
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

@ -1,13 +0,0 @@
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

@ -1,14 +0,0 @@
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

@ -1,63 +0,0 @@
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

@ -1,13 +0,0 @@
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

@ -1,20 +0,0 @@
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

@ -1,21 +0,0 @@
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

@ -1,20 +0,0 @@
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

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

View File

@ -4,17 +4,14 @@ import com.marvinelsen.willow.ui.DictionaryEntryFx
import javafx.event.EventHandler
import javafx.scene.control.ContextMenu
import javafx.scene.control.MenuItem
import java.util.ResourceBundle
fun createContextMenuForEntry(entry: DictionaryEntryFx, resourceBundle: ResourceBundle) = ContextMenu().apply {
val menuItemCopyHeadword =
MenuItem(resourceBundle.getString("menubar.edit.copy.headword")).apply {
onAction = EventHandler { ClipboardHelper.copyString(entry.traditionalProperty.value) }
fun createContextMenuForEntry(entry: DictionaryEntryFx) = ContextMenu().apply {
val menuItemCopyHeadword = MenuItem("Copy Headword").apply {
onAction = EventHandler { ClipboardHelper.copyHeadword(entry) }
}
val menuItemCopyPronunciation =
MenuItem(resourceBundle.getString("menubar.edit.copy.pronunciation")).apply {
onAction = EventHandler { ClipboardHelper.copyString(entry.pinyinWithToneMarksProperty.value) }
val menuItemCopyPronunciation = MenuItem("Copy Pronunciation").apply {
onAction = EventHandler { ClipboardHelper.copyPronunciation(entry) }
}
items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation)

View File

@ -1,10 +1,10 @@
package com.marvinelsen.willow.ui.services
package com.marvinelsen.willow.ui.util
import com.marvinelsen.willow.domain.Dictionary
import com.marvinelsen.willow.domain.SearchMode
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
@ -20,3 +20,13 @@ class SearchService(private val dictionary: Dictionary) : Service<ObservableList
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,38 +0,0 @@
/*
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 {
font-family: "Noto Sans TC";
font-size: 14px;
font-size: 16px;
line-height: 1.7em;
border: 1px solid #B5B5B5;
@ -15,11 +15,6 @@ h1 {
font-size: 1.25em;
}
ol {
padding-left: 0;
list-style-position: inside;
}
ol li:only-child {
list-style: none;
}

View File

@ -1,16 +1,4 @@
.headword {
-fx-font-family: TW-Kai;
}
.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;
-fx-font-size: 40;
}

View File

@ -1,3 +1,42 @@
.root {
-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

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

View File

@ -1,17 +0,0 @@
.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

@ -0,0 +1,428 @@
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.

View File

@ -1,80 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.web.WebView?>
<VBox stylesheets="/css/details.css" xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.marvinelsen.willow.ui.controllers.DetailsController">
<FlowPane fx:id="flowPaneHeader" hgap="8.0" vgap="8.0" rowValignment="BASELINE" VBox.vgrow="NEVER"
onContextMenuRequested="#headerOnContextMenuRequested">
<?import javafx.geometry.Insets?>
<VBox xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.marvinelsen.willow.ui.controllers.DetailsController"
stylesheets="/css/details.css">
<Label fx:id="labelHeadword" styleClass="headword" text="Label">
<padding>
<Insets bottom="6.0" left="6.0" right="6.0" top="6.0"/>
</padding>
<Label fx:id="labelHeadword" styleClass="headword"/>
<Label fx:id="labelPronunciation" styleClass="pronunciation"/>
</FlowPane>
<TabPane fx:id="tabPaneDetails" tabClosingPolicy="UNAVAILABLE" VBox.vgrow="ALWAYS">
<Tab closable="false" text="%details.tab.definition">
<WebView fx:id="webViewDefinition"/>
</Tab>
<Tab id="tabSentences" closable="false" text="%details.tab.sentences">
<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"/>
<Insets left="8" right="8" top="8" bottom="8"/>
</padding>
</Label>
<ListView fx:id="listViewSentences"/>
</StackPane>
<TabPane fx:id="tabPaneDetails" tabClosingPolicy="UNAVAILABLE" disable="true" VBox.vgrow="ALWAYS">
<Tab closable="false" disable="false" text="%tab.definition">
<WebView fx:id="webViewDefinition" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0"
prefWidth="-1.0"/>
</Tab>
<Tab id="tabWords" closable="false" text="%details.tab.words">
<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 id="tabSentences" closable="false" disable="false" text="%tab.sentences">
<ListView fx:id="listviewSentences"/>
</Tab>
<Tab fx:id="tabCharacters" id="tabCharacters" closable="false" text="%details.tab.characters">
<StackPane>
<Tab id="tabWords" closable="false" disable="false" text="%tab.words">
<ListView fx:id="listViewWords"/>
</Tab>
<Tab closable="false" disable="false" text="%tab.characters">
<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>
</TabPane>
</VBox>

View File

@ -1,175 +0,0 @@
<?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,9 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.*?>
<BorderPane xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
<BorderPane xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.marvinelsen.willow.ui.controllers.MainController"
stylesheets="/css/main.css">
<top>
@ -16,7 +20,20 @@
</BorderPane.margin>
<fx:include source="/fxml/search.fxml"/>
<SplitPane dividerPositions="0.33" VBox.vgrow="ALWAYS">
<fx:include source="/fxml/search-results.fxml"/>
<StackPane>
<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"/>
</SplitPane>
</VBox>

View File

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

View File

@ -1,19 +0,0 @@
<?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.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox 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.SearchController" spacing="8">
<TextField fx:id="textFieldSearch" promptText="%search.prompt" HBox.hgrow="ALWAYS"/>
<FlowPane hgap="8.0" vgap="8.0">
@ -18,19 +18,22 @@
<SearchMode fx:value="SIMPLIFIED"/>
</userData>
</RadioButton>
<RadioButton mnemonicParsing="false" text="%search.mode.traditional" toggleGroup="$searchModeToggleGroup">
<RadioButton mnemonicParsing="false" text="%search.mode.traditional"
toggleGroup="$searchModeToggleGroup">
<userData>
<SearchMode fx:value="TRADITIONAL"/>
</userData>
</RadioButton>
<RadioButton mnemonicParsing="false" text="%search.mode.pinyin" toggleGroup="$searchModeToggleGroup">
<RadioButton mnemonicParsing="false" text="%search.mode.pinyin"
toggleGroup="$searchModeToggleGroup">
<userData>
<SearchMode fx:value="PINYIN"/>
</userData>
</RadioButton>
<RadioButton mnemonicParsing="false" text="%search.mode.phrase" toggleGroup="$searchModeToggleGroup">
<RadioButton mnemonicParsing="false" text="%search.mode.english"
toggleGroup="$searchModeToggleGroup">
<userData>
<SearchMode fx:value="SEGMENTS"/>
<SearchMode fx:value="ENGLISH"/>
</userData>
</RadioButton>
</FlowPane>

View File

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

View File

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

View File

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

View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff