Class Color


  • public final class Color
    extends java.lang.Object
    The Color class is just an utility class used to do operations in a color, which is actually represented by an int in the format 0x00RRGGBB.

    A color is defined as a mixture of red, green and blue color values. Each value is in the range of 0 to 255 where 0 is darkest and 255 is brightest. For example, Color(255, 0, 0) is the color red.

    Here are some more examples:

    • Color(0, 0, 0) is black
    • Color(255, 255, 255) is white
    • Color(255, 0, 0 ) is red
    • Color(0, 255, 0) is green
    • Color(0, 0, 255) is blue
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BLACK  
      static int BLUE  
      static int BRIGHT  
      static int CYAN  
      static int DARK  
      static int FULL_STEP
      Increase or decrease all RGB values by 96.
      static int GREEN  
      static int HALF_STEP
      Increase or decrease all RGB values by 48.
      static int LESS_STEP
      Increase or decrease all RGB values by 32.
      static int MAGENTA  
      static int ORANGE  
      static int PINK  
      static int RED  
      static int WHITE  
      static int YELLOW  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static int brighter​(int rgb)
      Returns a color that is brighter than the current one.
      static int brighter​(int rgb, int step)
      Returns a color that is brighter than the current one.
      static int darker​(int rgb)
      Return a color that is darker than the current one.
      static int darker​(int rgb, int step)
      Returns a color that is darker than the current one.
      static int getAlpha​(int rgb)
      Deprecated.
      static int getBetterContrast​(int original, int color1, int color2)
      Returns a color that better contrasts with the given original color.
      static int getBlue​(int rgb)
      Returns the blue value of the color.
      static int getBrightness​(int rgb)
      Returns the brightness value of a color, in the range 0-255.
      static int getCursorColor​(int rgb)
      Returns the best cursor color depending on this color
      static int getCursorColor​(int rgb, int step)
      Returns the best cursor color depending on this color
      static int getGray​(int c)
      Returns a gray color based on the given one
      static int getGreen​(int rgb)
      Returns the green value of the color.
      static int getInvertedGray​(int c)
      Returns an inverted gray color based on the given one (255 - gray)
      static int getRandomColor​(Random r)
      Returns a random color.
      static int getRed​(int rgb)
      Returns the red value of the color.
      static int getRGB​(int red, int green, int blue)
      Returns a color integer value with the given red, green and blue components.
      static int getRGB​(java.lang.String rrggbb)
      Returns a color integer value parsing the given rgb.
      static int getRGBEnsureRange​(int red, int green, int blue)
      Returns a color integer value with the given red, green and blue components, ensuring that the values are within the 0-255 range.
      static int interpolate​(int color1, int color2)
      Interpolates the given colors.
      static int interpolate​(int color1, int color2, int factor)
      Interpolates the given colors by the given factor, ranging from 0 to 100.
      static int interpolateA​(int color1, int color2, int factor)
      Interpolates the given colors by the given factor, ranging from 0 to 255.
      static java.lang.String toString​(int rgb)
      Returns the string representation of this color: the rgb in hexadecimal
      • Methods inherited from class java.lang.Object

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

      • getRGB

        public static int getRGB​(int red,
                                 int green,
                                 int blue)
        Returns a color integer value with the given red, green and blue components.
        Parameters:
        red - the red value in the range of 0 to 255
        green - the green value in the range of 0 to 255
        blue - the blue value in the range of 0 to 255
        Since:
        SuperWaba 5.8
      • getRGBEnsureRange

        public static int getRGBEnsureRange​(int red,
                                            int green,
                                            int blue)
        Returns a color integer value with the given red, green and blue components, ensuring that the values are within the 0-255 range.
        Parameters:
        red - the red value in any range
        green - the green value in any range
        blue - the blue value in any range
        Since:
        SuperWaba 5.8
      • getRGB

        public static int getRGB​(java.lang.String rrggbb)
        Returns a color integer value parsing the given rgb. Note that this method is rather slow.
        Parameters:
        rrggbb - a string in the format RRGGBB (colors in hex).
        Since:
        SuperWaba 5.8
      • getAlpha

        @Deprecated
        public static int getAlpha​(int rgb)
        Deprecated.
        Returns the alpha channel (brightness) of the color value in a value from 0 to 255.
      • getBlue

        public static int getBlue​(int rgb)
        Returns the blue value of the color.
      • getGreen

        public static int getGreen​(int rgb)
        Returns the green value of the color.
      • getRed

        public static int getRed​(int rgb)
        Returns the red value of the color.
      • brighter

        public static int brighter​(int rgb)
        Returns a color that is brighter than the current one.
      • darker

        public static int darker​(int rgb)
        Return a color that is darker than the current one.
      • getBrightness

        public static int getBrightness​(int rgb)
        Returns the brightness value of a color, in the range 0-255. Source: https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
      • getCursorColor

        public static int getCursorColor​(int rgb)
        Returns the best cursor color depending on this color
      • getCursorColor

        public static int getCursorColor​(int rgb,
                                         int step)
        Returns the best cursor color depending on this color
      • brighter

        public static int brighter​(int rgb,
                                   int step)
        Returns a color that is brighter than the current one.
      • darker

        public static int darker​(int rgb,
                                 int step)
        Returns a color that is darker than the current one.
      • toString

        public static java.lang.String toString​(int rgb)
        Returns the string representation of this color: the rgb in hexadecimal
      • interpolate

        public static int interpolate​(int color1,
                                      int color2)
        Interpolates the given colors.
        Since:
        TotalCross 1.0 beta 4
      • interpolate

        public static int interpolate​(int color1,
                                      int color2,
                                      int factor)
        Interpolates the given colors by the given factor, ranging from 0 to 100.
        Since:
        TotalCross 1.23
      • interpolateA

        public static int interpolateA​(int color1,
                                       int color2,
                                       int factor)
        Interpolates the given colors by the given factor, ranging from 0 to 255.
        Since:
        TotalCross 1.23
      • getBetterContrast

        public static int getBetterContrast​(int original,
                                            int color1,
                                            int color2)
        Returns a color that better contrasts with the given original color.
        Since:
        TotalCross 1.23
      • getRandomColor

        public static int getRandomColor​(Random r)
        Returns a random color. Example:
              Random r = new Random();
              for (int i = 0; i < tt.length; i++)
                 tabPanel.getContainer(i).setBackColor(Color.getRandomColor(r));
         
        Since:
        TotalCross 3.0
      • getGray

        public static int getGray​(int c)
        Returns a gray color based on the given one
      • getInvertedGray

        public static int getInvertedGray​(int c)
        Returns an inverted gray color based on the given one (255 - gray)