org.apache.poi.xssf.usermodel
Class XSSFColor

java.lang.Object
  extended by org.apache.poi.ss.usermodel.ExtendedColor
      extended by org.apache.poi.xssf.usermodel.XSSFColor
All Implemented Interfaces:
Color

public class XSSFColor
extends ExtendedColor

Represents a color in SpreadsheetML


Constructor Summary
XSSFColor()
          Create an new instance of XSSFColor, without knowledge of any custom indexed colors.
XSSFColor(byte[] rgb, IndexedColorMap colorMap)
           
XSSFColor(java.awt.Color clr)
          TEST ONLY - does not know about custom indexed colors
XSSFColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor color)
          Deprecated. 3.17 beta 1 - pass the workbook styles indexed color map, if any
XSSFColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor color, IndexedColorMap map)
          Create an instance of XSSFColor from the supplied XML bean, with the given color indexes
XSSFColor(IndexedColors indexedColor, IndexedColorMap colorMap)
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
 byte[] getARGB()
          Standard Alpha Red Green Blue ctColor value (ARGB).
 org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor getCTColor()
          Returns the underlying XML bean
 short getIndex()
          Indexed ctColor value.
 short getIndexed()
           
protected  byte[] getIndexedRGB()
           
 byte[] getRGB()
          Standard Red Green Blue ctColor value (RGB).
protected  byte[] getStoredRBG()
           
 int getTheme()
          Index into the collection, referencing a particular or value expressed in the Theme part.
 double getTint()
          Specifies the tint value applied to the ctColor.
 boolean hasAlpha()
           
 int hashCode()
           
 boolean hasTint()
           
 boolean isAuto()
          A boolean value indicating the ctColor is automatic and system ctColor dependent.
 boolean isIndexed()
          A boolean value indicating the ctColor is Indexed
 boolean isRGB()
           
 boolean isThemed()
           
 void setAuto(boolean auto)
           
 void setIndexed(int indexed)
          Indexed ctColor value.
 void setRGB(byte[] rgb)
          Standard Alpha Red Green Blue ctColor value (ARGB).
 void setTheme(int theme)
          Index into the collection, referencing a particular or value expressed in the Theme part.
 void setTint(double tint)
          Specifies the tint value applied to the ctColor.
static XSSFColor toXSSFColor(Color color)
          Checked type cast color to an XSSFColor.
 
Methods inherited from class org.apache.poi.ss.usermodel.ExtendedColor
getARGBHex, getRGBOrARGB, getRGBWithTint, setARGBHex, setColor
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XSSFColor

@Deprecated
@Removal(version="3.19")
public XSSFColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor color)
Deprecated. 3.17 beta 1 - pass the workbook styles indexed color map, if any

Create an instance of XSSFColor from the supplied XML bean, with default color indexes

Parameters:
color -

XSSFColor

public XSSFColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor color,
                 IndexedColorMap map)
Create an instance of XSSFColor from the supplied XML bean, with the given color indexes

Parameters:
color -
map -

XSSFColor

public XSSFColor()
Create an new instance of XSSFColor, without knowledge of any custom indexed colors. This is OK for just transiently setting indexes, etc. but is discouraged in read/get uses


XSSFColor

public XSSFColor(java.awt.Color clr)
TEST ONLY - does not know about custom indexed colors

Parameters:
clr - awt Color

XSSFColor

public XSSFColor(byte[] rgb,
                 IndexedColorMap colorMap)
Parameters:
rgb - bytes
colorMap -

XSSFColor

public XSSFColor(IndexedColors indexedColor,
                 IndexedColorMap colorMap)
Parameters:
indexedColor - color index (Enum named for default colors)
colorMap -
Method Detail

isAuto

public boolean isAuto()
A boolean value indicating the ctColor is automatic and system ctColor dependent.

Specified by:
isAuto in class ExtendedColor

setAuto

public void setAuto(boolean auto)
Parameters:
auto - true if the ctColor is automatic and system ctColor dependent.

isIndexed

public boolean isIndexed()
A boolean value indicating the ctColor is Indexed

Specified by:
isIndexed in class ExtendedColor

isRGB

public boolean isRGB()
Specified by:
isRGB in class ExtendedColor
Returns:
true if the ctColor is RGB or ARGB based

isThemed

public boolean isThemed()
Specified by:
isThemed in class ExtendedColor
Returns:
true if the ctColor is Theme based

hasAlpha

public boolean hasAlpha()
Returns:
true if the ctColor has a alpha

hasTint

public boolean hasTint()
Returns:
true if the ctColor has a tint

getIndex

public short getIndex()
Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.

Specified by:
getIndex in class ExtendedColor

getIndexed

public short getIndexed()
Returns:
Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.

