Class IconLoader
java.lang.Object
com.github.weisj.darklaf.properties.icons.IconLoader
- All Implemented Interfaces:
IconResolver
Default implementation of
IconResolver, which provides some additional convenience
methods for loading svg icons.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionintReturns the current size of the cache.voidClears the icon cache.static @NotNull IconcreateDerivedIcon(@NotNull Icon icon, int w, int h) Create an derived version of the icon with the given width and height.static ImagecreateFrameIcon(@Nullable Icon icon, Window window) @NotNull UIAwareIconcreateUIAwareIcon(IconSupplier<Icon> lightIconSupplier, IconSupplier<Icon> darkIconSupplier) Creates a newUIAwareIconwhich is loaded lazily through the given supplier.@NotNull UIAwareIconcreateUIAwareIcon(Icon light, Icon dark) Creates a newUIAwareIconfrom the given icon.static @NotNull IconLoaderget()Get the default icon loader which resolves resources from the root directory of the jar.static @NotNull IconLoaderGet an icon loader which resolves resources from the class directory of the parent class.static AwareIconStyleGet the current aware icon style.@NotNull IconGet an icon at the specified location.@NotNull IconGet an icon at the specified location.@NotNull IconGet an icon at the specified location.@NotNull IconGet an icon at the specified location.static ObjectGet the object associated to the current theme.@NotNull DarkUIAwareIcongetUIAwareIcon(@NotNull String path) Get an aware icon.@NotNull DarkUIAwareIcongetUIAwareIcon(@NotNull String path, int w, int h) Get an aware icon.booleanReturns whether the cache is currently empty.booleanReturns whether icons are cached when creating them.@NotNull IconloadSVGIcon(@NotNull String path, boolean themed) Get an svg icon at the specified location.@NotNull IconloadSVGIcon(@NotNull String path, int w, int h, boolean themed) Get an svg icon at the specified location.@NotNull IconloadSVGIcon(@NotNull String path, int w, int h, boolean themed, Map<Object, Object> propertyMap) Get an svg icon at the specified location.static voidReload all created frame icons if necessary.voidsetCacheEnabled(boolean cacheEnabled) Sets whether icons should be cached orstatic voidupdateAwareStyle(AwareIconStyle style) Updates the style of aware icons.static voidupdateThemeStatus(Object theme) Updates the object associated with the current theme.
-
Method Details
-
cacheSize
public int cacheSize()Returns the current size of the cache.- Returns:
- the size of the cache.
-
isCacheEmpty
public boolean isCacheEmpty()Returns whether the cache is currently empty.- Returns:
- true if the cache is empty.
-
get
Get the default icon loader which resolves resources from the root directory of the jar.- Returns:
- the default icon loader.
-
get
Get an icon loader which resolves resources from the class directory of the parent class.- Returns:
- the default icon loader.
-
setCacheEnabled
public void setCacheEnabled(boolean cacheEnabled) Sets whether icons should be cached or- Parameters:
cacheEnabled- true if caching is enabled.
-
clearCache
public void clearCache()Clears the icon cache. -
isCacheEnabled
public boolean isCacheEnabled()Returns whether icons are cached when creating them.- Returns:
- true if caching is enabled.
-
updateAwareStyle
Updates the style of aware icons. Changing it will force aware icons to change their appearance accordingly.- Parameters:
style- the new style.
-
updateThemeStatus
Updates the object associated with the current theme. Changing it will force themed icons to refresh their colors. This doesn't need to be any specific type as it is simply a marker object.- Parameters:
theme- the new theme object.
-
reloadFrameIcons
public static void reloadFrameIcons()Reload all created frame icons if necessary. -
getAwareStyle
Get the current aware icon style.- Returns:
- the aware icon style.
-
getThemeStatus
Get the object associated to the current theme. This may not be any specific type as it is simply a marker object.- Returns:
- the current theme object.
-
getUIAwareIcon
Get an aware icon. If [path] is the search root of the current icon loader then the icon resource will be resolved to [path]/dark/[icon_path] and [path]/light/[icon_path] Uses 16x16 icons by default.- Specified by:
getUIAwareIconin interfaceIconResolver- Parameters:
path- the path to the icon resource described as above.- Returns:
- the icon.
-
getUIAwareIcon
@NotNull public @NotNull DarkUIAwareIcon getUIAwareIcon(@NotNull @NotNull String path, int w, int h) Get an aware icon. If [path] is the search root of the current icon loader then the icon resource will be resolved to [path]/dark/[icon_path] and [path]/light/[icon_path]- Specified by:
getUIAwareIconin interfaceIconResolver- Parameters:
path- the path to the icon resource described as above.w- the icon width.h- the icon height.- Returns:
- the icon.
-
createUIAwareIcon
@NotNull public @NotNull UIAwareIcon createUIAwareIcon(IconSupplier<Icon> lightIconSupplier, IconSupplier<Icon> darkIconSupplier) Creates a newUIAwareIconwhich is loaded lazily through the given supplier.- Parameters:
lightIconSupplier- the supplier for the light icon.darkIconSupplier- the supplier for the dark icon.- Returns:
- the
UIAwareIcon
-
createUIAwareIcon
Creates a newUIAwareIconfrom the given icon.- Parameters:
light- the light version of the icon.dark- the dark version of the icon.- Returns:
- the
UIAwareIcon.
-
getIcon
Get an icon at the specified location. The icon type is deduced from the file name. i.e. "folder/icon.svg" will be loaded as an svg.icon. Uses 16x16 icons by default.- Specified by:
getIconin interfaceIconResolver- Parameters:
path- the path to the icon with respect to the IconLoader resource root.- Returns:
- the icon.
- See Also:
-
getIcon
Get an icon at the specified location. The icon type is deduced from the file name. i.e. "folder/icon.svg" will be loaded as an svg.icon. Uses 16x16 icons by default.- Specified by:
getIconin interfaceIconResolver- Parameters:
path- the path to the icon with respect to the IconLoader resource root.themed- determines whether the icon is themed. This only has an effect on svg icons.- Returns:
- the icon.
- See Also:
-
getIcon
Get an icon at the specified location. The icon type is deduced from the file name. i.e. "folder/icon.svg" will be loaded as an svg.icon.- Specified by:
getIconin interfaceIconResolver- Parameters:
path- the path to the icon with respect to the IconLoader resource root.w- the icon width.h- the icon height.- Returns:
- the icon.
- See Also:
-
getIcon
Get an icon at the specified location. The icon type is deduced from the file name. i.e. "folder/icon.svg" will be loaded as an svg.icon.- Specified by:
getIconin interfaceIconResolver- Parameters:
path- the path to the icon with respect to the IconLoader resource root.w- the icon width.h- the icon height.themed- determines whether the icon is themed. This only has an effect on svg icons.- Returns:
- the icon.
- See Also:
-
loadSVGIcon
Get an svg icon at the specified location. will be loaded as an svg.icon. Uses 16x16 icons by default.- Parameters:
path- the path to the icon with respect to the IconLoader resource root.themed- determines whether the icon is themed. This only has an effect on svg icons.- Returns:
- the icon.
- See Also:
-
loadSVGIcon
@NotNull public @NotNull Icon loadSVGIcon(@NotNull @NotNull String path, int w, int h, boolean themed) Get an svg icon at the specified location. will be loaded as an svg.icon.- Parameters:
path- the path to the icon with respect to the IconLoader resource root.w- the icon width.h- the icon height.themed- determines whether the icon is themed. This only has an effect on svg icons.- Returns:
- the icon.
- See Also:
-
loadSVGIcon
@NotNull public @NotNull Icon loadSVGIcon(@NotNull @NotNull String path, int w, int h, boolean themed, Map<Object, Object> propertyMap) Get an svg icon at the specified location. will be loaded as an svg.icon.- Parameters:
path- the path to the icon with respect to the IconLoader resource root.w- the icon width.h- the icon height.themed- determines whether the icon is themed. This only has an effect on svg icons.propertyMap- the property map for resolving themed icon properties. If null the UIDefaults will be used.- Returns:
- the icon.
- See Also:
-
createFrameIcon
@Contract("null,_ -> null") public static Image createFrameIcon(@Nullable @Nullable Icon icon, Window window) Create anImagefrom anIconsuitable for a window icon. If the window is moved to a screen with a different scaling factor or the theme changes the icon automatically gets updated.- Parameters:
icon- the icon.window- the window.- Returns:
- the converted
Image.
-
createDerivedIcon
Create an derived version of the icon with the given width and height. This method will return the best possible result if the given icon implementsDerivableIconorImageSource.- Parameters:
icon- the icon to drive.w- the new width.h- the new height.- Returns:
- the derived icon.
-