Class Theme
- java.lang.Object
-
- com.github.weisj.darklaf.theme.Theme
-
- All Implemented Interfaces:
Serializable,Comparable<Theme>,Comparator<Theme>
- Direct Known Subclasses:
DarculaTheme,HighContrastDarkTheme,HighContrastLightTheme,IntelliJTheme,OneDarkTheme,SolarizedDarkTheme,SolarizedLightTheme,ThemeDelegate
public abstract class Theme extends Object implements Comparable<Theme>, Comparator<Theme>, Serializable
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Theme()Theme(FontSizeRule fontSizeRule, AccentColorRule accentColorRule)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanappearsEqualTo(Theme theme)Returns whether the appearance of the given theme is equal to the appearance if [this].static ThemebaseThemeOf(Theme theme)intcompare(Theme o1, Theme o2)intcompareTo(Theme o)Themecopy()Creates a copy of this theme.voidcustomizeGlobals(Properties properties, UIDefaults currentDefaults)Customize the global values.voidcustomizeIconTheme(Properties properties, UIDefaults currentDefaults)Customize the icon defaults.voidcustomizePlatformProperties(Properties properties, UIDefaults currentDefaults)Customize the platform defaults.voidcustomizeUIProperties(Properties properties, UIDefaults currentDefaults)Customize the ui defaults.Themederive(FontSizeRule fontSizeRule, AccentColorRule accentColorRule)Create a derived theme with the givenFontSizeRuleandAccentColorRule.booleanequals(Object o)AccentColorRulegetAccentColorRule()Get the accent color rule.abstract ColorToneRulegetColorToneRule()Returns the style rule for this theme.ContrastRulegetContrastRule()Returns contrast rule for the theme.StringgetDisplayName()Get the display name of this theme.FontSizeRulegetFontSizeRule()Get the font size rule for this theme.protected abstract Class<? extends Theme>getLoaderClass()The class used to determine the runtime location of resources.abstract StringgetName()Get the name of this theme.abstract StringgetPrefix()Get the prefix for resource loading.protected abstract PresetIconRulegetPresetIconRule()The preset icon theme.protected StringgetPropertyFilePath(String name)Get the path for the file [prefix]_[name].properties in the themes resource location.protected StringgetResourcePath()The path to the resource location relative to the classpath ofgetLoaderClass().Class<? extends Theme>getThemeClass()inthashCode()static booleanisDark(Theme theme)Returns whether the theme is a dark theme.static booleanisHighContrast(Theme theme)Returns whether the theme is a high contrast theme.protected Propertiesload(String name)Load a .properties file usinggetLoaderClass()} to resolve the file path.PropertiesloadAccentProperties()Load the properties specifying how to map the colors from theAccentColorRuleare mapped to the properties.protected voidloadCustomProperties(String propertySuffix, Properties properties, UIDefaults currentDefaults)Load custom properties that are located undergetResourcePath(), with the namegetPrefix()_{propertySuffix}.propertiesvoidloadDefaults(Properties properties, UIDefaults currentDefaults)Load the theme defaults.voidloadIconTheme(Properties properties, UIDefaults currentDefaults)Load the general properties file for the icon themes.PropertiesloadPropertyFile(String name)Load the theme property file with the specified name.PropertiesloadPropertyFile(String name, boolean silent)Load the theme property file with the specified name.StyleSheetloadStyleSheet()Load the css style sheet used for html display in text components with aHTMLEditorKit.protected PropertiesloadWithClass(String name, Class<?> loaderClass)Load a .properties file.booleansupportsCustomAccentColor()Returns whether this theme supports custom accent colors.booleansupportsCustomSelectionColor()Returns whether this theme supports custom selection colors.StringtoString()booleanuseCustomDecorations()Returns whether this theme should use custom decorations if available.ThemewithDisplayName(String newName)Create a derived theme with the given display name.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
Theme
public Theme()
-
Theme
public Theme(FontSizeRule fontSizeRule, AccentColorRule accentColorRule)
-
-
Method Detail
-
withDisplayName
public Theme withDisplayName(String newName)
Create a derived theme with the given display name.- Parameters:
newName- the new display name.- Returns:
- the derived theme.
-
derive
public Theme derive(FontSizeRule fontSizeRule, AccentColorRule accentColorRule)
Create a derived theme with the givenFontSizeRuleandAccentColorRule.- Parameters:
fontSizeRule- the font size rule.accentColorRule- the accent color rule.- Returns:
- the derived theme.
-
copy
public Theme copy()
Creates a copy of this theme. This is not equivalent toObject.clone()in the sense thatclone().getClass() == this.getClass()andcopy().getClass() != this.getClass(). Nonetheless the copy theme behaves exactly the same as the original.- Returns:
- a copy of the theme.
-
isDark
public static boolean isDark(Theme theme)
Returns whether the theme is a dark theme. This is used to determine the default mode for [aware] icons.- Parameters:
theme- the theme.- Returns:
- true if dark.
-
isHighContrast
public static boolean isHighContrast(Theme theme)
Returns whether the theme is a high contrast theme.- Parameters:
theme- the theme.- Returns:
- true if the theme is a high contrast theme.
-
loadDefaults
public void loadDefaults(Properties properties, UIDefaults currentDefaults)
Load the theme defaults.Note: When overwriting a theme you also have overwrite
getLoaderClass()to return the class of the theme you are overwriting. In this case you should useloadWithClass(String, Class)instead ofload(String).- Parameters:
properties- the properties to load the values into.currentDefaults- the current ui defaults.
-
customizeGlobals
public void customizeGlobals(Properties properties, UIDefaults currentDefaults)
Customize the global values.Note: When overwriting a theme you also have overwrite
getLoaderClass()to return the class of the theme you are overwriting. In this case you should useloadWithClass(String, Class)instead ofload(String).- Parameters:
properties- the properties to load the values into.currentDefaults- the current ui defaults.
-
customizeIconTheme
public void customizeIconTheme(Properties properties, UIDefaults currentDefaults)
Customize the icon defaults.Note: When overwriting a theme you also have overwrite
getLoaderClass()to return the class of the theme you are overwriting. In this case you should useloadWithClass(String, Class)instead ofload(String).- Parameters:
properties- the properties to load the value into.currentDefaults- the current ui defaults.
-
loadIconTheme
public void loadIconTheme(Properties properties, UIDefaults currentDefaults)
Load the general properties file for the icon themes.Note: When overwriting a theme you also have overwrite
getLoaderClass()to return the class of the theme you are overwriting. In this case you should useloadWithClass(String, Class)instead ofload(String).- Parameters:
properties- the properties to load the value into.currentDefaults- the current ui defaults.
-
customizePlatformProperties
public void customizePlatformProperties(Properties properties, UIDefaults currentDefaults)
Customize the platform defaults.Note: When overwriting a theme you should use
loadWithClass(String, Class)instead ofload(String).- Parameters:
properties- the properties to load the values into.currentDefaults- the current ui defaults.
-
customizeUIProperties
public void customizeUIProperties(Properties properties, UIDefaults currentDefaults)
Customize the ui defaults.Note: When overwriting a theme you should use
loadWithClass(String, Class)instead ofload(String).- Parameters:
properties- the properties to load the values into.currentDefaults- the current ui defaults.
-
getPresetIconRule
protected abstract PresetIconRule getPresetIconRule()
The preset icon theme.- Returns:
- the icon theme.
-
loadCustomProperties
protected final void loadCustomProperties(String propertySuffix, Properties properties, UIDefaults currentDefaults)
Load custom properties that are located undergetResourcePath(), with the namegetPrefix()_{propertySuffix}.propertiesNote: When overwriting a theme you should use
loadWithClass(String, Class)instead ofload(String).- Parameters:
propertySuffix- the property suffix.properties- the properties to load into.currentDefaults- the current ui defaults.
-
loadAccentProperties
public Properties loadAccentProperties()
Load the properties specifying how to map the colors from theAccentColorRuleare mapped to the properties.- Returns:
- the properties providing the mapping rules.
-
load
protected final Properties load(String name)
Load a .properties file usinggetLoaderClass()} to resolve the file path.Note: When overwriting a theme you should use
loadWithClass(String, Class)instead.- Parameters:
name- the properties file to load.- Returns:
- the properties.
-
loadWithClass
protected final Properties loadWithClass(String name, Class<?> loaderClass)
Load a .properties file.- Parameters:
name- the properties file to load.loaderClass- the class to resolve the file location from.- Returns:
- the properties.
-
loadStyleSheet
public StyleSheet loadStyleSheet()
Load the css style sheet used for html display in text components with aHTMLEditorKit.- Returns:
- the
StyleSheet.
-
getResourcePath
protected String getResourcePath()
The path to the resource location relative to the classpath ofgetLoaderClass().- Returns:
- the relative resource path
-
getPrefix
public abstract String getPrefix()
Get the prefix for resource loading.- Returns:
- the prefix for loading resources.
-
getName
public abstract String getName()
Get the name of this theme.- Returns:
- the name of the theme.
-
getDisplayName
public String getDisplayName()
Get the display name of this theme.- Returns:
- the display name of the theme.
-
getLoaderClass
protected abstract Class<? extends Theme> getLoaderClass()
The class used to determine the runtime location of resources. It is advised to explicitly return the class instead of usingObject.getClass()to protect against extending the theme.- Returns:
- the loader class.
-
getPropertyFilePath
protected String getPropertyFilePath(String name)
Get the path for the file [prefix]_[name].properties in the themes resource location.- Parameters:
name- the of the file.- Returns:
- the path relative to the location of
getLoaderClass().
-
loadPropertyFile
public final Properties loadPropertyFile(String name)
Load the theme property file with the specified name. The name gets resolved to the resource location of the theme adds the theme property prefix and appends ".properties" e.g. "test" -> [resource_location]/[prefix_of_theme]_test.properties.- Parameters:
name- the properties name.- Returns:
- the properties.
-
loadPropertyFile
public final Properties loadPropertyFile(String name, boolean silent)
Load the theme property file with the specified name. The name gets resolved to the resource location of the theme adds the theme property prefix and appends ".properties" e.g. "test" -> [resource_location]/[prefix_of_theme]_test.properties.- Parameters:
name- the properties name.silent- if true no warnings are issues if the file is not present. Instead, an empty property instance is returned.- Returns:
- the properties.
-
useCustomDecorations
public boolean useCustomDecorations()
Returns whether this theme should use custom decorations if available.- Returns:
- true if decoration should be used.
-
supportsCustomAccentColor
public boolean supportsCustomAccentColor()
Returns whether this theme supports custom accent colors.- Returns:
- true if supported.
-
supportsCustomSelectionColor
public boolean supportsCustomSelectionColor()
Returns whether this theme supports custom selection colors.- Returns:
- true if supported.
-
getColorToneRule
public abstract ColorToneRule getColorToneRule()
Returns the style rule for this theme.- Returns:
- the style rule.
-
getContrastRule
public ContrastRule getContrastRule()
Returns contrast rule for the theme.- Returns:
- the contrast rule.
-
getFontSizeRule
public FontSizeRule getFontSizeRule()
Get the font size rule for this theme.- Returns:
- the font size rule.
-
getAccentColorRule
public AccentColorRule getAccentColorRule()
Get the accent color rule.- Returns:
- the accent color rule.
-
compareTo
public int compareTo(Theme o)
- Specified by:
compareToin interfaceComparable<Theme>
-
compare
public int compare(Theme o1, Theme o2)
- Specified by:
comparein interfaceComparator<Theme>
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceComparator<Theme>- Overrides:
equalsin classObject
-
appearsEqualTo
public boolean appearsEqualTo(Theme theme)
Returns whether the appearance of the given theme is equal to the appearance if [this].- Parameters:
theme- the other theme.- Returns:
- true if they appear equal.
-
-