Class RetinaUtilities


  • @OpenApiAll
    public class RetinaUtilities
    extends java.lang.Object
    Utilities to work with icons and images on Retina display on Mac.
    • 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 size
      static 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • RetinaUtilities

        public RetinaUtilities()
    • 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 - width
        height - height
        type - 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 icon
        pt - the hot point
        cursorName - 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 - image
        c - component
        g - graphics
        x - x
        y - 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 image
        largeImage - 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 data
        largeIconData - 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 icon
        largeIcon - 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