Package org.openstreetmap.josm.tools
Class HiDPISupport
- java.lang.Object
-
- org.openstreetmap.josm.tools.HiDPISupport
-
public final class HiDPISupport extends Object
Helper class for HiDPI support. Gives access to the classBaseMultiResolutionImage
via reflection, in case it is on classpath. This is to be expected for Java 9, but not for Java 8 runtime.- Since:
- 12722
-
-
Field Summary
Fields Modifier and Type Field Description private static Class<? extends Image>
baseMultiResolutionImageClass
private static Constructor<? extends Image>
baseMultiResolutionImageConstructor
private static Method
resolutionVariantMethod
private static Method
resolutionVariantsMethod
-
Constructor Summary
Constructors Modifier Constructor Description private
HiDPISupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Image
getBaseImage(Image img)
Wrapper for the methodjava.awt.image.BaseMultiResolutionImage#getBaseImage()
.static double
getHiDPIScale()
Detect the GUI scale for HiDPI mode.static Image
getMultiResolutionImage(Image base, ImageResource ir, ImageResizeMode resizeMode)
Create a multi-resolution image from a base image and anImageResource
.static Image
getMultiResolutionImage(List<Image> imgs)
Create a multi-resolution image from a list of images.static Image
getResolutionVariant(Image img, double destImageWidth, double destImageHeight)
Wrapper for methodjava.awt.image.MultiResolutionImage#getResolutionVariant(double destImageWidth, double destImageHeight)
.static List<Image>
getResolutionVariants(Image img)
Wrapper for the methodjava.awt.image.MultiResolutionImage#getResolutionVariants()
.private static Class<? extends Image>
initBaseMultiResolutionImageClass()
private static Constructor<? extends Image>
initBaseMultiResolutionImageConstructor()
private static Method
initResolutionVariantMethod()
private static Method
initResolutionVariantsMethod()
static Image
processMRImage(Image img, UnaryOperator<Image> processor)
Perform an operation on multi-resolution images.static Image
processMRImages(List<Image> imgs, Function<List<Image>,Image> processor)
Perform an operation on multi-resolution images.
-
-
-
Field Detail
-
baseMultiResolutionImageClass
private static final Class<? extends Image> baseMultiResolutionImageClass
-
baseMultiResolutionImageConstructor
private static final Constructor<? extends Image> baseMultiResolutionImageConstructor
-
resolutionVariantsMethod
private static final Method resolutionVariantsMethod
-
resolutionVariantMethod
private static final Method resolutionVariantMethod
-
-
Constructor Detail
-
HiDPISupport
private HiDPISupport()
-
-
Method Detail
-
getMultiResolutionImage
public static Image getMultiResolutionImage(Image base, ImageResource ir, ImageResizeMode resizeMode)
Create a multi-resolution image from a base image and anImageResource
.Will only return multi-resolution image, if HiDPI-mode is detected. Then the image stack will consist of the base image and one that fits the HiDPI scale of the main display.
- Parameters:
base
- the base imageir
- a corresponding image resourceresizeMode
- how to size/resize the image- Returns:
- multi-resolution image if necessary and possible, the base image otherwise
-
getMultiResolutionImage
public static Image getMultiResolutionImage(List<Image> imgs)
Create a multi-resolution image from a list of images.- Parameters:
imgs
- the images, supposedly the same image at different resolutions, must not be empty- Returns:
- corresponding multi-resolution image, if possible, the first image in the list otherwise
-
getBaseImage
public static Image getBaseImage(Image img)
Wrapper for the methodjava.awt.image.BaseMultiResolutionImage#getBaseImage()
.Will return the argument
img
unchanged, if it is not a multi-resolution image.- Parameters:
img
- the image- Returns:
- if
img
is ajava.awt.image.BaseMultiResolutionImage
, then the base image, otherwise the image itself
-
getResolutionVariants
public static List<Image> getResolutionVariants(Image img)
Wrapper for the methodjava.awt.image.MultiResolutionImage#getResolutionVariants()
.Will return the argument as a singleton list, in case it is not a multi-resolution image.
- Parameters:
img
- the image- Returns:
- if
img
is ajava.awt.image.BaseMultiResolutionImage
, then the result of the method#getResolutionVariants()
, otherwise the image itself as a singleton list
-
getResolutionVariant
public static Image getResolutionVariant(Image img, double destImageWidth, double destImageHeight)
Wrapper for methodjava.awt.image.MultiResolutionImage#getResolutionVariant(double destImageWidth, double destImageHeight)
.Will return the argument, in case it is not a multi-resolution image.
- Parameters:
img
- the imagedestImageWidth
- the width of the destination imagedestImageHeight
- the height of the destination image- Returns:
- if
img
is ajava.awt.image.BaseMultiResolutionImage
, then the result of the method#getResolutionVariant(destImageWidth, destImageHeight)
, otherwise the image itself
-
getHiDPIScale
public static double getHiDPIScale()
Detect the GUI scale for HiDPI mode.This method may not work as expected for a multi-monitor setup. It will only take the default screen device into account.
- Returns:
- the GUI scale for HiDPI mode, a value of 1.0 means standard mode.
-
processMRImage
public static Image processMRImage(Image img, UnaryOperator<Image> processor)
Perform an operation on multi-resolution images. When input image is not multi-resolution, it will simply apply the processor once. Otherwise, the processor will be called for each resolution variant and the resulting images assembled to become the output multi-resolution image.- Parameters:
img
- input image, possibly multi-resolutionprocessor
- processor taking a plain image as input and returning a single plain image as output- Returns:
- multi-resolution image assembled from the output of calls to
processor
for each resolution variant
-
processMRImages
public static Image processMRImages(List<Image> imgs, Function<List<Image>,Image> processor)
Perform an operation on multi-resolution images. When input images are not multi-resolution, it will simply apply the processor once. Otherwise, the processor will be called for each resolution variant and the resulting images assembled to become the output multi-resolution image.- Parameters:
imgs
- input images, possibly multi-resolutionprocessor
- processor taking a list of plain images as input and returning a single plain image as output- Returns:
- multi-resolution image assembled from the output of calls to
processor
for each resolution variant
-
initBaseMultiResolutionImageClass
private static Class<? extends Image> initBaseMultiResolutionImageClass()
-
initBaseMultiResolutionImageConstructor
private static Constructor<? extends Image> initBaseMultiResolutionImageConstructor()
-
initResolutionVariantsMethod
private static Method initResolutionVariantsMethod()
-
initResolutionVariantMethod
private static Method initResolutionVariantMethod()
-
-