Class ColorUtils

java.lang.Object
net.thevpc.echo.jfx.util.ColorUtils

public class ColorUtils
extends java.lang.Object
Author:
vpc
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String TEXTUTE_ID_SAMPLE1  
    static java.lang.String TEXTUTE_ID_SAMPLE2  
    static java.lang.String TEXTUTE_ID_SAMPLE3  
    static java.lang.String TEXTUTE_ID_SAMPLE4  
    static java.lang.String TEXTUTE_ID_SAMPLE5  
  • Constructor Summary

    Constructors
    Constructor Description
    ColorUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.awt.Color addColors​(java.awt.Color c1, java.awt.Color c2, double amt)  
    static java.awt.Color blendColors​(java.awt.Color c1, java.awt.Color c2, double amt)  
    static java.awt.Color blendColors​(java.awt.Color c1, java.awt.Paint c2, double amt)  
    static java.awt.Color blendColors​(java.awt.Paint c1, java.awt.Color c2, double amt)  
    static java.awt.Color changeAlpha​(java.awt.Color c, int alpha)  
    static java.awt.Color convertColor​(float[] color)
    Returns a new Color object given the color components in the given array.
    static float[] convertColor​(java.awt.Color color)
    Returns an array of color components for the given Color object.
    static void convertColor​(java.awt.Color color, float[] destination)
    Places the RGBA values from the given Color object into the destination array.
    static java.lang.String formatColor​(java.awt.Color s)  
    static java.lang.String formatPaint​(java.awt.Paint s)  
    static int getBrightness​(java.awt.Color color)
    Uses the method described at http://alienryderflex.com/hsp.html to get the perceived brightness of a color.
    static int getBrightness​(java.awt.Paint color)  
    static java.awt.TexturePaint getCheckerBoard​(int checkerSize, java.awt.Color color1, java.awt.Color color2)  
    static java.awt.Color getColor​(java.awt.Color color, float factor)
    Returns a new color that is darker or lighter than the given color by the given factor.
    static java.awt.Color getForegroundColorFromBackgroundColor​(java.awt.Color color)
    Returns a foreground color (for text) given a background color by examining the brightness of the background color.
    static java.awt.Color getForegroundColorFromBackgroundColor​(java.awt.Paint color)
    Returns a foreground color (for text) given a background color by examining the brightness of the background color.
    static java.awt.Color getInvertColor​(java.awt.Color color)
    Returns a foreground color (for text) given a background color by examining the brightness of the background color.
    static java.awt.Color getRandomColor​(float offset, float alpha)
    Returns a random color given the offset and alpha values.
    static java.awt.Color paintToColor​(java.awt.Paint color)  
    static java.awt.Color parseColor​(java.lang.String s)  
    static java.awt.Paint parsePaint​(java.lang.String s)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TEXTUTE_ID_SAMPLE1

      public static final java.lang.String TEXTUTE_ID_SAMPLE1
      See Also:
      Constant Field Values
    • TEXTUTE_ID_SAMPLE2

      public static final java.lang.String TEXTUTE_ID_SAMPLE2
      See Also:
      Constant Field Values
    • TEXTUTE_ID_SAMPLE3

      public static final java.lang.String TEXTUTE_ID_SAMPLE3
      See Also:
      Constant Field Values
    • TEXTUTE_ID_SAMPLE4

      public static final java.lang.String TEXTUTE_ID_SAMPLE4
      See Also:
      Constant Field Values
    • TEXTUTE_ID_SAMPLE5

      public static final java.lang.String TEXTUTE_ID_SAMPLE5
      See Also:
      Constant Field Values
  • Constructor Details

    • ColorUtils

      public ColorUtils()
  • Method Details

    • formatPaint

      public static java.lang.String formatPaint​(java.awt.Paint s)
    • parseColor

      public static java.awt.Color parseColor​(java.lang.String s)
    • formatColor

      public static java.lang.String formatColor​(java.awt.Color s)
    • parsePaint

      public static java.awt.Paint parsePaint​(java.lang.String s)
    • getCheckerBoard

      public static java.awt.TexturePaint getCheckerBoard​(int checkerSize, java.awt.Color color1, java.awt.Color color2)
    • changeAlpha

      public static java.awt.Color changeAlpha​(java.awt.Color c, int alpha)
    • blendColors

      public static java.awt.Color blendColors​(java.awt.Paint c1, java.awt.Color c2, double amt)
    • blendColors

      public static java.awt.Color blendColors​(java.awt.Color c1, java.awt.Paint c2, double amt)
    • getForegroundColorFromBackgroundColor

      public static final java.awt.Color getForegroundColorFromBackgroundColor​(java.awt.Paint color)
      Returns a foreground color (for text) given a background color by examining the brightness of the background color.
      Parameters:
      color - the foreground color
      Returns:
      Color
    • blendColors

      public static java.awt.Color blendColors​(java.awt.Color c1, java.awt.Color c2, double amt)
    • addColors

      public static java.awt.Color addColors​(java.awt.Color c1, java.awt.Color c2, double amt)
    • convertColor

      public static final float[] convertColor​(java.awt.Color color)
      Returns an array of color components for the given Color object.
      Parameters:
      color - the color object
      Returns:
      float[]
    • convertColor

      public static final java.awt.Color convertColor​(float[] color)
      Returns a new Color object given the color components in the given array.
      Parameters:
      color - the color components in RGB or RGBA
      Returns:
      Color
    • convertColor

      public static final void convertColor​(java.awt.Color color, float[] destination)
      Places the RGBA values from the given Color object into the destination array.
      Parameters:
      color - the color to convert
      destination - the array to hold the RGBA values; length 4
    • getBrightness

      public static final int getBrightness​(java.awt.Paint color)
    • getBrightness

      public static final int getBrightness​(java.awt.Color color)
      Uses the method described at http://alienryderflex.com/hsp.html to get the perceived brightness of a color.
      Parameters:
      color - the color
      Returns:
      int brightness on the scale of 0 to 255
    • getForegroundColorFromBackgroundColor

      public static final java.awt.Color getForegroundColorFromBackgroundColor​(java.awt.Color color)
      Returns a foreground color (for text) given a background color by examining the brightness of the background color.
      Parameters:
      color - the foreground color
      Returns:
      Color
    • getInvertColor

      public static final java.awt.Color getInvertColor​(java.awt.Color color)
      Returns a foreground color (for text) given a background color by examining the brightness of the background color.
      Parameters:
      color - the foreground color
      Returns:
      Color
    • getRandomColor

      public static final java.awt.Color getRandomColor​(float offset, float alpha)
      Returns a random color given the offset and alpha values.
      Parameters:
      offset - the offset between 0.0 and 1.0
      alpha - the alpha value between 0.0 and 1.0
      Returns:
      Color
    • getColor

      public static final java.awt.Color getColor​(java.awt.Color color, float factor)
      Returns a new color that is darker or lighter than the given color by the given factor.
      Parameters:
      color - the color to modify
      factor - 0.0 ≤ factor ≤ 1.0 darkens; 1.0 < factor brightens
      Returns:
      Color
      Since:
      1.0.1
    • paintToColor

      public static java.awt.Color paintToColor​(java.awt.Paint color)