Class TextColor.Indexed

  • All Implemented Interfaces:
    TextColor, java.io.Serializable
    Enclosing interface:
    TextColor

    public static class TextColor.Indexed
    extends java.lang.Object
    implements TextColor
    This class represents a color expressed in the indexed XTerm 256 color extension, where each color is defined in a lookup-table. All in all, there are 256 codes, but in order to know which one to know you either need to have the table at hand, or you can use the two static helper methods which can help you convert from three 8-bit RGB values to the closest approximate indexed color number. If you are interested, the 256 index values are actually divided like this:
    0 .. 15 - System colors, same as ANSI, but the actual rendered color depends on the terminal emulators color scheme
    16 .. 231 - Forms a 6x6x6 RGB color cube
    232 .. 255 - A gray scale ramp (without black and white endpoints)

    Support for indexed colors is somewhat widely adopted, not as much as the ANSI colors (TextColor.ANSI) but more than the RGB (TextColor.RGB).

    For more details on this, please see this commit message to Konsole.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[][] COLOR_TABLE  
      private int colorIndex  
    • Constructor Summary

      Constructors 
      Constructor Description
      Indexed​(int colorIndex)
      Creates a new TextColor using the XTerm 256 color indexed mode, with the specified index value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      private static TextColor.Indexed fromGreyRamp​(int intensity)
      Picks out a color from the grey-scale ramp area of the color index.
      static TextColor.Indexed fromRGB​(int red, int green, int blue)
      Picks out a color approximated from the supplied RGB components
      byte[] getBackgroundSGRSequence()
      Returns the byte sequence in between CSI and character 'm' that is used to enable this color as the background color on an ANSI-compatible terminal.
      int getBlue()  
      byte[] getForegroundSGRSequence()
      Returns the byte sequence in between CSI and character 'm' that is used to enable this color as the foreground color on an ANSI-compatible terminal.
      int getGreen()  
      int getRed()  
      int hashCode()  
      java.awt.Color toColor()
      Converts this color to an AWT color object, assuming a standard VGA palette.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • COLOR_TABLE

        private static final byte[][] COLOR_TABLE
      • colorIndex

        private final int colorIndex
    • Constructor Detail

      • Indexed

        public Indexed​(int colorIndex)
        Creates a new TextColor using the XTerm 256 color indexed mode, with the specified index value. You must choose a value between 0 and 255.
        Parameters:
        colorIndex - Index value to use for this color.
    • Method Detail

      • getForegroundSGRSequence

        public byte[] getForegroundSGRSequence()
        Description copied from interface: TextColor
        Returns the byte sequence in between CSI and character 'm' that is used to enable this color as the foreground color on an ANSI-compatible terminal.
        Specified by:
        getForegroundSGRSequence in interface TextColor
        Returns:
        Byte array out data to output in between of CSI and 'm'
      • getBackgroundSGRSequence

        public byte[] getBackgroundSGRSequence()
        Description copied from interface: TextColor
        Returns the byte sequence in between CSI and character 'm' that is used to enable this color as the background color on an ANSI-compatible terminal.
        Specified by:
        getBackgroundSGRSequence in interface TextColor
        Returns:
        Byte array out data to output in between of CSI and 'm'
      • getRed

        public int getRed()
        Specified by:
        getRed in interface TextColor
        Returns:
        Red intensity of this color, from 0 to 255
      • getGreen

        public int getGreen()
        Specified by:
        getGreen in interface TextColor
        Returns:
        Green intensity of this color, from 0 to 255
      • getBlue

        public int getBlue()
        Specified by:
        getBlue in interface TextColor
        Returns:
        Blue intensity of this color, from 0 to 255
      • toColor

        public java.awt.Color toColor()
        Description copied from interface: TextColor
        Converts this color to an AWT color object, assuming a standard VGA palette.
        Specified by:
        toColor in interface TextColor
        Returns:
        TextColor as an AWT Color
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • fromRGB

        public static TextColor.Indexed fromRGB​(int red,
                                                int green,
                                                int blue)
        Picks out a color approximated from the supplied RGB components
        Parameters:
        red - Red intensity, from 0 to 255
        green - Red intensity, from 0 to 255
        blue - Red intensity, from 0 to 255
        Returns:
        Nearest color from the 6x6x6 RGB color cube or from the 24 entries grey-scale ramp (whichever is closest)
      • fromGreyRamp

        private static TextColor.Indexed fromGreyRamp​(int intensity)
        Picks out a color from the grey-scale ramp area of the color index.
        Parameters:
        intensity - Intensity, 0 - 255
        Returns:
        Indexed color from the grey-scale ramp which is the best match for the supplied intensity