Browse Source

Fix error messages in DefaultThemeProvider constructor.

Ensure themes in DefaultThemeProvider are non-null.
Provide factory methods fro ThemeProvider.
pull/214/head
weisj 4 years ago
parent
commit
51ae12d05e
  1. 29
      theme/src/main/java/com/github/weisj/darklaf/theme/info/DefaultThemeProvider.java
  2. 9
      theme/src/main/java/com/github/weisj/darklaf/theme/info/ThemeProvider.java

29
theme/src/main/java/com/github/weisj/darklaf/theme/info/DefaultThemeProvider.java

@ -21,6 +21,8 @@
*/ */
package com.github.weisj.darklaf.theme.info; package com.github.weisj.darklaf.theme.info;
import java.util.Objects;
import com.github.weisj.darklaf.theme.*; import com.github.weisj.darklaf.theme.*;
public class DefaultThemeProvider implements ThemeProvider { public class DefaultThemeProvider implements ThemeProvider {
@ -34,8 +36,16 @@ public class DefaultThemeProvider implements ThemeProvider {
this(new IntelliJTheme(), new DarculaTheme(), new HighContrastLightTheme(), new HighContrastDarkTheme()); this(new IntelliJTheme(), new DarculaTheme(), new HighContrastLightTheme(), new HighContrastDarkTheme());
} }
public DefaultThemeProvider(final Theme lightTheme, final Theme darkTheme) {
this(lightTheme, darkTheme, new HighContrastLightTheme(), new HighContrastDarkTheme());
}
public DefaultThemeProvider(final Theme lightTheme, final Theme darkTheme, final Theme lightHighContrastTheme, public DefaultThemeProvider(final Theme lightTheme, final Theme darkTheme, final Theme lightHighContrastTheme,
final Theme darkHighContrastTheme) { final Theme darkHighContrastTheme) {
Objects.requireNonNull(lightTheme, "Light theme is null");
Objects.requireNonNull(darkTheme, "Dark theme is null");
Objects.requireNonNull(lightHighContrastTheme, "Light high contrast theme is null");
Objects.requireNonNull(darkHighContrastTheme, "Dark high contrast theme is null");
/* /*
* Ensure the given themes actually serve the purpose they are intended for. * Ensure the given themes actually serve the purpose they are intended for.
*/ */
@ -47,11 +57,11 @@ public class DefaultThemeProvider implements ThemeProvider {
"Given light high-contrast theme " + lightHighContrastTheme + " is declared as dark"); "Given light high-contrast theme " + lightHighContrastTheme + " is declared as dark");
} }
if (!Theme.isDark(darkTheme)) { if (!Theme.isDark(darkTheme)) {
throw new UnsupportedThemeException("Given dark theme " + darkTheme + "is not declared as dark"); throw new UnsupportedThemeException("Given dark theme " + darkTheme + " is not declared as dark");
} }
if (!Theme.isDark(darkHighContrastTheme)) { if (!Theme.isDark(darkHighContrastTheme)) {
throw new UnsupportedThemeException( throw new UnsupportedThemeException(
"Given dark high-contrast theme " + darkTheme + "is not declared as dark"); "Given dark high-contrast theme " + darkHighContrastTheme + "is not declared as dark");
} }
/* /*
* A high contrast theme may serve as a standard theme, but a standard theme should never be used * A high contrast theme may serve as a standard theme, but a standard theme should never be used
@ -81,4 +91,19 @@ public class DefaultThemeProvider implements ThemeProvider {
return theme.derive(themeStyle.getFontSizeRule(), themeStyle.getAccentColorRule()); return theme.derive(themeStyle.getFontSizeRule(), themeStyle.getAccentColorRule());
} }
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof DefaultThemeProvider)) return false;
DefaultThemeProvider that = (DefaultThemeProvider) o;
return lightTheme.appearsEqualTo(that.lightTheme) && darkTheme.appearsEqualTo(that.darkTheme)
&& lightHighContrastTheme.appearsEqualTo(that.lightHighContrastTheme)
&& darkHighContrastTheme.appearsEqualTo(that.darkHighContrastTheme);
}
@Override
public int hashCode() {
return Objects.hash(lightTheme, darkTheme, lightHighContrastTheme, darkHighContrastTheme);
}
} }

9
theme/src/main/java/com/github/weisj/darklaf/theme/info/ThemeProvider.java

@ -26,4 +26,13 @@ import com.github.weisj.darklaf.theme.Theme;
public interface ThemeProvider { public interface ThemeProvider {
Theme getTheme(final PreferredThemeStyle themeStyle); Theme getTheme(final PreferredThemeStyle themeStyle);
static ThemeProvider fromThemes(final Theme lightTheme, final Theme darkTheme) {
return new DefaultThemeProvider(lightTheme, darkTheme);
}
static ThemeProvider fromThemes(final Theme lightTheme, final Theme darkTheme, final Theme lightHighContrastTheme,
final Theme darkHighContrastTheme) {
return new DefaultThemeProvider(lightTheme, darkTheme, lightHighContrastTheme, darkHighContrastTheme);
}
} }

Loading…
Cancel
Save