Skip to content
This repository was archived by the owner on Jul 16, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

35 changes: 31 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
jacoco
application
distribution
kotlin("jvm") version "1.5.20"
id("com.github.spotbugs") version "4.7.9"
id("com.diffplug.spotless") version "5.17.1"
id("com.github.kt3k.coveralls") version "2.12.0"
Expand All @@ -18,7 +19,11 @@ plugins {

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,19 +83,32 @@ repositories {

dependencies {
implementation("io.github.eb4j:eb4j:2.3.0")
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 video replay
implementation("uk.co.caprica:vlcj:4.7.1")

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

// for projector support
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.slf4j:slf4j-simple:1.7.30")
implementation("commons-io:commons-io:2.11.0")
implementation("org.jsoup:jsoup:1.13.1")
implementation("org.java-websocket:Java-WebSocket:1.5.1")
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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