Package com.nomagic.ui
Class RetinaUtilities
java.lang.Object
com.nomagic.ui.RetinaUtilities
Utilities to work with icons and images on Retina display on Mac.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Cursor
createCursor
(Icon icon, Point pt, String cursorName) Creates a cursor from a given icon.static ScalableImageIcon
createIcon
(Image image) Create retina friendly image icon from a given image.static BufferedImage
createImage
(int width, int height, int type) Create retina friendly buffered image if retina is enabled.static Image
createMultiResolutionImage
(byte[] smallIconData, byte[] largeIconData) Create a multi resolution friendly image from a pair of given images - small (regular) and large one.static Image
createMultiResolutionImage
(RenderedImage smallImage, RenderedImage largeImage) Create a multi resolution friendly image from a pair of given images - small (regular) and large one.static int
Retrieve retina scaling factor from a default screen device.static boolean
static boolean
static void
paintRetinaImage
(Image img, ImageObserver observer, 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 Image
toMultiResolutionImage
(Icon smallIcon, Icon largeIcon) Create a multi resolution friendly image from a pair of given icons - small (regular) and large one.
-
Constructor Details
-
RetinaUtilities
public RetinaUtilities()
-
-
Method Details
-
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:
-
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
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
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:
-
createCursor
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:
-
paintRetinaImage
public static void paintRetinaImage(Image img, @CheckForNull ImageObserver observer, 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
- imageobserver
- componentg
- graphicsx
- xy
- y
-
createMultiResolutionImage
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:
-
createMultiResolutionImage
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:
-
toMultiResolutionImage
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
- Parameters:
image
- image- Returns:
- true if given image is instance of sun.awt.image.MultiResolutionToolkitImage
-