33import java .io .IOException ;
44import java .net .URISyntaxException ;
55import java .net .URL ;
6- import java .nio .file .Files ;
76import java .nio .file .Path ;
87import java .nio .file .Paths ;
98import java .util .Objects ;
@@ -39,21 +38,25 @@ public class ThemeLoader {
3938 public static final String DEFAULT_MAIN_CSS = "Base.css" ;
4039 private static final String DEFAULT_PATH_MAIN_CSS = JabRefFrame .class .getResource (DEFAULT_MAIN_CSS ).toExternalForm ();
4140 private static final Logger LOGGER = LoggerFactory .getLogger (ThemeLoader .class );
42- private String cssProperty = System .getProperty ("jabref.theme.css" );
41+ private String cssToLoad = System .getProperty ("jabref.theme.css" );
4342 private final FileUpdateMonitor fileUpdateMonitor ;
4443
45- public ThemeLoader (FileUpdateMonitor fileUpdateMonitor , JabRefPreferences jabRefPreferences ) throws JabRefException {
44+ public ThemeLoader (FileUpdateMonitor fileUpdateMonitor , JabRefPreferences jabRefPreferences ) {
4645 this .fileUpdateMonitor = Objects .requireNonNull (fileUpdateMonitor );
4746
48- if (StringUtil .isNullOrEmpty (cssProperty )) {
49- String cssFileName = jabRefPreferences .get (JabRefPreferences .FX_THEME );
50- if (cssFileName != null ) {
51- try {
52- cssProperty = Paths .get (JabRefFrame .class .getResource (cssFileName ).toURI ()).toString ();
53- } catch (URISyntaxException e ) {
54- LOGGER .warn ("can't get css file URI" );
55- throw new JabRefException ("can't set custom theme" );
56- }
47+ if (!StringUtil .isNullOrEmpty (cssToLoad )) {
48+ LOGGER .info ("using css from system " + cssToLoad );
49+ return ;
50+ }
51+
52+ // otherwise load css from preference
53+ String cssFileName = jabRefPreferences .get (JabRefPreferences .FX_THEME );
54+ if (cssFileName != null ) {
55+ try {
56+ cssToLoad = JabRefFrame .class .getResource (cssFileName ).toExternalForm ();
57+ LOGGER .info ("using css " + cssToLoad );
58+ } catch (Exception e ) {
59+ LOGGER .warn ("can't get css file path of " + cssFileName );
5760 }
5861 }
5962 }
@@ -64,15 +67,10 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef
6467 * Changes in the css file lead to a redraw of the scene using the new css file.
6568 */
6669 public void installBaseCss (Scene scene , JabRefPreferences preferences ) {
67- if (StringUtil .isNotBlank (cssProperty )) {
68- final Path path = Paths .get (cssProperty );
69- if (Files .isReadable (path )) {
70- String cssUrl = path .toUri ().toString ();
71- addAndWatchForChanges (scene , cssUrl , 0 );
72- } else {
73- LOGGER .warn (path .toAbsolutePath () + " is not readable" );
74- }
70+ if (!StringUtil .isNullOrEmpty (cssToLoad )) {
71+ addAndWatchForChanges (scene , cssToLoad , 0 );
7572 } else {
73+ LOGGER .warn ("using the last default css " + DEFAULT_PATH_MAIN_CSS );
7674 addAndWatchForChanges (scene , DEFAULT_PATH_MAIN_CSS , 0 );
7775 }
7876
@@ -88,7 +86,7 @@ private void addAndWatchForChanges(Scene scene, String cssUrl, int index) {
8886 try {
8987 // If -Djabref.theme.css is defined and the resources are not part of a .jar bundle,
9088 // we watch the file for changes and turn on live reloading
91- if (!cssUrl .startsWith ("jar:" ) && cssProperty != null ) {
89+ if (!cssUrl .startsWith ("jar:" )) {
9290 Path cssFile = Paths .get (new URL (cssUrl ).toURI ());
9391 LOGGER .info ("Enabling live reloading of " + cssFile );
9492 fileUpdateMonitor .addListenerForFile (cssFile , () -> {
0 commit comments