Class RetinaUtilities

java.lang.Object
com.nomagic.ui.RetinaUtilities

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

      public static 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(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:
    • createCursor

      public static Cursor createCursor(Icon icon, Point pt, 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:
    • 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 - image
      observer - component
      g - graphics
      x - x
      y - y
    • createMultiResolutionImage

      public static Image createMultiResolutionImage(RenderedImage smallImage, 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:
    • createMultiResolutionImage

      public static 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:
    • toMultiResolutionImage

      public static Image toMultiResolutionImage(Icon smallIcon, @CheckForNull 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

      public static boolean isMultiResolutionToolkitImage(Image image)
      Parameters:
      image - image
      Returns:
      true if given image is instance of sun.awt.image.MultiResolutionToolkitImage