Browse Source

Expose method to compute an effective PreferredThemeStyle adhering to the current ThemeSettings

pull/323/head
Jannis Weis 2 years ago
parent
commit
27972b9bc5
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 14
      core/src/main/java/com/github/weisj/darklaf/settings/SettingsConfiguration.java
  2. 11
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java

14
core/src/main/java/com/github/weisj/darklaf/settings/SettingsConfiguration.java

@ -73,6 +73,16 @@ public class SettingsConfiguration implements Serializable {
return baseTheme.derive(fontSizeRule, getFontPrototype(), accentColorRule); return baseTheme.derive(fontSizeRule, getFontPrototype(), accentColorRule);
} }
public final PreferredThemeStyle getEffectiveThemeStyle(final PreferredThemeStyle themeStyle) {
Theme baseTheme = getEffectiveBaseTheme(themeStyle);
FontSizeRule fontSizeRule = getEffectiveFontSizeRule(themeStyle);
AccentColorRule accentColorRule = getEffectiveAccentColorRule(baseTheme, themeStyle);
return new PreferredThemeStyle(themeStyle.getContrastRule(), themeStyle.getColorToneRule(),
accentColorRule, fontSizeRule);
}
private AccentColorRule getEffectiveAccentColorRule(final Theme baseTheme, private AccentColorRule getEffectiveAccentColorRule(final Theme baseTheme,
final PreferredThemeStyle preferredThemeStyle) { final PreferredThemeStyle preferredThemeStyle) {
AccentColorRule accentColorRule = getAccentColorRule(); AccentColorRule accentColorRule = getAccentColorRule();
@ -81,10 +91,10 @@ public class SettingsConfiguration implements Serializable {
AccentColorRule systemAccentColorRule = preferredThemeStyle.getAccentColorRule(); AccentColorRule systemAccentColorRule = preferredThemeStyle.getAccentColorRule();
Color accentColor = accentColorRule.getAccentColor(); Color accentColor = accentColorRule.getAccentColor();
Color selectionColor = accentColorRule.getSelectionColor(); Color selectionColor = accentColorRule.getSelectionColor();
if (isAccentColorFollowsSystem() && baseTheme.supportsCustomAccentColor()) { if (isAccentColorFollowsSystem() && (baseTheme == null || baseTheme.supportsCustomAccentColor())) {
accentColor = systemAccentColorRule.getAccentColor(); accentColor = systemAccentColorRule.getAccentColor();
} }
if (isSelectionColorFollowsSystem() && baseTheme.supportsCustomSelectionColor()) { if (isSelectionColorFollowsSystem() && (baseTheme == null || baseTheme.supportsCustomSelectionColor())) {
selectionColor = systemAccentColorRule.getSelectionColor(); selectionColor = systemAccentColorRule.getSelectionColor();
} }

11
core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java

@ -38,6 +38,7 @@ import com.github.weisj.darklaf.theme.event.ThemePreferenceListener;
import com.github.weisj.darklaf.theme.spec.AccentColorRule; import com.github.weisj.darklaf.theme.spec.AccentColorRule;
import com.github.weisj.darklaf.theme.spec.FontPrototype; import com.github.weisj.darklaf.theme.spec.FontPrototype;
import com.github.weisj.darklaf.theme.spec.FontSizeRule; import com.github.weisj.darklaf.theme.spec.FontSizeRule;
import com.github.weisj.darklaf.theme.spec.PreferredThemeStyle;
import com.github.weisj.darklaf.ui.util.DarkUIUtil; import com.github.weisj.darklaf.ui.util.DarkUIUtil;
import com.github.weisj.darklaf.ui.util.UIThread; import com.github.weisj.darklaf.ui.util.UIThread;
import com.github.weisj.darklaf.util.LazyValue; import com.github.weisj.darklaf.util.LazyValue;
@ -496,6 +497,16 @@ public class ThemeSettings implements ThemePreferenceListener {
applyTheme(currentConfiguration.getEffectiveTheme()); applyTheme(currentConfiguration.getEffectiveTheme());
} }
/**
* Compute the effective preferred theme style adhering to the current ThemeSettings
*
* @param style the preferred theme style prototype
* @return the effective preferred theme style
*/
public PreferredThemeStyle computeEffectiveStyle(final PreferredThemeStyle style) {
return currentConfiguration.getEffectiveThemeStyle(style);
}
/** /**
* Revert the settings to the last time they have been saved. * Revert the settings to the last time they have been saved.
* *

Loading…
Cancel
Save