Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'main' into topic-support-mdict
Browse files Browse the repository at this point in the history
  • Loading branch information
miurahr committed Nov 18, 2021
2 parents d69c074 + 2e9cdba commit 91d5573
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 36 additions & 7 deletions build.gradle.kts
Expand Up @@ -9,16 +9,21 @@ plugins {
jacoco
application
distribution
kotlin("jvm") version "1.5.31"
id("com.github.spotbugs") version "4.7.9"
id("com.diffplug.spotless") version "5.17.1"
id("com.diffplug.spotless") version "6.0.0"
id("com.github.kt3k.coveralls") version "2.12.0"
id("org.mikeneck.graalvm-native-image") version "1.4.1"
id("com.palantir.git-version") version "0.12.3" apply false
}

fun getProps(f: File): Properties {
val props = Properties()
props.load(FileInputStream(f))
try {
props.load(FileInputStream(f))
} catch (t: Throwable) {
println("Can't read $f: $t, assuming empty")
}
return props
}

Expand Down Expand Up @@ -58,6 +63,15 @@ application {
mainClass.set("io.github.eb4j.ebview.EBViewer")
}

val home = System.getProperty("user.home")
tasks.register<JavaExec>("projectorRun") {
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("io.github.eb4j.ebview.EBViewer")
systemProperty("org.jetbrains.projector.server.enable", "true")
args = listOf("$home/Dicts")
group = "application"
}

application.applicationDistribution.into("") {
from("README.md", "COPYING")
}
Expand All @@ -69,20 +83,35 @@ repositories {

dependencies {
implementation("io.github.eb4j:eb4j:2.3.0")
implementation("io.github.eb4j:mdict4j:0.1.1")
implementation("org.slf4j:slf4j-simple:1.7.32")

implementation("commons-io:commons-io:2.11.0")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("tokyo.northside:url-protocol-handler:0.1.4")

// for pdic
implementation("com.ibm.icu:icu4j-charset:70.1")

// for stardict
implementation("io.github.dictzip:dictzip:0.9.5")
implementation("com.github.takawitter:trie4j:0.9.8")

// for mdict
implementation("io.github.eb4j:mdict4j:0.1.1")

// for video replay
implementation("uk.co.caprica:vlcj:4.7.1")

implementation("com.formdev:flatlaf:1.6.1")
implementation("com.formdev:flatlaf:1.6.2")

// for projector support
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.slf4j:slf4j-simple:1.7.32")
implementation("commons-io:commons-io:2.11.0")
implementation("org.jsoup:jsoup:1.13.1")
implementation("org.java-websocket:Java-WebSocket:1.5.2")
implementation("dnsjava:dnsjava:2.1.9")
implementation("org.javassist:javassist:3.27.0-GA")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.2.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1")

testImplementation("org.codehaus.groovy:groovy-all:3.0.9")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
Expand Down
Binary file added libs/projector-agent-initialization-4892def9.jar
Binary file not shown.
Binary file added libs/projector-awt-1.4.0.jar
Binary file not shown.
Binary file added libs/projector-common-jvm-4892def9.jar
Binary file not shown.
Binary file added libs/projector-server-1.4.0.jar
Binary file not shown.
Binary file added libs/projector-server-core-4892def9.jar
Binary file not shown.
Binary file added libs/projector-util-agent-4892def9.jar
Binary file not shown.
Binary file added libs/projector-util-loading-4892def9.jar
Binary file not shown.
Binary file added libs/projector-util-logging-jvm-4892def9.jar
Binary file not shown.
19 changes: 16 additions & 3 deletions src/main/java/io/github/eb4j/ebview/EBViewer.java
Expand Up @@ -4,6 +4,8 @@
import io.github.eb4j.ebview.dictionary.DictionariesManager;
import io.github.eb4j.ebview.gui.MainWindow;
import io.github.eb4j.ebview.gui.MainWindowMenu;
import org.jetbrains.projector.server.ProjectorLauncher;
import org.jetbrains.projector.server.ProjectorServer;
import tokyo.northside.protocol.URLProtocolHandler;

import javax.swing.JFrame;
Expand All @@ -14,13 +16,18 @@ public class EBViewer implements Runnable {
private final DictionariesManager dictionariesManager;
private final MainWindow mw;

public EBViewer(final File dictionaryDirectory) {
public EBViewer(final File dictionaryDirectory, final boolean remote) {
dictionariesManager = new DictionariesManager();
if (dictionaryDirectory != null) {
dictionariesManager.loadDictionaries(dictionaryDirectory);
}
mw = new MainWindow(dictionariesManager);
new MainWindowMenu(this);
if (!remote) {
new MainWindowMenu(this);
mw.showMessage("Please add dictionaries from Dictionary menu at first.");
} else {
mw.showMessage("Please enter search word above input box.");
}
}

public DictionariesManager getDictionariesManager() {
Expand All @@ -36,14 +43,20 @@ public JFrame getApplicationFrame() {
* @param args command line arguments.
*/
public static void main(final String... args) {
boolean remote = ProjectorServer.isEnabled();
if (remote) {
if (!ProjectorLauncher.runProjectorServer()) {
throw new RuntimeException("Fail to start projector server");
}
}
URLProtocolHandler.install();
FlatLightLaf.setup();
File dictionaryDirectory = null;
if (args.length == 1) {
dictionaryDirectory = new File(args[0]);
}
try {
EBViewer viewer = new EBViewer(dictionaryDirectory);
EBViewer viewer = new EBViewer(dictionaryDirectory, remote);
Thread t = new Thread(viewer);
t.start();
} catch (Exception e) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/github/eb4j/ebview/gui/MainWindow.java
Expand Up @@ -147,14 +147,17 @@ private void initializeGUI() {
getContentPane().add(headingsPane, BorderLayout.WEST);
getContentPane().add(articlePane, BorderLayout.CENTER);
getContentPane().add(infoPanel, BorderLayout.EAST);
DICTIONARY_PANE.setText("Please add dictionaries from Dictionary menu at first.");
if (SystemTray.isSupported()) {
setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
} else {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

public void showMessage(final String msg) {
DICTIONARY_PANE.setText(msg);
}

private void startSearch() {
Searcher searchSwingWorker = new Searcher(ebViewerModel, dictionariesManager);
searchSwingWorker.execute();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/io/github/eb4j/ebview/utils/ResourceUtil.java
@@ -1,7 +1,8 @@
package io.github.eb4j.ebview.utils;

import javax.imageio.ImageIO;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.URL;

public final class ResourceUtil {
Expand Down Expand Up @@ -33,7 +34,13 @@ private ResourceUtil() {
*/
public static Image getImage(final String resourceName) {
URL resourceURL = ResourceUtil.class.getResource(resourceName);
return Toolkit.getDefaultToolkit().getImage(resourceURL);
if (resourceURL != null) {
try {
return ImageIO.read(resourceURL);
} catch (IOException ignored) {
}
}
return null;
}

/**
Expand Down

0 comments on commit 91d5573

Please sign in to comment.