Class IconUtils

java.lang.Object
org.pepsoft.util.IconUtils

@NonNls public final class IconUtils extends Object
Utility methods for loading and scaling images and icons, with automatic support for HiDPI displays.
  • Method Details

    • getTheme

      public static String getTheme()
    • setTheme

      public static void setTheme(String theme)
    • loadUnscaledIcon

      public static ImageIcon loadUnscaledIcon(String path)
      Load an icon from the classpath using the system class loader.

      The icon will not be scaled.

      Parameters:
      path - The path of the image to load.
      Returns:
      The specified icon, or null if the specified path did not contain a resource.
    • loadScaledIcon

      public static ImageIcon loadScaledIcon(String path)
      Load an icon from the classpath using the system class loader.

      The icon will automatically be scaled up for HiDPI displays.

      Parameters:
      path - The path of the image to load.
      Returns:
      The specified icon, or null if the specified path did not contain a resource.
    • loadScaledIcon

      public static ImageIcon loadScaledIcon(ClassLoader classLoader, String path)
      Load an icon from the classpath using a specific class loader.

      The icon will automatically be scaled up for HiDPI displays.

      Parameters:
      classLoader - The class loader to use to load the image.
      path - The path of the image to load.
      Returns:
      The specified icon, or null if the specified path did not contain a resource.
    • loadUnscaledImage

      public static BufferedImage loadUnscaledImage(String path)
      Load an image from the classpath using the system class loader. If theme is set it will first look for a themed version of the image by looking in the _<theme> subdirectory.

      The image will be returned at its original resolution and not be rescaled.

      Parameters:
      path - The path of the image to load.
      Returns:
      The specified image, or null if the specified path did not contain a resource.
      See Also:
    • loadScaledImage

      public static BufferedImage loadScaledImage(String path)
      Load an image from the classpath using the system class loader.

      The image will automatically be scaled up for HiDPI displays.

      Parameters:
      path - The path of the image to load.
      Returns:
      The specified image, or null if the specified path did not contain a resource.
    • loadScaledImage

      public static BufferedImage loadScaledImage(ClassLoader classLoader, String path)
      Load an image from the classpath using a specific class loader. If theme is set it will first look for a themed version of the image by looking in the _<theme> subdirectory.

      The image will automatically be scaled up for HiDPI displays.

      Parameters:
      classLoader - The class loader to use to load the image.
      path - The path of the image to load.
      Returns:
      The specified image, or null if the specified path did not contain a resource.
      See Also:
    • createScaledColourIcon

      public static Icon createScaledColourIcon(int colour)
      Create a 16x16 pixel icon of a solid colour.

      The icon will automatically be scaled up for HiDPI displays.

      Parameters:
      colour - The colour as a combined rgb value.
      Returns:
      A 16x16 icon of the specified colour.
    • createScaledLetterIcon

      public static Icon createScaledLetterIcon(char letter, Color colour)
    • scaleIcon

      public static ImageIcon scaleIcon(ImageIcon icon, int size)
      Scale a square icon using bicubic scaling.

      The icon will automatically be scaled up for HiDPI displays.

      Parameters:
      icon - The icon to scale.
      size - The size (edge to edge) of the scaled icon.
      Returns:
      The scaled icon.
    • scaleIcon

      public static BufferedImage scaleIcon(Image iconImage, int size)
      Scale a square icon using bicubic scaling.

      The icon will automatically be scaled up for HiDPI displays.

      Parameters:
      iconImage - The icon to scale.
      size - The size (edge to edge) of the scaled icon.
      Returns:
      The scaled icon.
    • rotateIcon

      public static Icon rotateIcon(Icon icon, int degrees)
      Rotate a square icon clockwise by the specified number of degrees.
      Parameters:
      icon - The icon to rotate.
      degrees - The number of degrees to rotate the icon.
      Returns:
      The rotated icon.