setIndexed

public void setIndexed(int indexed)
Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.

Parameters:
indexed - color index

getRGB

public byte[] getRGB()
Standard Red Green Blue ctColor value (RGB). If there was an A (Alpha) value, it will be stripped.

Specified by:
getRGB in class ExtendedColor

getARGB

public byte[] getARGB()
Standard Alpha Red Green Blue ctColor value (ARGB).

Specified by:
getARGB in class ExtendedColor

getStoredRBG

protected byte[] getStoredRBG()
Specified by:
getStoredRBG in class ExtendedColor

getIndexedRGB

protected byte[] getIndexedRGB()
Specified by:
getIndexedRGB in class ExtendedColor

setRGB

public void setRGB(byte[] rgb)
Standard Alpha Red Green Blue ctColor value (ARGB).

Specified by:
setRGB in class ExtendedColor

getTheme

public int getTheme()
Index into the collection, referencing a particular or value expressed in the Theme part.

Specified by:
getTheme in class ExtendedColor

setTheme

public void setTheme(int theme)
Index into the collection, referencing a particular or value expressed in the Theme part.

Parameters:
theme - index

getTint

public double getTint()
Specifies the tint value applied to the ctColor.

If tint is supplied, then it is applied to the RGB value of the ctColor to determine the final ctColor applied.

The tint value is stored as a double from -1.0 .. 1.0, where -1.0 means 100% darken and 1.0 means 100% lighten. Also, 0.0 means no change.

In loading the RGB value, it is converted to HLS where HLS values are (0..HLSMAX), where HLSMAX is currently 255.

Here are some examples of how to apply tint to ctColor:
 If (tint < 0)
 Lum' = Lum * (1.0 + tint)

 For example: Lum = 200; tint = -0.5; Darken 50%
 Lum' = 200 * (0.5) => 100
 For example: Lum = 200; tint = -1.0; Darken 100% (make black)
 Lum' = 200 * (1.0-1.0) => 0
 If (tint > 0)
 Lum' = Lum * (1.0-tint) + (HLSMAX - HLSMAX * (1.0-tint))
 For example: Lum = 100; tint = 0.75; Lighten 75%

 Lum' = 100 * (1-.75) + (HLSMAX - HLSMAX*(1-.75))
 = 100 * .25 + (255 - 255 * .25)
 = 25 + (255 - 63) = 25 + 192 = 217
 For example: Lum = 100; tint = 1.0; Lighten 100% (make white)
 Lum' = 100 * (1-1) + (HLSMAX - HLSMAX*(1-1))
 = 100 * 0 + (255 - 255 * 0)
 = 0 + (255 - 0) = 255
 

Specified by:
getTint in class ExtendedColor
Returns:
the tint value

setTint

public void setTint(double tint)
Specifies the tint value applied to the ctColor.

If tint is supplied, then it is applied to the RGB value of the ctColor to determine the final ctColor applied.

The tint value is stored as a double from -1.0 .. 1.0, where -1.0 means 100% darken and 1.0 means 100% lighten. Also, 0.0 means no change.

In loading the RGB value, it is converted to HLS where HLS values are (0..HLSMAX), where HLSMAX is currently 255.

Here are some examples of how to apply tint to ctColor:
 If (tint < 0)
 Lum' = Lum * (1.0 + tint)

 For example: Lum = 200; tint = -0.5; Darken 50%
 Lum' = 200 * (0.5) => 100
 For example: Lum = 200; tint = -1.0; Darken 100% (make black)
 Lum' = 200 * (1.0-1.0) => 0
 If (tint > 0)
 Lum' = Lum * (1.0-tint) + (HLSMAX - HLSMAX * (1.0-tint))
 For example: Lum = 100; tint = 0.75; Lighten 75%

 Lum' = 100 * (1-.75) + (HLSMAX - HLSMAX*(1-.75))
 = 100 * .25 + (255 - 255 * .25)
 = 25 + (255 - 63) = 25 + 192 = 217
 For example: Lum = 100; tint = 1.0; Lighten 100% (make white)
 Lum' = 100 * (1-1) + (HLSMAX - HLSMAX*(1-1))
 = 100 * 0 + (255 - 255 * 0)
 = 0 + (255 - 0) = 255
 

Specified by:
setTint in class ExtendedColor
Parameters:
tint - the tint value

getCTColor

@Internal
public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor getCTColor()
Returns the underlying XML bean

Returns:
the underlying XML bean

toXSSFColor

public static XSSFColor toXSSFColor(Color color)
Checked type cast color to an XSSFColor.

Parameters:
color - the color to type cast
Returns:
the type casted color
Throws:
java.lang.IllegalArgumentException - if color is null or is not an instance of XSSFColor

hashCode

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

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object