From a3a15310d38df7fb7badaf46dd77a70f1426e4c1 Mon Sep 17 00:00:00 2001 From: Fancy Z Date: Wed, 24 Oct 2018 22:45:50 +0800 Subject: [PATCH 1/3] fix "save" button in preference dialog not response or work this is because default value for fxTheme is not set, thus cause null exception solution: set default value "Base.css" for key "fxTheme" in preferencewq --- src/main/java/org/jabref/preferences/JabRefPreferences.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 45f724fc252..80298994fcc 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -780,6 +780,8 @@ private JabRefPreferences() { + "\\begin{comment}

Comment: \\format[HTMLChars]{\\comment} \\end{comment}" + "__NEWLINE__

"); + // set default theme + defaults.put(JabRefPreferences.FX_THEME, "Base.css"); setLanguageDependentDefaultValues(); } From 613db98867502dad77bf4e9192692572eced041c Mon Sep 17 00:00:00 2001 From: Fancy Z Date: Thu, 25 Oct 2018 22:00:02 +0800 Subject: [PATCH 2/3] avoid repeat adding the same css --- .../java/org/jabref/gui/util/ThemeLoader.java | 16 +++++++++++----- .../jabref/preferences/JabRefPreferences.java | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/util/ThemeLoader.java b/src/main/java/org/jabref/gui/util/ThemeLoader.java index 7a7004d3445..15cc23d0f45 100644 --- a/src/main/java/org/jabref/gui/util/ThemeLoader.java +++ b/src/main/java/org/jabref/gui/util/ThemeLoader.java @@ -36,7 +36,8 @@ */ public class ThemeLoader { - private static final String DEFAULT_PATH_MAIN_CSS = JabRefFrame.class.getResource("Base.css").toExternalForm(); + public static final String DEFAULT_MAIN_CSS = "Base.css"; + private static final String DEFAULT_PATH_MAIN_CSS = JabRefFrame.class.getResource(DEFAULT_MAIN_CSS).toExternalForm(); private static final Logger LOGGER = LoggerFactory.getLogger(ThemeLoader.class); private String cssProperty = System.getProperty("jabref.theme.css"); private final FileUpdateMonitor fileUpdateMonitor; @@ -57,25 +58,31 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef } } + /** * Installs the base css file as a stylesheet in the given scene. * Changes in the css file lead to a redraw of the scene using the new css file. */ public void installBaseCss(Scene scene, JabRefPreferences preferences) { - addAndWatchForChanges(scene, DEFAULT_PATH_MAIN_CSS, 0); - if (StringUtil.isNotBlank(cssProperty)) { final Path path = Paths.get(cssProperty); if (Files.isReadable(path)) { String cssUrl = path.toUri().toString(); - addAndWatchForChanges(scene, cssUrl, 1); + addAndWatchForChanges(scene, cssUrl, 0); + }else{ + LOGGER.warn(path.toAbsolutePath() + " is not readable"); } + }else{ + addAndWatchForChanges(scene, DEFAULT_PATH_MAIN_CSS, 0); } preferences.getFontSize().ifPresent(size -> scene.getRoot().setStyle("-fx-font-size: " + size + "pt;")); } private void addAndWatchForChanges(Scene scene, String cssUrl, int index) { + // avoid repeat add + if (scene.getStylesheets().contains(cssUrl)) return; + scene.getStylesheets().add(index, cssUrl); try { @@ -86,7 +93,6 @@ private void addAndWatchForChanges(Scene scene, String cssUrl, int index) { LOGGER.info("Enabling live reloading of " + cssFile); fileUpdateMonitor.addListenerForFile(cssFile, () -> { LOGGER.info("Reload css file " + cssFile); - DefaultTaskExecutor.runInJavaFXThread(() -> { scene.getStylesheets().remove(cssUrl); scene.getStylesheets().add(index, cssUrl); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 80298994fcc..79d0afc5a5f 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -51,6 +51,7 @@ import org.jabref.gui.maintable.ColumnPreferences; import org.jabref.gui.maintable.MainTablePreferences; import org.jabref.gui.preferences.ImportSettingsTab; +import org.jabref.gui.util.ThemeLoader; import org.jabref.logic.bibtex.FieldContentParserPreferences; import org.jabref.logic.bibtex.LatexFieldFormatterPreferences; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; @@ -781,7 +782,7 @@ private JabRefPreferences() { + "__NEWLINE__

"); // set default theme - defaults.put(JabRefPreferences.FX_THEME, "Base.css"); + defaults.put(JabRefPreferences.FX_THEME, ThemeLoader.DEFAULT_MAIN_CSS); setLanguageDependentDefaultValues(); } From d875b9d36cbbc282bdc4f95efa5557eb628505ac Mon Sep 17 00:00:00 2001 From: Fancy Z Date: Fri, 26 Oct 2018 00:29:15 +0800 Subject: [PATCH 3/3] fix code style --- src/main/java/org/jabref/gui/util/ThemeLoader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/util/ThemeLoader.java b/src/main/java/org/jabref/gui/util/ThemeLoader.java index 15cc23d0f45..e9d9a7b40e8 100644 --- a/src/main/java/org/jabref/gui/util/ThemeLoader.java +++ b/src/main/java/org/jabref/gui/util/ThemeLoader.java @@ -69,10 +69,10 @@ public void installBaseCss(Scene scene, JabRefPreferences preferences) { if (Files.isReadable(path)) { String cssUrl = path.toUri().toString(); addAndWatchForChanges(scene, cssUrl, 0); - }else{ + } else { LOGGER.warn(path.toAbsolutePath() + " is not readable"); } - }else{ + } else { addAndWatchForChanges(scene, DEFAULT_PATH_MAIN_CSS, 0); }