Class ColorUtil


  • public class ColorUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ColorUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Paint getCheckerPaint()
      Obtain a java.awt.Paint instance which draws a checker background of black and white.
      static java.awt.Paint getCheckerPaint​(java.awt.Color c1, java.awt.Color c2, int size)  
      static java.awt.Color interpolate​(java.awt.Color b, java.awt.Color a, float t)  
      static java.awt.Color removeAlpha​(java.awt.Color color)
      Returns a new color equal to the old one, except that there is no alpha channel (transparency).
      static java.awt.Color setAlpha​(java.awt.Color col, int alpha)
      Modifies the passed in color by setting a new alpha channel (transparency) and returns the new color.
      static java.awt.Color setBrightness​(java.awt.Color color, float brightness)
      Modifies the passed in color by changing it's brightness using HSB calculations.
      static java.awt.Color setSaturation​(java.awt.Color color, float saturation)  
      static void tileStretchPaint​(java.awt.Graphics g, javax.swing.JComponent comp, java.awt.image.BufferedImage img, java.awt.Insets ins)
      Draws an image on top of a component by doing a 3x3 grid stretch of the image using the specified insets.
      static java.lang.String toHexString​(java.awt.Color color)
      Produces a String representing the passed in color as a hex value (including the #) suitable for use in html.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ColorUtil

        public ColorUtil()
    • Method Detail

      • removeAlpha

        public static java.awt.Color removeAlpha​(java.awt.Color color)
        Returns a new color equal to the old one, except that there is no alpha channel (transparency).
        Parameters:
        color - the color to remove the alpha (transparency) from
        Returns:
        Color
      • setAlpha

        public static java.awt.Color setAlpha​(java.awt.Color col,
                                              int alpha)
        Modifies the passed in color by setting a new alpha channel (transparency) and returns the new color.
        Parameters:
        col - the color to modify
        alpha - the new alpha (transparency) level. Must be an int between 0 and 255
        Returns:
        the new Color
      • setBrightness

        public static java.awt.Color setBrightness​(java.awt.Color color,
                                                   float brightness)
        Modifies the passed in color by changing it's brightness using HSB calculations. The brightness must be a float between 0 and 1. If 0 the resulting color will be black. If 1 the resulting color will be the brightest possible form of the passed in color.
        Parameters:
        color - the color to modify
        brightness - the brightness to use in the new color
        Returns:
        the new Color
      • toHexString

        public static java.lang.String toHexString​(java.awt.Color color)
        Produces a String representing the passed in color as a hex value (including the #) suitable for use in html. It does not include the alpha (transparency) channel in the string.
        Parameters:
        color - the color to convert
        Returns:
        the hex String
      • getCheckerPaint

        public static java.awt.Paint getCheckerPaint()
        Obtain a java.awt.Paint instance which draws a checker background of black and white. Note: The returned instance may be shared. Note: This method should be reimplemented to not use a png resource.
        Returns:
        a Paint implementation
      • getCheckerPaint

        public static java.awt.Paint getCheckerPaint​(java.awt.Color c1,
                                                     java.awt.Color c2,
                                                     int size)
      • tileStretchPaint

        public static void tileStretchPaint​(java.awt.Graphics g,
                                            javax.swing.JComponent comp,
                                            java.awt.image.BufferedImage img,
                                            java.awt.Insets ins)
        Draws an image on top of a component by doing a 3x3 grid stretch of the image using the specified insets.
      • setSaturation

        public static java.awt.Color setSaturation​(java.awt.Color color,
                                                   float saturation)
      • interpolate

        public static java.awt.Color interpolate​(java.awt.Color b,
                                                 java.awt.Color a,
                                                 float t)