commit 1ee597f93455b486f6017e6c74925e8d0398dcf3 Author: Marvin Elsen Date: Fri Sep 20 17:24:02 2024 +0200 Initial commit diff --git a/.gitea/workflows/pull-request.yaml b/.gitea/workflows/pull-request.yaml new file mode 100644 index 0000000..8be02ff --- /dev/null +++ b/.gitea/workflows/pull-request.yaml @@ -0,0 +1,26 @@ +name: Pull Request + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 21 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Lint + run: ./gradlew detekt + - name: Build + run: ./gradlew build testClasses -x check + - name: Test + run: ./gradlew test \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b33b62 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Kotlin ### +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..125978a --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,52 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.detekt) + alias(libs.plugins.jfx) +} + +group = "com.marvinelsen" +version = "1.0.0" + +repositories { + mavenCentral() + repositories { + maven { + url = uri("https://gitea.marvinelsen.com/api/packages/marvinelsen/maven") + } + } +} + +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) + + testImplementation(libs.kotest.core) + testImplementation(libs.kotest.assertions) +} + +tasks.test { + useJUnitPlatform() +} + +kotlin { + jvmToolchain(21) +} + +javafx { + version = libs.versions.javafx.get() + modules("javafx.base", "javafx.graphics", "javafx.controls", "javafx.fxml", "javafx.web") +} + +detekt { + buildUponDefaultConfig = true + allRules = false + autoCorrect = true +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..29e08e8 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..c75a353 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,45 @@ +[versions] +kotlin = "2.0.20" +detekt = "1.23.7" +jfx-plugin = "0.1.0" +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" + +[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" } +kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } + +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" } + +# Detekt +# See: https://detekt.dev +detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } + +[plugins] +# Kotlin +# See: https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } + +# Detekt +# See: https://detekt.dev +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } + +jfx = { id = "org.openjfx.javafxplugin", version.ref = "jfx-plugin" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a4b76b9 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..0aaefbc --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..f5feea6 --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..9d21a21 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..6c8f74b --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "willow" \ No newline at end of file diff --git a/src/main/kotlin/com/marvinelsen/willow/Model.kt b/src/main/kotlin/com/marvinelsen/willow/Model.kt new file mode 100644 index 0000000..50d832c --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/Model.kt @@ -0,0 +1,62 @@ +package com.marvinelsen.willow + +import com.marvinelsen.willow.domain.SearchMode +import com.marvinelsen.willow.ui.DictionaryEntryFx +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 +import javafx.beans.property.SimpleObjectProperty +import javafx.collections.FXCollections +import javafx.collections.ObservableList +import javafx.event.EventHandler + +class Model(private val searchService: SearchService, private val findWordsService: FindWordsService) { + private val internalSelectedEntry: ObjectProperty = SimpleObjectProperty() + private val internalSearchResults: ObservableList = FXCollections.observableArrayList() + private val internalWordsContaining: ObservableList = FXCollections.observableArrayList() + + val selectedEntry: ReadOnlyObjectProperty = internalSelectedEntry + + val searchResults: ObservableList = + FXCollections.unmodifiableObservableList(internalSearchResults) + val wordsContaining: ObservableList = + FXCollections.unmodifiableObservableList(internalWordsContaining) + + val isSearching: ReadOnlyBooleanProperty = searchService.runningProperty() + val isFindingWords: ReadOnlyBooleanProperty = findWordsService.runningProperty() + + init { + searchService.onSucceeded = EventHandler { + internalSearchResults.setAll(searchService.value) + } + findWordsService.onSucceeded = EventHandler { + internalWordsContaining.setAll(findWordsService.value) + } + } + + fun search(query: String, searchMode: SearchMode) { + searchService.searchQuery = query + searchService.searchMode = searchMode + searchService.restart() + } + + fun findWords() { + findWordsService.entry = internalSelectedEntry.value + findWordsService.restart() + } + + fun selectEntry(entry: DictionaryEntryFx) { + internalSelectedEntry.value = entry + } + + fun copyHeadwordOfSelectedEntry() { + ClipboardHelper.copyHeadword(internalSelectedEntry.get()) + } + + fun copyPronunciationOfSelectedEntry() { + ClipboardHelper.copyPronunciation(internalSelectedEntry.get()) + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt new file mode 100644 index 0000000..4a01aa5 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt @@ -0,0 +1,81 @@ +package com.marvinelsen.willow + +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.util.FindWordsService +import com.marvinelsen.willow.ui.util.SearchService +import javafx.application.Application +import javafx.fxml.FXMLLoader +import javafx.scene.Scene +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() { + companion object { + private const val WINDOW_TITLE = "Willow" + private const val WINDOW_MIN_HEIGHT = 480.0 + private const val WINDOW_MIN_WIDTH = 640.0 + private const val WINDOW_WIDTH = 640.0 + private const val WINDOW_HEIGHT = 480.0 + + private const val FONT_SIZE = 12.0 + + private const val JDBC_CONNECTION_STRING = "jdbc:sqlite:dictionary.db" + } + + override fun init() { + loadFonts() + } + + override fun start(primaryStage: Stage) { + val connection = DriverManager.getConnection(JDBC_CONNECTION_STRING).apply { + autoCommit = false + } + val dictionary = SqliteDictionary(connection) + val searchService = SearchService(dictionary) + val findWordsService = FindWordsService(dictionary) + val model = Model(searchService, findWordsService) + + val fxmlLoader = FXMLLoader() + fxmlLoader.resources = ResourceBundle.getBundle("i18n/willow", Locale.US) + fxmlLoader.controllerFactory = Callback { type -> + when (type) { + MainController::class.java -> MainController(model) + MenuController::class.java -> MenuController(model) + DetailsController::class.java -> DetailsController(model) + SearchController::class.java -> SearchController(model) + else -> error("Trying to instantiate unknown controller type $type") + } + } + + val root = fxmlLoader.load(javaClass.getResourceAsStream("/fxml/main.fxml")) as BorderPane + + val primaryScene = Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT) + + primaryStage.apply { + title = WINDOW_TITLE + minWidth = WINDOW_MIN_WIDTH + minHeight = WINDOW_MIN_HEIGHT + scene = primaryScene + }.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.ttf"), FONT_SIZE) + } +} + +@Suppress("SpreadOperator") +fun main(args: Array) { + Application.launch(WillowApplication::class.java, *args) +} diff --git a/src/main/kotlin/com/marvinelsen/willow/cedict/CreateDatabase.kt b/src/main/kotlin/com/marvinelsen/willow/cedict/CreateDatabase.kt new file mode 100644 index 0000000..5b61c09 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/cedict/CreateDatabase.kt @@ -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() +} diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/DatabaseQueryTest.kt b/src/main/kotlin/com/marvinelsen/willow/domain/DatabaseQueryTest.kt new file mode 100644 index 0000000..11e4dd2 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/domain/DatabaseQueryTest.kt @@ -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) +} diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/Dictionary.kt b/src/main/kotlin/com/marvinelsen/willow/domain/Dictionary.kt new file mode 100644 index 0000000..c77415f --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/domain/Dictionary.kt @@ -0,0 +1,8 @@ +package com.marvinelsen.willow.domain + +interface Dictionary { + fun search(query: String, searchMode: SearchMode): List + fun findWordsContaining(entry: DictionaryEntry): List + fun findSentencesContaining(entry: DictionaryEntry): List + fun findCharacters(entry: DictionaryEntry): List +} diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt b/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt new file mode 100644 index 0000000..6667c39 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/domain/DictionaryEntry.kt @@ -0,0 +1,10 @@ +package com.marvinelsen.willow.domain + +data class DictionaryEntry( + val traditional: String, + val simplified: String, + val pinyinWithToneMarks: String, + val pinyinWithToneNumbers: String, + val zhuyin: String, + val definitions: List> +) diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/SearchMode.kt b/src/main/kotlin/com/marvinelsen/willow/domain/SearchMode.kt new file mode 100644 index 0000000..79e8908 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/domain/SearchMode.kt @@ -0,0 +1,5 @@ +package com.marvinelsen.willow.domain + +enum class SearchMode { + PINYIN, SIMPLIFIED, TRADITIONAL, ENGLISH +} diff --git a/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt new file mode 100644 index 0000000..9e74dd8 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/domain/SqliteDictionary.kt @@ -0,0 +1,99 @@ +package com.marvinelsen.willow.domain + +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 searchSimplifiedPreparedStatement: PreparedStatement by lazy { + connection.prepareStatement( + """ + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions + FROM cedict + WHERE simplified GLOB ? + ORDER BY character_count ASC + """.trimIndent() + ) + } + + private val searchTraditionalPreparedStatement: PreparedStatement by lazy { + connection.prepareStatement( + """ + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions + FROM cedict + WHERE traditional GLOB ? + ORDER BY character_count ASC + """.trimIndent() + ) + } + + private val findWordsContaining: PreparedStatement by lazy { + connection.prepareStatement( + """ + SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions + FROM cedict + WHERE traditional LIKE ? + ORDER BY character_count ASC + """.trimIndent() + ) + } + + override fun search(query: String, searchMode: SearchMode) = when (searchMode) { + SearchMode.PINYIN -> TODO() + SearchMode.SIMPLIFIED -> searchSimplified(query) + SearchMode.TRADITIONAL -> searchTraditional(query) + SearchMode.ENGLISH -> TODO() + } + + override fun findWordsContaining(entry: DictionaryEntry): List { + findWordsContaining.setString(1, "_%${entry.traditional}%") + + val resultSet: ResultSet = findWordsContaining.executeQuery() + + return resultSet.toListOfDictionaryEntries() + } + + override fun findSentencesContaining(entry: DictionaryEntry): List { + return emptyList() + } + + override fun findCharacters(entry: DictionaryEntry): List { + return emptyList() + } + + private fun searchSimplified(query: String): List { + searchSimplifiedPreparedStatement.setString(1, "$query*") + + val resultSet: ResultSet = searchSimplifiedPreparedStatement.executeQuery() + + return resultSet.toListOfDictionaryEntries() + } + + private fun searchTraditional(query: String): List { + searchTraditionalPreparedStatement.setString(1, "$query*") + + val resultSet: ResultSet = searchTraditionalPreparedStatement.executeQuery() + + return resultSet.toListOfDictionaryEntries() + } +} + +@Suppress("MagicNumber") +private fun ResultSet.toDictionaryEntry() = DictionaryEntry( + traditional = this.getString(1), + simplified = this.getString(2), + pinyinWithToneMarks = this.getString(3), + pinyinWithToneNumbers = this.getString(4), + zhuyin = this.getString(5), + definitions = Json.decodeFromString(this.getString(6)) +) + +private fun ResultSet.toListOfDictionaryEntries() = buildList { + this@toListOfDictionaryEntries.use { + while (it.next()) { + add(it.toDictionaryEntry()) + } + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/Configuration.kt b/src/main/kotlin/com/marvinelsen/willow/ui/Configuration.kt new file mode 100644 index 0000000..314c10d --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/Configuration.kt @@ -0,0 +1,3 @@ +package com.marvinelsen.willow.ui + +class Configuration diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt b/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt new file mode 100644 index 0000000..9045536 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/DictionaryEntryFx.kt @@ -0,0 +1,34 @@ +package com.marvinelsen.willow.ui + +import com.marvinelsen.willow.domain.DictionaryEntry +import javafx.beans.property.SimpleStringProperty +import javafx.beans.property.StringProperty +import javafx.collections.FXCollections +import javafx.collections.ObservableList + +data class DictionaryEntryFx( + val traditionalProperty: StringProperty, + val simplifiedProperty: StringProperty, + val pinyinWithToneMarksProperty: StringProperty, + val pinyinWithToneNumbersProperty: StringProperty, + val zhuyinProperty: StringProperty, + val definitions: ObservableList>, +) + +fun DictionaryEntry.toFx() = DictionaryEntryFx( + traditionalProperty = SimpleStringProperty(this.traditional), + simplifiedProperty = SimpleStringProperty(this.simplified), + pinyinWithToneMarksProperty = SimpleStringProperty(this.pinyinWithToneMarks), + pinyinWithToneNumbersProperty = SimpleStringProperty(this.pinyinWithToneNumbers), + zhuyinProperty = SimpleStringProperty(this.zhuyin), + definitions = FXCollections.observableList(this.definitions) +) + +fun DictionaryEntryFx.toDomain() = DictionaryEntry( + traditional = this.traditionalProperty.value, + simplified = this.simplifiedProperty.value, + pinyinWithToneMarks = this.pinyinWithToneMarksProperty.value, + pinyinWithToneNumbers = this.pinyinWithToneNumbersProperty.value, + zhuyin = this.zhuyinProperty.value, + definitions = this.definitions.toList() +) diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/cells/EntryCellFactory.kt b/src/main/kotlin/com/marvinelsen/willow/ui/cells/EntryCellFactory.kt new file mode 100644 index 0000000..0513a6a --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/cells/EntryCellFactory.kt @@ -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, ListCell> { + override fun call(listView: ListView): ListCell { + 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() { + 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 + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt new file mode 100644 index 0000000..039dcb1 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt @@ -0,0 +1,84 @@ +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.TabPane +import javafx.scene.web.WebView + +class DetailsController(private val model: Model) { + @FXML + private lateinit var tabPaneDetails: TabPane + + @FXML + private lateinit var webViewDefinition: WebView + + @FXML + @Suppress("UnusedPrivateProperty") + private lateinit var listviewSentences: ListView + + @FXML + private lateinit var listViewWords: ListView + + @FXML + @Suppress("UnusedPrivateProperty") + private lateinit var listViewCharacters: ListView + + @FXML + private lateinit var labelHeadword: Label + + @FXML + @Suppress("UnusedPrivateMember") + private fun initialize() { + val headwordObjectBinding = + Bindings.createStringBinding({ model.selectedEntry.value?.traditionalProperty?.value }, model.selectedEntry) + + labelHeadword.textProperty().bind(headwordObjectBinding) + + tabPaneDetails.disableProperty().bind(Bindings.isNull(model.selectedEntry)) + + listViewWords.items = model.wordsContaining + tabPaneDetails.selectionModel.selectedItemProperty().addListener { _, _, selectedTab -> + if (model.selectedEntry.value == null) return@addListener + + when (selectedTab.id) { + "tabWords" -> { + model.findWords() + } + + else -> {} + } + } + + webViewDefinition.apply { + isContextMenuEnabled = false + engine.userStyleSheetLocation = + this::class.java.getResource("/css/definitions.css")!!.toExternalForm() + } + + model.selectedEntry.addListener { _, _, newValue -> + if (newValue == null) { + return@addListener + } + webViewDefinition.engine.loadContent( + buildString { + append("") + append("") + append("

