Browse Source

Installation: Ensure installed theme is reported correctly at all time. We need to avoid to set the installed theme to eagerly as it may be requested during defaults initialisation, which would cause components to query an incorrect color.

pull/235/head
weisj 4 years ago
parent
commit
436e7c13e3
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 21
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  2. 2
      core/src/main/java/com/github/weisj/darklaf/LafInstaller.java
  3. 16
      core/src/main/java/com/github/weisj/darklaf/LafManager.java

21
core/src/main/java/com/github/weisj/darklaf/DarkLaf.java

@ -75,14 +75,15 @@ public class DarkLaf extends ThemedLookAndFeel {
private final boolean runListenerCallback;
DarkLaf(final boolean runListenerCallback) {
DarkLaf(final Theme theme, final boolean runListenerCallback) {
this.runListenerCallback = runListenerCallback;
base = getBase();
this.theme = theme;
this.base = getBase();
}
/** Create Custom Darcula LaF. */
public DarkLaf() {
this(true);
this(null, true);
}
private LookAndFeel getBase() {
@ -142,16 +143,24 @@ public class DarkLaf extends ThemedLookAndFeel {
public UIDefaults getDefaults() {
final UIDefaults defaults = base.getDefaults();
final Theme currentTheme = getTheme();
if (isInitialized && !LafManager.getTheme().equals(currentTheme)) {
LafManager.setTheme(currentTheme);
}
for (DefaultsInitTask task : INIT_TASKS) {
if (task.onlyDuringInstallation() && !isInitialized) continue;
task.run(currentTheme, defaults);
}
if (isInitialized) {
postInstall();
}
return defaults;
}
private void postInstall() {
Theme currentTheme = getTheme();
if (!LafManager.getInstalledTheme().equals(currentTheme)) {
LafManager.setInstalledTheme(currentTheme);
LafManager.setTheme(currentTheme);
}
}
@Override
public LayoutStyle getLayoutStyle() {
return base.getLayoutStyle();

2
core/src/main/java/com/github/weisj/darklaf/LafInstaller.java

@ -44,7 +44,7 @@ final class LafInstaller {
try {
LOGGER.fine(() -> "Installing theme " + theme);
LafTransition transition = LafTransition.showSnapshot();
UIManager.setLookAndFeel(new DarkLaf(false));
UIManager.setLookAndFeel(new DarkLaf(theme, false));
updateLaf();
SwingUtilities.invokeLater(transition::runTransition);
notifyThemeInstalled(theme);

16
core/src/main/java/com/github/weisj/darklaf/LafManager.java

@ -54,6 +54,7 @@ public final class LafManager {
private static final LafInstaller installer = new LafInstaller();
private static ThemeProvider themeProvider;
private static Theme theme;
private static Theme installedTheme;
private static final List<Theme> registeredThemes = new ArrayList<>();
private static final Collection<DefaultsAdjustmentTask> uiDefaultsTasks = new ArrayList<>();
private static final Collection<DefaultsInitTask> uiInitTasks = new ArrayList<>();
@ -348,11 +349,12 @@ public final class LafManager {
* @return the currently installed theme.
*/
public static Theme getInstalledTheme() {
LookAndFeel laf = UIManager.getLookAndFeel();
if (laf instanceof ThemedLookAndFeel) {
return ((ThemedLookAndFeel) laf).getTheme();
}
return getTheme();
return installedTheme != null ? installedTheme : getTheme();
}
static void setInstalledTheme(final Theme theme) {
LOGGER.info("Setting installed theme: " + theme);
installedTheme = theme;
}
/**
@ -432,7 +434,9 @@ public final class LafManager {
* {@link ThemeProvider}. This sets the current LaF and applies the given theme.
*/
public static void install() {
installer.install(getTheme());
Theme theme = getTheme();
installer.install(theme);
setInstalledTheme(theme);
}
/** Update the component ui classes for all current windows. */

Loading…
Cancel
Save