Class IconLoader

java.lang.Object
com.github.weisj.darklaf.properties.icons.IconLoader
All Implemented Interfaces:
IconResolver

public final class IconLoader extends Object implements IconResolver
Default implementation of IconResolver, which provides some additional convenience methods for loading svg icons.
  • 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

      @NotNull public static @NotNull IconLoader get()
      Get the default icon loader which resolves resources from the root directory of the jar.
      Returns:
      the default icon loader.
    • get

      @NotNull public static @NotNull IconLoader get(@Nullable @Nullable Class<?> parentClass)
      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

      public static void updateAwareStyle(AwareIconStyle style)
      Updates the style of aware icons. Changing it will force aware icons to change their appearance accordingly.
      Parameters:
      style - the new style.
    • updateThemeStatus

      public static void updateThemeStatus(Object theme)
      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

      public static AwareIconStyle getAwareStyle()
      Get the current aware icon style.
      Returns:
      the aware icon style.
    • getThemeStatus

      public static Object 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

      @NotNull public @NotNull DarkUIAwareIcon getUIAwareIcon(@NotNull @NotNull String path)
      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:
      getUIAwareIcon in interface IconResolver
      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:
      getUIAwareIcon in interface IconResolver
      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 new UIAwareIcon which 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

      @NotNull public @NotNull UIAwareIcon createUIAwareIcon(Icon light, Icon dark)
      Creates a new UIAwareIcon from the given icon.
      Parameters:
      light - the light version of the icon.
      dark - the dark version of the icon.
      Returns:
      the UIAwareIcon.
    • getIcon

      @NotNull public @NotNull Icon getIcon(@NotNull @NotNull String path)
      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:
      getIcon in interface IconResolver
      Parameters:
      path - the path to the icon with respect to the IconLoader resource root.
      Returns:
      the icon.
      See Also:
    • getIcon

      @NotNull public @NotNull Icon getIcon(@NotNull @NotNull String path, boolean themed)
      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:
      getIcon in interface IconResolver
      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

      @NotNull public @NotNull Icon getIcon(@NotNull @NotNull String path, int w, int h)
      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:
      getIcon in interface IconResolver
      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

      @NotNull public @NotNull Icon getIcon(@NotNull @NotNull String path, int w, int h, boolean themed)
      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:
      getIcon in interface IconResolver
      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, boolean themed)
      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 an Image from an Icon suitable 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

      @NotNull public static @NotNull Icon createDerivedIcon(@NotNull @NotNull Icon icon, int w, int h)
      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 implements DerivableIcon or ImageSource.
      Parameters:
      icon - the icon to drive.
      w - the new width.
      h - the new height.
      Returns:
      the derived icon.