Class MultiResolutionImageSupport


  • public class MultiResolutionImageSupport
    extends java.lang.Object
    Support for multi-resolution images available since Java 9.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Image create​(int baseImageIndex, java.awt.Dimension[] dimensions, java.util.function.Function<java.awt.Dimension,​java.awt.Image> producer)
      Creates a multi-resolution image for the given dimensions.
      static java.awt.Image create​(int baseImageIndex, java.awt.Image... resolutionVariants)
      Creates a multi-resolution image from the given resolution variants.
      static java.awt.Image getResolutionVariant​(java.awt.Image image, int destImageWidth, int destImageHeight)
      Get the image variant that best matches the given width and height.
      static java.util.List<java.awt.Image> getResolutionVariants​(java.awt.Image image)
      Get a list of all resolution variants.
      static boolean isAvailable()
      Checks whether multi-resolution image support is available.
      static boolean isMultiResolutionImage​(java.awt.Image image)
      Checks whether the given image is a multi-resolution image that implements the interface java.awt.image.MultiResolutionImage.
      static java.awt.Image map​(java.awt.Image image, java.util.function.Function<java.awt.Image,​java.awt.Image> mapper)
      Creates a multi-resolution image that maps images from another multi-resolution image using the given mapper function.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MultiResolutionImageSupport

        public MultiResolutionImageSupport()
    • Method Detail

      • isAvailable

        public static boolean isAvailable()
        Checks whether multi-resolution image support is available.
        Returns:
        true when running on Java 9 or later; false on Java 8
      • isMultiResolutionImage

        public static boolean isMultiResolutionImage​(java.awt.Image image)
        Checks whether the given image is a multi-resolution image that implements the interface java.awt.image.MultiResolutionImage.
      • create

        public static java.awt.Image create​(int baseImageIndex,
                                            java.awt.Image... resolutionVariants)
        Creates a multi-resolution image from the given resolution variants.
        Parameters:
        baseImageIndex - index of the base image in the resolution variants array
        resolutionVariants - image resolution variants (sorted by size; smallest first)
        Returns:
        a multi-resolution image on Java 9 or later; the base image on Java 8
      • create

        public static java.awt.Image create​(int baseImageIndex,
                                            java.awt.Dimension[] dimensions,
                                            java.util.function.Function<java.awt.Dimension,​java.awt.Image> producer)
        Creates a multi-resolution image for the given dimensions. Initially the image does not contain any image data. The real images are created (and cached) on demand by invoking the given producer function.

        The given dimensions array is only used for getResolutionVariants(Image). The producer function may be invoked with any dimension (that is not contained in dimensions array) and is expected to produce an image for the passed in dimension.

        Parameters:
        baseImageIndex - index of the base image in the dimensions array
        dimensions - dimensions of resolution variants (sorted by size; smallest first)
        producer - producer function that creates a real image for the requested size
        Returns:
        a multi-resolution image on Java 9 or later; the base image on Java 8
      • map

        public static java.awt.Image map​(java.awt.Image image,
                                         java.util.function.Function<java.awt.Image,​java.awt.Image> mapper)
        Creates a multi-resolution image that maps images from another multi-resolution image using the given mapper function.

        Can be used to apply filter to multi-resolution images on demand. E.g. passed in image is for "enabled" state and mapper function creates images for "disabled" state.

        Parameters:
        image - a multi-resolution image that is mapped using the given mapper function
        mapper - mapper function that maps a single resolution variant to a new image (e.g. applying a filter)
        Returns:
        a multi-resolution image on Java 9 or later; a mapped image on Java 8
      • getResolutionVariant

        public static java.awt.Image getResolutionVariant​(java.awt.Image image,
                                                          int destImageWidth,
                                                          int destImageHeight)
        Get the image variant that best matches the given width and height.

        If the given image is a multi-resolution image then invokes java.awt.image.MultiResolutionImage.getResolutionVariant(destImageWidth, destImageHeight). Otherwise, returns the given image.

      • getResolutionVariants

        public static java.util.List<java.awt.Image> getResolutionVariants​(java.awt.Image image)
        Get a list of all resolution variants.

        If the given image is a multi-resolution image then invokes java.awt.image.MultiResolutionImage.getResolutionVariants(). Otherwise, returns a list containing only the given image.