CC-CEDICT

") + append("
    ") + for (definition in newValue.definitions) { + append("
  1. ") + append(definition.joinToString(separator = "; ")) + append("
  2. ") + } + append("
") + append("") + append("") + } + ) + } + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MainController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MainController.kt new file mode 100644 index 0000000..2298f7c --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MainController.kt @@ -0,0 +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 + +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 + + @FXML + @Suppress("UnusedPrivateMember") + private fun initialize() { + 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) + } + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MenuController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MenuController.kt new file mode 100644 index 0000000..3a74300 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MenuController.kt @@ -0,0 +1,37 @@ +package com.marvinelsen.willow.ui.controllers + +import com.marvinelsen.willow.Model +import javafx.application.Platform +import javafx.beans.binding.Bindings +import javafx.fxml.FXML +import javafx.scene.control.MenuItem + +@Suppress("UnusedPrivateMember") +class MenuController(private val model: Model) { + @FXML + private lateinit var menuItemCopyHeadword: MenuItem + + @FXML + private lateinit var menuItemCopyPronunciation: MenuItem + + @FXML + private fun initialize() { + menuItemCopyPronunciation.disableProperty().bind(Bindings.isNull(model.selectedEntry)) + menuItemCopyHeadword.disableProperty().bind(Bindings.isNull(model.selectedEntry)) + } + + @FXML + private fun onMenuItemQuitAction() { + Platform.exit() + } + + @FXML + private fun onMenuItemCopyPronunciationAction() { + model.copyPronunciationOfSelectedEntry() + } + + @FXML + private fun onMenuItemCopyHeadwordAction() { + model.copyHeadwordOfSelectedEntry() + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchController.kt new file mode 100644 index 0000000..ed30ed9 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchController.kt @@ -0,0 +1,28 @@ +package com.marvinelsen.willow.ui.controllers + +import com.marvinelsen.willow.Model +import com.marvinelsen.willow.domain.SearchMode +import javafx.fxml.FXML +import javafx.scene.control.TextField +import javafx.scene.control.ToggleGroup + +class SearchController(private val model: Model) { + @FXML + private lateinit var searchModeToggleGroup: ToggleGroup + + @FXML + private lateinit var textFieldSearch: TextField + + @FXML + @Suppress("UnusedPrivateMember") + private fun initialize() { + textFieldSearch.textProperty().addListener { _, _, newValue -> + if (newValue.isNullOrBlank()) { + return@addListener + } + + val searchMode = searchModeToggleGroup.selectedToggle.userData as SearchMode + model.search(newValue, searchMode) + } + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/util/ClipboardHelper.kt b/src/main/kotlin/com/marvinelsen/willow/ui/util/ClipboardHelper.kt new file mode 100644 index 0000000..2f56a60 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/util/ClipboardHelper.kt @@ -0,0 +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 copyHeadword(entry: DictionaryEntryFx) { + val clipboardContent = ClipboardContent() + clipboardContent.putString(entry.traditionalProperty.value) + systemClipboard.setContent(clipboardContent) + } + + fun copyPronunciation(entry: DictionaryEntryFx) { + val clipboardContent = ClipboardContent() + clipboardContent.putString(entry.pinyinWithToneMarksProperty.value) + systemClipboard.setContent(clipboardContent) + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/util/Concurrency.kt b/src/main/kotlin/com/marvinelsen/willow/ui/util/Concurrency.kt new file mode 100644 index 0000000..13fcfb9 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/util/Concurrency.kt @@ -0,0 +1,7 @@ +package com.marvinelsen.willow.ui.util + +import javafx.concurrent.Task + +fun task(block: () -> T) = object : Task() { + override fun call() = block() +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt b/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt new file mode 100644 index 0000000..d7c9e73 --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/util/ContextMenuUtils.kt @@ -0,0 +1,18 @@ +package com.marvinelsen.willow.ui.util + +import com.marvinelsen.willow.ui.DictionaryEntryFx +import javafx.event.EventHandler +import javafx.scene.control.ContextMenu +import javafx.scene.control.MenuItem + +fun createContextMenuForEntry(entry: DictionaryEntryFx) = ContextMenu().apply { + val menuItemCopyHeadword = MenuItem("Copy Headword").apply { + onAction = EventHandler { ClipboardHelper.copyHeadword(entry) } + } + + val menuItemCopyPronunciation = MenuItem("Copy Pronunciation").apply { + onAction = EventHandler { ClipboardHelper.copyPronunciation(entry) } + } + + items.addAll(menuItemCopyHeadword, menuItemCopyPronunciation) +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/util/Services.kt b/src/main/kotlin/com/marvinelsen/willow/ui/util/Services.kt new file mode 100644 index 0000000..bb256ee --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/util/Services.kt @@ -0,0 +1,32 @@ +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 javafx.collections.FXCollections +import javafx.collections.ObservableList +import javafx.concurrent.Service + +class SearchService(private val dictionary: Dictionary) : Service>() { + lateinit var searchQuery: String + lateinit var searchMode: SearchMode + + override fun createTask() = task { + if (!this::searchQuery.isInitialized) error("Search query is not initialized") + if (!this::searchMode.isInitialized) error("Search mode is not initialized") + + FXCollections.observableList(dictionary.search(searchQuery, searchMode).map { it.toFx() }) + } +} + +class FindWordsService(private val dictionary: Dictionary) : Service>() { + 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() }) + } +} diff --git a/src/main/resources/css/definitions.css b/src/main/resources/css/definitions.css new file mode 100644 index 0000000..18d48cd --- /dev/null +++ b/src/main/resources/css/definitions.css @@ -0,0 +1,63 @@ +html { + font-family: "Noto Sans TC"; + font-size: 16px; + line-height: 1.7em; + + border: 1px solid #B5B5B5; + padding: 16px; + + overflow-wrap: break-word; + word-break: break-all; +} + +h1 { + font-weight: bold; + font-size: 1.25em; +} + +ol li:only-child { + list-style: none; +} + +hr.in-definition { + width: 50%; + margin-left: 0; +} + +li { + margin-bottom: 0.5em; +} + +span.type { + color: #fff; + background-color: rgb(107, 0, 0); + + border-radius: 4px; + + padding: 2px; +} + +span.definition { + display: block; + margin-bottom: 2pt; +} + +span.example { + display: block; + font-size: 0.9em; +} + +span.quote { + display: block; + font-size: 0.9em; +} + +span.synonyms { + display: block; + font-size: 0.9em; +} + +span.antonyms { + display: block; + font-size: 0.9em; +} diff --git a/src/main/resources/css/details.css b/src/main/resources/css/details.css new file mode 100644 index 0000000..bdfec22 --- /dev/null +++ b/src/main/resources/css/details.css @@ -0,0 +1,4 @@ +.headword { + -fx-font-family: TW-Kai; + -fx-font-size: 40; +} diff --git a/src/main/resources/css/main.css b/src/main/resources/css/main.css new file mode 100644 index 0000000..b635691 --- /dev/null +++ b/src/main/resources/css/main.css @@ -0,0 +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; +} diff --git a/src/main/resources/data/LICENSE-CC-CEDICT b/src/main/resources/data/LICENSE-CC-CEDICT new file mode 100644 index 0000000..2d58298 --- /dev/null +++ b/src/main/resources/data/LICENSE-CC-CEDICT @@ -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. + diff --git a/src/main/resources/data/cedict_1_0_ts_utf-8_mdbg.txt.gz b/src/main/resources/data/cedict_1_0_ts_utf-8_mdbg.txt.gz new file mode 100644 index 0000000..f2823b3 Binary files /dev/null and b/src/main/resources/data/cedict_1_0_ts_utf-8_mdbg.txt.gz differ diff --git a/src/main/resources/fonts/LICENSE-INTER b/src/main/resources/fonts/LICENSE-INTER new file mode 100644 index 0000000..9b2ca37 --- /dev/null +++ b/src/main/resources/fonts/LICENSE-INTER @@ -0,0 +1,92 @@ +Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/main/resources/fonts/LICENSE-NOTO-SANS-CJK b/src/main/resources/fonts/LICENSE-NOTO-SANS-CJK new file mode 100644 index 0000000..d45fd49 --- /dev/null +++ b/src/main/resources/fonts/LICENSE-NOTO-SANS-CJK @@ -0,0 +1,92 @@ +This Font Software is licensed under the SIL Open Font License, +Version 1.1. + +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/src/main/resources/fonts/LICENSE-TW-KAI b/src/main/resources/fonts/LICENSE-TW-KAI new file mode 100644 index 0000000..d45fd49 --- /dev/null +++ b/src/main/resources/fonts/LICENSE-TW-KAI @@ -0,0 +1,92 @@ +This Font Software is licensed under the SIL Open Font License, +Version 1.1. + +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/src/main/resources/fonts/inter.ttf b/src/main/resources/fonts/inter.ttf new file mode 100644 index 0000000..2d4b470 Binary files /dev/null and b/src/main/resources/fonts/inter.ttf differ diff --git a/src/main/resources/fonts/noto-sans-tc.ttf b/src/main/resources/fonts/noto-sans-tc.ttf new file mode 100644 index 0000000..fa89e00 Binary files /dev/null and b/src/main/resources/fonts/noto-sans-tc.ttf differ diff --git a/src/main/resources/fonts/tw-kai.ttf b/src/main/resources/fonts/tw-kai.ttf new file mode 100644 index 0000000..7887fdb Binary files /dev/null and b/src/main/resources/fonts/tw-kai.ttf differ diff --git a/src/main/resources/fxml/details.fxml b/src/main/resources/fxml/details.fxml new file mode 100644 index 0000000..0aa5bfe --- /dev/null +++ b/src/main/resources/fxml/details.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/main.fxml b/src/main/resources/fxml/main.fxml new file mode 100644 index 0000000..ab1805a --- /dev/null +++ b/src/main/resources/fxml/main.fxml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
diff --git a/src/main/resources/fxml/menu.fxml b/src/main/resources/fxml/menu.fxml new file mode 100644 index 0000000..cfd4025 --- /dev/null +++ b/src/main/resources/fxml/menu.fxml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/search.fxml b/src/main/resources/fxml/search.fxml new file mode 100644 index 0000000..a8dfc1b --- /dev/null +++ b/src/main/resources/fxml/search.fxml @@ -0,0 +1,40 @@ + + + + + + + + + + + + diff --git a/src/main/resources/i18n/willow.properties b/src/main/resources/i18n/willow.properties new file mode 100644 index 0000000..a90a055 --- /dev/null +++ b/src/main/resources/i18n/willow.properties @@ -0,0 +1,19 @@ +search.prompt=Search dictionary… +search.mode=Searching: +search.mode.pinyin=Pinyin +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.settings=_Settings… +menubar.edit=_Edit +menubar.edit.copy.headword=Copy Headword +menubar.edit.copy.pronunciation=Copy Pronunciation +menubar.help=_Help +menubar.help.about=_About… +list.no_entries_found=No matching entries found diff --git a/src/main/resources/i18n/willow_de.properties b/src/main/resources/i18n/willow_de.properties new file mode 100644 index 0000000..5ae4d0d --- /dev/null +++ b/src/main/resources/i18n/willow_de.properties @@ -0,0 +1,19 @@ +search.prompt=Durchsuche Wörterbuch… +search.mode=Suche: +search.mode.pinyin=Pinyin +search.mode.traditional=Langzeichen +search.mode.simplified=Kurzzeichen +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.settings=_Einstellungen… +menubar.edit=_Bearbeiten +menubar.edit.copy.headword=Kopiere Wort +menubar.edit.copy.pronunciation=Kopiere Aussprache +menubar.help=_Hilfe +menubar.help.about=_Über… +list.no_entries_found=No matching entries found diff --git a/src/main/resources/i18n/willow_en.properties b/src/main/resources/i18n/willow_en.properties new file mode 100644 index 0000000..a90a055 --- /dev/null +++ b/src/main/resources/i18n/willow_en.properties @@ -0,0 +1,19 @@ +search.prompt=Search dictionary… +search.mode=Searching: +search.mode.pinyin=Pinyin +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.settings=_Settings… +menubar.edit=_Edit +menubar.edit.copy.headword=Copy Headword +menubar.edit.copy.pronunciation=Copy Pronunciation +menubar.help=_Help +menubar.help.about=_About… +list.no_entries_found=No matching entries found diff --git a/src/main/resources/i18n/willow_zh_CN.properties b/src/main/resources/i18n/willow_zh_CN.properties new file mode 100644 index 0000000..57faf58 --- /dev/null +++ b/src/main/resources/i18n/willow_zh_CN.properties @@ -0,0 +1,19 @@ +search.prompt=搜尋… +search.mode=搜尋: +search.mode.pinyin=漢語拼音 +search.mode.traditional=繁體字 +search.mode.simplified=簡體字 +search.mode.english=英文 +tab.definition=Definition +tab.sentences=例句 +tab.words=詞 +tab.characters=字 +menubar.file=_檔案 +menubar.file.quit=_結束 Willow +menubar.file.settings=_設定… +menubar.edit=_編輯 +menubar.edit.copy.headword=複製 Wort +menubar.edit.copy.pronunciation=複製 Aussprache +menubar.help=_說明 +menubar.help.about=_關於 Willow… +list.no_entries_found=No matching entries found diff --git a/src/main/resources/i18n/willow_zh_TW.properties b/src/main/resources/i18n/willow_zh_TW.properties new file mode 100644 index 0000000..57faf58 --- /dev/null +++ b/src/main/resources/i18n/willow_zh_TW.properties @@ -0,0 +1,19 @@ +search.prompt=搜尋… +search.mode=搜尋: +search.mode.pinyin=漢語拼音 +search.mode.traditional=繁體字 +search.mode.simplified=簡體字 +search.mode.english=英文 +tab.definition=Definition +tab.sentences=例句 +tab.words=詞 +tab.characters=字 +menubar.file=_檔案 +menubar.file.quit=_結束 Willow +menubar.file.settings=_設定… +menubar.edit=_編輯 +menubar.edit.copy.headword=複製 Wort +menubar.edit.copy.pronunciation=複製 Aussprache +menubar.help=_說明 +menubar.help.about=_關於 Willow… +list.no_entries_found=No matching entries found