Verified Owner
Top Description Fields Constructors Methods
org.jabref.gui.theme

public Class ThemeManager

extends Object
Class Inheritance
Annotations
@NullMarked
Imports
java.io.IOException, java.nio.file.Path, java.util.ArrayList, .List, .Map, .Objects, .Optional, javafx.application.ColorScheme, .Platform, javafx.beans.value.ChangeListener, javafx.collections.ListChangeListener, javafx.scene.Node, .Scene, javafx.stage.Window, org.jabref.gui.WorkspacePreferences, org.jabref.gui.icon.IconTheme, org.jabref.gui.util.BindingsHelper, .UiTaskExecutor, org.jabref.logic.l10n.Localization, org.jabref.model.util.FileUpdateListener, .FileUpdateMonitor, com.google.common.annotations.VisibleForTesting, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Installs and manages style files and provides live reloading. JabRef provides themes and the ability to add a custom stylesheet on top.

For a custom stylesheet, we will protect against removal of the CSS file, degrading as gracefully as possible: the stylesheet is embedded as a data: URL, so scenes keep their theme if the file becomes unavailable while the application is running. Large style sheets are not URL-encoded to protect memory usage (see StyleSheetFile#MAX_IN_MEMORY_CSS_LENGTH).

See Also
Custom themes in the JabRef documentation.

Field Summary

Modifier and TypeField and Description
private final FileUpdateListener
private ThemeColorScheme
private @Nullable FileUpdateListener
private @Nullable StyleSheet
public static Map<String, Node>
private final FileUpdateMonitor
private static final String
private final Object
fontSizeFollowsRootKey

Marks a scene whose root this manager already follows for the font size.

public static final StyleSheet
private static final Logger
private @Nullable FileUpdateListener
private final ChangeListener<Scene>
private ThemePreset
private @Nullable FileUpdateListener
private final WorkspacePreferences

Constructor Summary

AccessConstructor and Description
public
ThemeManager(WorkspacePreferences workspacePreferences, FileUpdateMonitor fileUpdateMonitor)

Method Summary

Modifier and TypeMethod and Description
private void
addStylesheetToWatchlist(StyleSheet styleSheet, FileUpdateListener updateMethod)

Adds a stylesheet to the live-reload watch list only when it has a real filesystem path.

private void
private void
pack-priv @Nullable StyleSheet
getCustomTheme()

Returns: the currently active custom theme

private void
private void
private void
private void
private void
private void
private void
public void
updateCssOnScene(Scene scene)

Installs the CSS on the given scene.

private void
private void
private void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseCssLiveUpdateback to summary
private final FileUpdateListener baseCssLiveUpdate
colorSchemeback to summary
private ThemeColorScheme colorScheme
customCssLiveUpdateback to summary
private @Nullable FileUpdateListener customCssLiveUpdate
customThemeback to summary
private @Nullable StyleSheet customTheme
downloadIconTitleMapback to summary
public static Map<String, Node> downloadIconTitleMap
fileUpdateMonitorback to summary
private final FileUpdateMonitor fileUpdateMonitor
FONT_SIZE_STYLE_CLASS_PREFIXback to summary
private static final String FONT_SIZE_STYLE_CLASS_PREFIX
fontSizeFollowsRootKeyback to summary
private final Object fontSizeFollowsRootKey

Marks a scene whose root this manager already follows for the font size. A window re-enters Window#getWindows() every time it is shown again, and the scene it brings is the same one.

JABREF_BASE_STYLE_SHEETback to summary
public static final StyleSheet JABREF_BASE_STYLE_SHEET
LOGGERback to summary
private static final Logger LOGGER
parentCssLiveUpdateback to summary
private @Nullable FileUpdateListener parentCssLiveUpdate
sceneChangeListenerback to summary
private final ChangeListener<Scene> sceneChangeListener
themeback to summary
private ThemePreset theme
themeCssLiveUpdateback to summary
private @Nullable FileUpdateListener themeCssLiveUpdate
workspacePreferencesback to summary
private final WorkspacePreferences workspacePreferences

Constructor Detail

ThemeManagerback to summary
public ThemeManager(WorkspacePreferences workspacePreferences, FileUpdateMonitor fileUpdateMonitor)

Method Detail

addStylesheetToWatchlistback to summary
private void addStylesheetToWatchlist(StyleSheet styleSheet, FileUpdateListener updateMethod)

Adds a stylesheet to the live-reload watch list only when it has a real filesystem path.

Classpath resources cannot be watched.

addThemeStylesheetToWatchlistback to summary
private void addThemeStylesheetToWatchlist(ThemePreset theme)
cssLiveUpdateback to summary
private void cssLiveUpdate(StyleSheet styleSheet)
getCustomThemeback to summary
pack-priv @Nullable StyleSheet getCustomTheme()
Returns:@Nullable StyleSheet

the currently active custom theme

Annotations
@VisibleForTesting
initializeWindowThemeUpdaterback to summary
private void initializeWindowThemeUpdater()
registerSceneback to summary
private void registerScene(Scene scene)
removeStylesheetFromWatchListback to summary
private void removeStylesheetFromWatchList(StyleSheet styleSheet, FileUpdateListener updateMethod)
removeThemeStylesheetsFromWatchListback to summary
private void removeThemeStylesheetsFromWatchList(ThemePreset theme)
updateColorSchemeOnAllScenesback to summary
private void updateColorSchemeOnAllScenes()
updateColorSchemeOnSceneback to summary
private void updateColorSchemeOnScene(Scene scene)
updateCssOnAllScenesback to summary
private void updateCssOnAllScenes()
updateCssOnSceneback to summary
public void updateCssOnScene(Scene scene)

Installs the CSS on the given scene.

The theme stylesheet comes first, the user's custom stylesheet on top of it, and the base stylesheet last -- the base sheet only maps JabRef's own selectors onto the color tokens the theme defines, so it has to win over both. A theme with a parent declares only the tokens it changes, so the parent's stylesheet goes beneath it to supply the rest.

updateFontOnAllScenesback to summary
private void updateFontOnAllScenes()
updateFontSettingsback to summary
private void updateFontSettings()
updateFontStyleForSceneback to summary
private void updateFontStyleForScene(Scene scene)
updateThemeSettingsback to summary
private void updateThemeSettings()