Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4130 provide dark theme #4372

Merged
merged 17 commits into from
Oct 17, 2018
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We add auto url formatting when user paste link to URL field in entry editor. [#254](https://github.com/koppor/jabref/issues/254)
- We added a minimal height for the entry editor so that it can no longer be hidden by accident. [#4279](https://github.com/JabRef/jabref/issues/4279)
- We added a new keyboard shortcut so that the entry editor could be closed by <kbd>Ctrl<kbd> + <kbd>E<kbd>. [#4222] (https://github.com/JabRef/jabref/issues/4222)

- Change theme to dark or light via settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please formulate the changelog as the above ones and link the issue




Expand Down
36 changes: 32 additions & 4 deletions src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import javafx.scene.Node;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
Expand All @@ -16,12 +18,16 @@

class AppearancePrefsTab extends Pane implements PrefsTab {

public static final String BASE_CSS = "Base.css";
public static final String DARK_CSS = "Dark.css";
private final JabRefPreferences prefs;
private final CheckBox fontTweaksLAF;
private final TextField fontSize;
private final CheckBox overrideFonts;
private final VBox container = new VBox();
private final DialogService dialogService;
private final RadioButton lightTheme;
private final RadioButton darkTheme;

/**
* Customization of appearance parameters.
Expand All @@ -41,7 +47,18 @@ public AppearancePrefsTab(DialogService dialogService, JabRefPreferences prefs)
fontSizeContainer.disableProperty().bind(overrideFonts.selectedProperty().not());
fontTweaksLAF = new CheckBox(Localization.lang("Tweak font rendering for entry editor on Linux"));

container.getChildren().addAll(overrideFonts, fontSizeContainer, fontTweaksLAF);
ToggleGroup themeGroup = new ToggleGroup();
lightTheme = new RadioButton("Light theme");
lightTheme.setToggleGroup(themeGroup);
darkTheme = new RadioButton("Dark theme");
darkTheme.setToggleGroup(themeGroup);

if (prefs.get(JabRefPreferences.FX_THEME).equals(BASE_CSS))
lightTheme.setSelected(true);
else if (prefs.get(JabRefPreferences.FX_THEME).equals(DARK_CSS))
darkTheme.setSelected(true);

container.getChildren().addAll(overrideFonts, fontSizeContainer, fontTweaksLAF, lightTheme, darkTheme);

}

Expand All @@ -68,10 +85,21 @@ public void storeSettings() {
int newFontSize = Integer.parseInt(fontSize.getText());
prefs.putInt(JabRefPreferences.MAIN_FONT_SIZE, newFontSize);

boolean isThemeChanged = false;

if (lightTheme.isSelected() && !prefs.get(JabRefPreferences.FX_THEME).equals(BASE_CSS)) {
prefs.put(JabRefPreferences.FX_THEME, BASE_CSS);
isThemeChanged = true;
} else if (darkTheme.isSelected() && !prefs.get(JabRefPreferences.FX_THEME).equals(DARK_CSS)) {
prefs.put(JabRefPreferences.FX_THEME, DARK_CSS);
isThemeChanged = true;
}

boolean isRestartRequired =
oldFxTweakValue != fontTweaksLAF.isSelected()
|| oldOverrideDefaultFontSize != overrideFonts.isSelected()
|| oldFontSize != newFontSize;
(oldFxTweakValue != fontTweaksLAF.isSelected())
|| (oldOverrideDefaultFontSize != overrideFonts.isSelected())
|| (oldFontSize != newFontSize)
|| isThemeChanged;
if (isRestartRequired) {
dialogService.showWarningDialogAndWait(Localization.lang("Settings"),
Localization.lang("Some appearance settings you changed require to restart JabRef to come into effect."));
Expand Down
10 changes: 9 additions & 1 deletion 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.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -37,12 +38,19 @@
public class ThemeLoader {

private static final String DEFAULT_PATH_MAIN_CSS = JabRefFrame.class.getResource("Base.css").toExternalForm();
private static final String CSS_SYSTEM_PROPERTY = System.getProperty("jabref.theme.css");
private static final Logger LOGGER = LoggerFactory.getLogger(ThemeLoader.class);
private final String CSS_SYSTEM_PROPERTY;
private final FileUpdateMonitor fileUpdateMonitor;

public ThemeLoader(FileUpdateMonitor fileUpdateMonitor) {
this.fileUpdateMonitor = Objects.requireNonNull(fileUpdateMonitor);
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved

String cssFileName = JabRefPreferences.getInstance().get(JabRefPreferences.FX_THEME);
if (cssFileName != null) {
String themeName = JabRefFrame.class.getResource(cssFileName).getPath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the nio methods for accessing the resource. Have a look at the exporter tests to see how

CSS_SYSTEM_PROPERTY = new File(themeName).getAbsolutePath();
} else
CSS_SYSTEM_PROPERTY = null;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public class JabRefPreferences implements PreferencesService {
public static final String EXTERNAL_FILE_TYPES = "externalFileTypes";
public static final String FONT_FAMILY = "fontFamily";
public static final String FX_FONT_RENDERING_TWEAK = "fxFontRenderingTweak";
public static final String FX_THEME = "fxTheme";
public static final String LANGUAGE = "language";
public static final String NAMES_LAST_ONLY = "namesLastOnly";
public static final String ABBR_AUTHOR_NAMES = "abbrAuthorNames";
Expand Down Expand Up @@ -472,6 +473,7 @@ private JabRefPreferences() {
}

defaults.put(FX_FONT_RENDERING_TWEAK, OS.LINUX); //we turn this on per default on Linux
defaults.put(FX_THEME, "Base.css");
defaults.put(EMACS_ADDITIONAL_PARAMETERS, "-n -e");

defaults.put(PUSH_TO_APPLICATION, "TeXstudio");
Expand Down