Class Color
CT_Color).
Construct with rgb(int, int, int), argb, of(int), indexed(int),
theme(int) or auto(). Check the kind with isRgb(),
isIndexed(), isTheme() and isAuto() before you call
a kind-specific reader: argb(), red() and the other channel
readers work on RGB colors only, themeIndex() and tint() on
theme colors only, and each throws IllegalStateException on the wrong
kind.
Colors read back from a cell keep their kind: a theme color reads back as a
theme color, not as its resolved RGB value. Some setters accept RGB colors
only; they say so and throw IllegalStateException for the other kinds.
Color accent = Color.theme(4, -0.25); // accent 1, 25 % darker
Color brand = Color.rgb(0x1F, 0x4E, 0x79);
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ColorOpaque black, #000000.static final ColorOpaque blue, #0000FF.static final ColorOpaque gray, #808080.static final ColorOpaque green, #008000 (HTML green, not #00FF00).static final ColorOpaque red, #FF0000.static final ColorOpaque white, #FFFFFF.static final ColorOpaque yellow, #FFFF00. -
Method Summary
Modifier and TypeMethodDescriptionintalpha()The alpha channel of an RGB color.intargb()The packed0xAARRGGBBvalue of an RGB color.static Colorargb(int a, int r, int g, int b) An RGB color with an alpha channel.static Colorauto()The automatic color: Excel's "Automatic", which draws as the window-text color (black by default).intblue()The blue channel of an RGB color.booleanstatic ColorDecodes the engine's JSON color form: a map such as{"rgb":"#AARRGGBB"},{"indexed":N},{"theme":I,"tint":T}or{"auto":true}, or a string in a form thatparse(String)accepts.intgreen()The green channel of an RGB color.inthashCode()static Colorindexed(int index) A legacy indexed-palette color (ECMA-376 §18.8.27).intThe palette index of an indexed color.booleanisAuto()Whether this is the automatic (window-text) color,auto().booleanWhether this is a legacy indexed-palette color; thenindexedValue()works.booleanisRgb()Whether this is a plain ARGB color; thenargb()and the channel readers work.booleanisTheme()Whether this is a theme-palette color; thenthemeIndex()andtint()work.static Colorof(int argb) An RGB color from a packed0xAARRGGBBvalue.static ColorParses a color string.intred()The red channel of an RGB color.static Colorrgb(int r, int g, int b) An opaque RGB color (alpha 255).static Colortheme(int themeIndex) A theme-palette color with no tint.static Colortheme(int themeIndex, double tint) A theme-palette color with a tint.intThe theme index of a theme color, in the order oftheme(int, double)(0 = light 1, 1 = dark 1).doubletint()The tint of a theme color.toHex()The hex form of an RGB color, upper case with alpha, e.g.The JSON value sent to the engine, in the forms thatfromJson(Object)reads.toString()
-
Field Details
-
BLACK
Opaque black, #000000. -
WHITE
Opaque white, #FFFFFF. -
RED
Opaque red, #FF0000. -
GREEN
Opaque green, #008000 (HTML green, not #00FF00). -
BLUE
Opaque blue, #0000FF. -
YELLOW
Opaque yellow, #FFFF00. -
GRAY
Opaque gray, #808080.
-
-
Method Details
-
rgb
An opaque RGB color (alpha 255).- Parameters:
r- red channel, 0-255; only the low 8 bits are keptg- green channel, 0-255; only the low 8 bits are keptb- blue channel, 0-255; only the low 8 bits are kept- Returns:
- the color
-
argb
An RGB color with an alpha channel.- Parameters:
a- alpha, 0-255 (255 = opaque); only the low 8 bits are keptr- red channel, 0-255; only the low 8 bits are keptg- green channel, 0-255; only the low 8 bits are keptb- blue channel, 0-255; only the low 8 bits are kept- Returns:
- the color
-
of
An RGB color from a packed0xAARRGGBBvalue. Note thatof(0xFF0000)has alpha 0; writeof(0xFFFF0000)or usergb(int, int, int)for an opaque color.- Parameters:
argb- the packed value, alpha in the top byte- Returns:
- the color
-
indexed
A legacy indexed-palette color (ECMA-376 §18.8.27). Indices 0-63 address the 64-entry palette; 64 is the system foreground and 65 the system background.- Parameters:
index- the palette index, 0-255- Returns:
- the color
- Throws:
IllegalArgumentException- ifindexis outside 0-255
-
theme
A theme-palette color with no tint.themeIndexuses the order oftheme(int, double): 0 = light 1, 1 = dark 1, 2 = light 2, 3 = dark 2, 4-9 = accent 1-6, 10 = hyperlink, 11 = followed hyperlink.- Parameters:
themeIndex- the SpreadsheetML theme index, 0-11- Returns:
- the color
- Throws:
IllegalArgumentException- ifthemeIndexis outside 0-11
-
theme
A theme-palette color with a tint.themeIndexis the SpreadsheetML cell-color index: 0 = light 1 (Excel's "Background 1"), 1 = dark 1 ("Text 1"), 2 = light 2 ("Background 2"), 3 = dark 2 ("Text 2"), 4-9 = accent 1-6, 10 = hyperlink, 11 = followed hyperlink.This order swaps 0/1 and 2/3 against the theme file order of
Theme.Slot. SoColor.theme(0)is white andColor.theme(1)is black in the default Office theme. The index is written to the file as given, so Excel shows the same color.Color text = Color.theme(1); // dark 1: black text Color band = Color.theme(4, 0.8); // accent 1, 80 % lighter- Parameters:
themeIndex- the SpreadsheetML theme index, 0-11tint- lightens (positive) or darkens (negative) the color, in[-1, 1]; 0 means no change (ECMA-376 §18.8.19)- Returns:
- the color
- Throws:
IllegalArgumentException- ifthemeIndexis outside 0-11, ortintis outside[-1, 1]or NaN
-
auto
The automatic color: Excel's "Automatic", which draws as the window-text color (black by default). A cell attribute that has no explicit color reads back as this value.- Returns:
- the shared automatic color
-
parse
Parses a color string. Accepted forms:"#RRGGBB"(opaque),"#AARRGGBB","auto"(any case),"indexed:N"and"theme:I:TINT", whereTINTis the tint times 10000 ("theme:4:-2500"is accent 1, 25 % darker). The leading#is required for hex.- Parameters:
s- the color string, may benull- Returns:
- the color, or
nullwhensisnullor not one of the accepted forms, or its index or tint is out of range
-
fromJson
Decodes the engine's JSON color form: a map such as{"rgb":"#AARRGGBB"},{"indexed":N},{"theme":I,"tint":T}or{"auto":true}, or a string in a form thatparse(String)accepts. Not intended for application code; public only for the SDK's own packages.- Parameters:
value- the decoded JSON value- Returns:
- the color, or
nullfor an unrecognized value - Throws:
IllegalArgumentException- if an indexed or theme value is out of range
-
toJsonValue
The JSON value sent to the engine, in the forms thatfromJson(Object)reads. Not intended for application code; public only for the SDK's own packages.- Returns:
- a new map on each call
-
isRgb
public boolean isRgb()Whether this is a plain ARGB color; thenargb()and the channel readers work. -
isIndexed
public boolean isIndexed()Whether this is a legacy indexed-palette color; thenindexedValue()works. -
isTheme
public boolean isTheme()Whether this is a theme-palette color; thenthemeIndex()andtint()work. -
isAuto
public boolean isAuto()Whether this is the automatic (window-text) color,auto(). -
indexedValue
public int indexedValue()The palette index of an indexed color.- Returns:
- the index, 0-255
- Throws:
IllegalStateException- if this is not an indexed color
-
themeIndex
public int themeIndex()The theme index of a theme color, in the order oftheme(int, double)(0 = light 1, 1 = dark 1).- Returns:
- the index, 0-11
- Throws:
IllegalStateException- if this is not a theme color
-
tint
public double tint()The tint of a theme color.- Returns:
- the tint in
[-1, 1]; 0 when there is none - Throws:
IllegalStateException- if this is not a theme color
-
argb
public int argb()The packed0xAARRGGBBvalue of an RGB color.- Returns:
- the packed value, alpha in the top byte
- Throws:
IllegalStateException- if this is not an RGB color
-
alpha
public int alpha()The alpha channel of an RGB color.- Returns:
- 0-255; 255 is opaque
- Throws:
IllegalStateException- if this is not an RGB color
-
red
public int red()The red channel of an RGB color.- Returns:
- 0-255
- Throws:
IllegalStateException- if this is not an RGB color
-
green
public int green()The green channel of an RGB color.- Returns:
- 0-255
- Throws:
IllegalStateException- if this is not an RGB color
-
blue
public int blue()The blue channel of an RGB color.- Returns:
- 0-255
- Throws:
IllegalStateException- if this is not an RGB color
-
toHex
The hex form of an RGB color, upper case with alpha, e.g."#FFFF0000"for opaque red.- Returns:
"#AARRGGBB"- Throws:
IllegalStateException- if this is not an RGB color
-
equals
-
hashCode
public int hashCode() -
toString
-