Skip to content

Commit

Permalink
feat/#1 Load custom CSS if toggled
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsstre committed Feb 26, 2020
1 parent 8cb3a50 commit bd6c561
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/org/jabref/gui/util/ThemeLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.util;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
Expand Down Expand Up @@ -48,6 +49,7 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef

String cssVmArgument = System.getProperty("jabref.theme.css");
String cssPreferences = jabRefPreferences.get(JabRefPreferences.FX_THEME);

if (StringUtil.isNotBlank(cssVmArgument)) {
// First priority: VM argument
LOGGER.info("Using css from VM option: {}", cssVmArgument);
Expand All @@ -60,10 +62,20 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef
additionalCssToLoad = Optional.ofNullable(cssVmUrl);
} else if (StringUtil.isNotBlank(cssPreferences) && !MAIN_CSS.equalsIgnoreCase(cssPreferences)) {
// Otherwise load css from preference
URL cssResource = JabRefFrame.class.getResource(cssPreferences);
if (cssResource != null) {
Optional<URL> cssResource = Optional.empty();
if (DARK_CSS.equals(cssPreferences)) {
cssResource = Optional.ofNullable(JabRefFrame.class.getResource(cssPreferences));
} else {
try {
cssResource = Optional.of(new File(cssPreferences).toURI().toURL());
} catch (MalformedURLException e) {
LOGGER.warn("Cannot load css {}", cssResource);
}
}

if (cssResource.isPresent()) {
LOGGER.debug("Using css {}", cssResource);
additionalCssToLoad = Optional.of(cssResource);
additionalCssToLoad = cssResource;
} else {
additionalCssToLoad = Optional.empty();
LOGGER.warn("Cannot load css {}", cssPreferences);
Expand Down Expand Up @@ -104,7 +116,7 @@ private void addAndWatchForChanges(Scene scene, URL cssFile, int index) {
});
}
} catch (IOException | URISyntaxException | UnsupportedOperationException e) {
LOGGER.error("Could not watch css file for changes " + cssFile, e);
LOGGER.error("Could not watch css file for changes {}", cssFile, e);
}
}
}

0 comments on commit bd6c561

Please sign in to comment.