Package org.openstreetmap.josm.tools
Class HiDPISupport
java.lang.Object
org.openstreetmap.josm.tools.HiDPISupport
Helper class for HiDPI support.
Gives access to the class
BaseMultiResolutionImage 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
FieldsModifier and TypeFieldDescriptionprivate static final Constructor<? extends Image>private static final Methodprivate static final Method -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ImagegetBaseImage(Image img) Wrapper for the methodjava.awt.image.BaseMultiResolutionImage#getBaseImage().static doubleDetect the GUI scale for HiDPI mode.static ImagegetMultiResolutionImage(Image base, ImageResource ir, ImageResizeMode resizeMode) Create a multi-resolution image from a base image and anImageResource.static ImagegetMultiResolutionImage(List<Image> imgs) Create a multi-resolution image from a list of images.static ImagegetResolutionVariant(Image img, double destImageWidth, double destImageHeight) Wrapper for methodjava.awt.image.MultiResolutionImage#getResolutionVariant(double destImageWidth, double destImageHeight).Wrapper for the methodjava.awt.image.MultiResolutionImage#getResolutionVariants().private static Constructor<? extends Image>private static Methodprivate static Methodstatic ImageprocessMRImage(Image img, UnaryOperator<Image> processor) Perform an operation on multi-resolution images.static ImagePerform an operation on multi-resolution images.
-
Field Details
-
baseMultiResolutionImageClass
-
baseMultiResolutionImageConstructor
-
resolutionVariantsMethod
-
resolutionVariantMethod
-
-
Constructor Details
-
HiDPISupport
private HiDPISupport()
-
-
Method Details
-
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
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
Wrapper for the methodjava.awt.image.BaseMultiResolutionImage#getBaseImage().Will return the argument
imgunchanged, if it is not a multi-resolution image.- Parameters:
img- the image- Returns:
- if
imgis ajava.awt.image.BaseMultiResolutionImage, then the base image, otherwise the image itself
-
getResolutionVariants
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
imgis ajava.awt.image.BaseMultiResolutionImage, then the result of the method#getResolutionVariants(), otherwise the image itself as a singleton list
-
getResolutionVariant
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
imgis ajava.awt.image.BaseMultiResolutionImage, then the result of the method#getResolutionVariant(destImageWidth, destImageHeight), otherwise the image itself
-
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
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
processorfor each resolution variant
-
processMRImages
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
processorfor each resolution variant
-
initBaseMultiResolutionImageClass
-
initBaseMultiResolutionImageConstructor
-
initResolutionVariantsMethod
-
initResolutionVariantMethod
-