Class DarkUIAwareIcon

java.lang.Object
com.github.weisj.darklaf.icons.DarkUIAwareIcon
All Implemented Interfaces:
DynamicIcon, UIAwareIcon, Serializable, Icon, UIResource

public class DarkUIAwareIcon extends Object implements UIAwareIcon, UIResource, Serializable
Icon that is aware of the current ui theme and adjusts the icon accordingly. Icons are loaded lazily at their point of usage.
Since:
2019
See Also:
Serialized Form
  • Field Details

    • darkKey

      protected final String darkKey
    • lightKey

      protected final String lightKey
    • w

      protected final int w
    • h

      protected final int h
    • parentClass

      protected final Class<?> parentClass
    • loaded

      protected transient boolean loaded
    • icon

      protected transient Icon icon
  • Constructor Details

    • DarkUIAwareIcon

      public DarkUIAwareIcon(String darkKey, String lightKey, int w, int h, Class<?> parentClass)
      Create new ui aware icon.
      Parameters:
      darkKey - key to load icon for dark mode.
      lightKey - key to load icon for light mode.
      w - width of icon.
      h - height of icon.
      parentClass - the class to resolve the path while lazy loading.
  • Method Details

    • paintIcon

      public void paintIcon(Component c, Graphics g2, int x, int y, double scale)
    • ensureLoaded

      protected void ensureLoaded()
    • updateStyle

      protected void updateStyle()
    • isLoaded

      protected boolean isLoaded()
    • isDark

      public boolean isDark()
    • loadIcon

      protected void loadIcon()
    • paintIcon

      public void paintIcon(Component c, Graphics g, int x, int y)
      Specified by:
      paintIcon in interface Icon
    • getIconWidth

      public int getIconWidth()
      Specified by:
      getIconWidth in interface Icon
    • getIconHeight

      public int getIconHeight()
      Specified by:
      getIconHeight in interface Icon
    • getDual

      public DarkUIAwareIcon getDual()
      Description copied from interface: UIAwareIcon
      Return the dual version of the icon. i.e. if the current icon is light then the dual version will be dark and vice versa. Implementations of this method should respect that the appearance of the icon after invoking this method twice should be the same.
      Specified by:
      getDual in interface UIAwareIcon
      Returns:
      the dual icon.