Skip to content

Commit

Permalink
Merge pull request #5497 from JabRef/fixdarktheme
Browse files Browse the repository at this point in the history
Try to fix dark theme path
  • Loading branch information
Siedlerchr authored Oct 25, 2019
2 parents e7c4be5 + b97f58f commit 681d6aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.preview;

import java.net.URL;
import java.util.Base64;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -27,6 +29,7 @@
import org.jabref.logic.search.SearchQuery;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.strings.StringUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -116,9 +119,14 @@ public PreviewViewer(BibDatabaseContext database, DialogService dialogService, S

public void setTheme(String theme) {
if (theme.equals(ThemeLoader.DARK_CSS)) {
previewView.getEngine().setUserStyleSheetLocation(JabRefFrame.class.getResource(ThemeLoader.DARK_CSS).toString());
// We need to load the css file manually, due to a bug in the jdk
// TODO: Remove this workaround as soon as https://github.com/openjdk/jfx/pull/22 is merged
URL url = JabRefFrame.class.getResource(ThemeLoader.DARK_CSS);
String dataUrl = "data:text/css;charset=utf-8;base64," +
Base64.getEncoder().encodeToString(StringUtil.getResourceFileAsString(url).getBytes());

previewView.getEngine().setUserStyleSheetLocation(dataUrl);
}

}

private void highlightSearchPattern() {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/jabref/model/strings/StringUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package org.jabref.model.strings;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -9,6 +16,7 @@
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.jabref.architecture.ApacheCommonsLang3Allowed;

Expand Down Expand Up @@ -721,4 +729,19 @@ public static boolean containsIgnoreCase(String text, String searchString) {
public static String substringBetween(String str, String open, String close) {
return StringUtils.substringBetween(str, open, close);
}

public static String getResourceFileAsString(URL resource) {
try {
URLConnection conn = resource.openConnection();
conn.connect();

try (InputStream inputStream = new BufferedInputStream(conn.getInputStream());
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(inputStreamReader)) {
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/org/jabref/model/strings/StringUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void StringUtilClassIsSmall() throws Exception {
Path path = Paths.get("src", "main", "java", StringUtil.class.getName().replace('.', '/') + ".java");
int lineCount = Files.readAllLines(path, StandardCharsets.UTF_8).size();

assertTrue(lineCount <= 725, "StringUtil increased in size to " + lineCount + ". "
assertTrue(lineCount <= 749, "StringUtil increased in size to " + lineCount + ". "
+ "We try to keep this class as small as possible. "
+ "Thus think twice if you add something to StringUtil.");
}
Expand Down

0 comments on commit 681d6aa

Please sign in to comment.