Class MultiResolutionImageSupport
- java.lang.Object
-
- com.formdev.flatlaf.util.MultiResolutionImageSupport
-
public class MultiResolutionImageSupport extends Object
Support for multi-resolution images available since Java 9.
-
-
Constructor Summary
Constructors Constructor Description MultiResolutionImageSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Image
create(int baseImageIndex, Dimension[] dimensions, Function<Dimension,Image> producer)
Creates a multi-resolution image for the given dimensions.static Image
create(int baseImageIndex, Image... resolutionVariants)
Creates a multi-resolution image from the given resolution variants.static Image
getResolutionVariant(Image image, int destImageWidth, int destImageHeight)
Get the image variant that best matches the given width and height.static List<Image>
getResolutionVariants(Image image)
Get a list of all resolution variants.static boolean
isAvailable()
Checks whether multi-resolution image support is available.static boolean
isMultiResolutionImage(Image image)
Checks whether the given image is a multi-resolution image that implements the interfacejava.awt.image.MultiResolutionImage
.static Image
map(Image image, Function<Image,Image> mapper)
Creates a multi-resolution image that maps images from another multi-resolution image using the given mapper function.
-
-
-
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(Image image)
Checks whether the given image is a multi-resolution image that implements the interfacejava.awt.image.MultiResolutionImage
.
-
create
public static Image create(int baseImageIndex, Image... resolutionVariants)
Creates a multi-resolution image from the given resolution variants.- Parameters:
baseImageIndex
- index of the base image in the resolution variants arrayresolutionVariants
- 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 Image create(int baseImageIndex, Dimension[] dimensions, Function<Dimension,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 arraydimensions
- 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 Image map(Image image, Function<Image,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 functionmapper
- 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 Image getResolutionVariant(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 List<Image> getResolutionVariants(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.
-
-