Package com.nomagic.ui
Class RetinaUtilities
- java.lang.Object
-
- com.nomagic.ui.RetinaUtilities
-
@OpenApiAll public class RetinaUtilities extends java.lang.Object
Utilities to work with icons and images on Retina display on Mac.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RetinaUtilities.LoadedImageIcon
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
MULTI_RESOLUTION_TOOLKIT_IMAGE_CLASS
private static java.lang.Integer
retinaScaling
-
Constructor Summary
Constructors Constructor Description RetinaUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.Cursor
createCursor(javax.swing.Icon icon, java.awt.Point pt, java.lang.String cursorName)
Creates a cursor from a given icon.static ScalableImageIcon
createIcon(java.awt.Image image)
Create retina friendly image icon from a given image.static java.awt.image.BufferedImage
createImage(int width, int height, int type)
Create retina friendly buffered image if retina is enabled.static java.awt.Image
createMultiResolutionImage(byte[] smallIconData, byte[] largeIconData)
Create a multi resolution friendly image from a pair of given images - small (regular) and large one.static java.awt.Image
createMultiResolutionImage(java.awt.image.RenderedImage smallImage, java.awt.image.RenderedImage largeImage)
Create a multi resolution friendly image from a pair of given images - small (regular) and large one.private static java.lang.String
getDefaultRetinaScalingFactor()
static int
getRetinaScaling()
Retrieve retina scaling factor from a default screen device.static boolean
isMultiResolutionToolkitImage(java.awt.Image image)
static boolean
isRetinaScalingDefined()
static void
paintRetinaImage(java.awt.Image img, java.awt.Component c, java.awt.Graphics g, int x, int y)
Paint given retina image on the graphics.static double
scaleDown(double size)
Scale given size by retina factor.static double
scaleUp(double size)
Scale sizestatic int
scaleUp(int size)
Scale given size by retina factor.static java.awt.Image
toMultiResolutionImage(javax.swing.Icon smallIcon, javax.swing.Icon largeIcon)
Create a multi resolution friendly image from a pair of given icons - small (regular) and large one.
-
-
-
Field Detail
-
MULTI_RESOLUTION_TOOLKIT_IMAGE_CLASS
private static final java.lang.String MULTI_RESOLUTION_TOOLKIT_IMAGE_CLASS
- See Also:
- Constant Field Values
-
retinaScaling
private static java.lang.Integer retinaScaling
-
-
Method Detail
-
isRetinaScalingDefined
public static boolean isRetinaScalingDefined()
- Returns:
- true if retina is used on the primary display
-
getRetinaScaling
public static int getRetinaScaling()
Retrieve retina scaling factor from a default screen device.- Returns:
- retina scaling factor. 1 if retina is not available, 2 if retina is available.
- See Also:
GraphicsEnvironment.getDefaultScreenDevice()
-
getDefaultRetinaScalingFactor
private static java.lang.String getDefaultRetinaScalingFactor()
-
scaleUp
public static int scaleUp(int size)
Scale given size by retina factor.- Parameters:
size
- size- Returns:
- scaled size
-
scaleUp
public static double scaleUp(double size)
Scale size- Parameters:
size
- size- Returns:
- scaled size
-
scaleDown
public static double scaleDown(double size)
Scale given size by retina factor.- Parameters:
size
- size- Returns:
- scaled size
-
createImage
public static java.awt.image.BufferedImage createImage(int width, int height, int type)
Create retina friendly buffered image if retina is enabled. Actual size of returned image is scaled up by retina scale factor (twice bigger). Image will- Parameters:
width
- widthheight
- heighttype
- image type- Returns:
- image
-
createIcon
public static ScalableImageIcon createIcon(java.awt.Image image)
Create retina friendly image icon from a given image.- Parameters:
image
- image- Returns:
- retina icon or simple icon if retina is not available
- See Also:
RetinaImageIcon
-
createCursor
public static java.awt.Cursor createCursor(javax.swing.Icon icon, java.awt.Point pt, java.lang.String cursorName)
Creates a cursor from a given icon. Multi-resolution image is created from a given icon and that image is used for a cursor.- Parameters:
icon
- the given iconpt
- the hot pointcursorName
- the cursor name- Returns:
- cursor
- See Also:
toMultiResolutionImage(javax.swing.Icon, javax.swing.Icon)
-
paintRetinaImage
public static void paintRetinaImage(java.awt.Image img, @CheckForNull java.awt.Component c, java.awt.Graphics g, int x, int y)
Paint given retina image on the graphics. Retina image is twice bigger than normal, so painting will apply 0.5 scale on the graphics.- Parameters:
img
- imagec
- componentg
- graphicsx
- xy
- y
-
createMultiResolutionImage
public static java.awt.Image createMultiResolutionImage(java.awt.image.RenderedImage smallImage, java.awt.image.RenderedImage largeImage)
Create a multi resolution friendly image from a pair of given images - small (regular) and large one.- Parameters:
smallImage
- small imagelargeImage
- large icon- Returns:
- multi-resolution friendly image
- See Also:
isMultiResolutionToolkitImage(java.awt.Image)
-
createMultiResolutionImage
public static java.awt.Image createMultiResolutionImage(byte[] smallIconData, byte[] largeIconData)
Create a multi resolution friendly image from a pair of given images - small (regular) and large one.- Parameters:
smallIconData
- small image datalargeIconData
- large image data- Returns:
- multi-resolution friendly image
- See Also:
isMultiResolutionToolkitImage(java.awt.Image)
-
toMultiResolutionImage
public static java.awt.Image toMultiResolutionImage(javax.swing.Icon smallIcon, @CheckForNull javax.swing.Icon largeIcon)
Create a multi resolution friendly image from a pair of given icons - small (regular) and large one. If small icon is an ImageIcon and it's image is multi-resolution friendly, that image is returned.- Parameters:
smallIcon
- small iconlargeIcon
- large icon- Returns:
- multi-resolution friendly image
- See Also:
isMultiResolutionToolkitImage(java.awt.Image)
-
isMultiResolutionToolkitImage
public static boolean isMultiResolutionToolkitImage(java.awt.Image image)
- Parameters:
image
- image- Returns:
- true if given image is instance of sun.awt.image.MultiResolutionToolkitImage
-
-