Class CachedHiDPIIcon

java.lang.Object
org.openide.util.CachedHiDPIIcon
All Implemented Interfaces:
Icon

public abstract class CachedHiDPIIcon extends Object implements Icon
Abstract base class for Icon implementations that need to cache scaled bitmap representations for HiDPI displays. Bitmaps for multiple HiDPI scaling factors can be cached at the same time, e.g. for multi-monitor setups. Thread-safe.
Since:
9.15
  • Constructor Details

    • CachedHiDPIIcon

      protected CachedHiDPIIcon(int width, int height)
      Constructor to be used by subclasses. For HiDPI screens, dimensions are specified in logical pixels rather than device pixels, as in the superclass.
      Parameters:
      width - the width of the icon
      height - the height of the icon
  • Method Details

    • paintIcon

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

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

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

      protected abstract Image createAndPaintImage(Component c, ColorModel colorModel, int deviceWidth, int deviceHeight, double scale)
      Create a scaled image containing the graphics of this icon. The result may be cached. The dimensions are specfied in device pixels rather than logical pixels, i.e. with HiDPI scaling applied.
      Parameters:
      c - the component that was passed to Icon.paintIcon(Component,Graphics,int,int). The cache will not be invalidated if c or its state changes, so subclasses should avoid depending on it if possible. This parameter exists mainly to ensure compatibility with existing Icon implementations that may be used as delegates. Future implementations might also elect to simply pass a dummy Component instance here.
      colorModel - the ColorModel of the surface on which the image will be painted (may be passed to createBufferedImage(ColorModel, int, int) in the common case)
      deviceWidth - the required width of the image, in device pixels (>=1)
      deviceHeight - the required height of the image, in device pixels (>=1)
      scale - the HiDPI scaling factor detected in graphicsConfiguration
    • createBufferedImage

      protected static final BufferedImage createBufferedImage(ColorModel colorModel, int deviceWidth, int deviceHeight)
      Utility method to create a compatible BufferedImage from the parameters passed to createAndPaintImage(Component, ColorModel, int, int, double). May be called by implementors of the latter to create a surface to draw on and return.
      Parameters:
      colorModel - the required ColorModel
      deviceWidth - the required width of the image, in device pixels (>=1)
      deviceHeight - the required height of the image, in device pixels (>=1)
      Returns:
      an image compatible with the given parameters