Class IconUtils

java.lang.Object
uno.anahata.asi.swing.icons.IconUtils

public class IconUtils extends Object
A utility class for loading, scaling, and managing a global registry of icons.

This class provides high-quality icon scaling by leveraging the legacy Image.SCALE_SMOOTH algorithm, which has proven to produce superior results for small UI icons compared to single-step Graphics2D scaling.

Author:
anahata
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Map<String,Icon>
    A global registry for mapping icon IDs to actual Icon objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Icon
    Creates an icon for adding items to the context by overlaying a small Anahata badge on a large blue '+' symbol.
    static Icon
    Creates a disabled (grayed out and semi-transparent) version of the given icon.
    static Icon
    getIcon(String idOrName)
    Retrieves an icon from the global registry or loads it from the classpath.
    static Icon
    getIcon(String idOrName, int size)
    Retrieves a square icon of the specified size.
    static ImageIcon
    getIcon(String name, int width, int height)
    Loads an icon from the classpath resources and scales it to the specified size.
    static List<Image>
    Gets a list of images for the Anahata logo in various sizes.
    static Icon
    Creates an icon for removing items from the context by overlaying a small Anahata badge on a large red '-' symbol.
    private static Icon
    getSymbolBaseIcon(boolean isAdd)
    Internal helper to create an icon with a symbol base and an Anahata badge.
    static void
    Registers an icon in the global registry.
    static Image
    toImage(Icon icon)
    Converts any standard Swing Icon to a java.awt.Image.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ICON_REGISTRY

      private static final Map<String,Icon> ICON_REGISTRY
      A global registry for mapping icon IDs to actual Icon objects.
  • Constructor Details

    • IconUtils

      public IconUtils()
  • Method Details

    • registerIcon

      public static void registerIcon(String id, Icon icon)
      Registers an icon in the global registry.
      Parameters:
      id - The unique identifier for the icon.
      icon - The icon object.
    • getIcon

      public static Icon getIcon(String idOrName)
      Retrieves an icon from the global registry or loads it from the classpath.
      Parameters:
      idOrName - The icon ID or the resource name (e.g., "attach.png").
      Returns:
      The Icon, or null if not found.
    • getIcon

      public static Icon getIcon(String idOrName, int size)
      Retrieves a square icon of the specified size.
      Parameters:
      idOrName - The icon ID or resource name.
      size - The desired width and height.
      Returns:
      The scaled Icon.
    • getIcon

      public static ImageIcon getIcon(String name, int width, int height)
      Loads an icon from the classpath resources and scales it to the specified size.

      Implementation details: Uses Image.getScaledInstance(int, int, int) with Image.SCALE_SMOOTH to ensure the best possible quality for small icons, matching the visual fidelity of the V1 architecture.

      Parameters:
      name - The name of the icon file.
      width - The desired width.
      height - The desired height.
      Returns:
      A scaled ImageIcon, or null if the resource is not found.
    • toImage

      public static Image toImage(Icon icon)
      Converts any standard Swing Icon to a java.awt.Image.

      Implementation details: If the icon is an instance of ImageIcon, it returns the underlying image directly. Otherwise, it creates a BufferedImage and paints the icon into it. This allows programmatic icons to be used for window icons and other native-facing APIs.

      Parameters:
      icon - The icon to convert.
      Returns:
      The resulting Image, or null if the input was null.
    • getDisabledIcon

      public static Icon getDisabledIcon(Icon icon)
      Creates a disabled (grayed out and semi-transparent) version of the given icon.
      Parameters:
      icon - The original icon.
      Returns:
      The disabled icon.
    • getLogoImages

      public static List<Image> getLogoImages()
      Gets a list of images for the Anahata logo in various sizes. This is useful for setting the window icon, allowing the OS to choose the best size.
      Returns:
      A list of logo images.
    • getAddIcon

      public static Icon getAddIcon()
      Creates an icon for adding items to the context by overlaying a small Anahata badge on a large blue '+' symbol.
      Returns:
      The 'Add to Context' icon.
    • getRemoveIcon

      public static Icon getRemoveIcon()
      Creates an icon for removing items from the context by overlaying a small Anahata badge on a large red '-' symbol.
      Returns:
      The 'Remove from Context' icon.
    • getSymbolBaseIcon

      private static Icon getSymbolBaseIcon(boolean isAdd)
      Internal helper to create an icon with a symbol base and an Anahata badge.
      Parameters:
      isAdd - True for '+', false for '-'.
      Returns:
      The combined icon.