Top Description Inners Fields Constructors Methods
org.apache.poi.hssf.usermodel

public final Class HSSFPalette

extends Object
Class Inheritance
Imports
java.util.Locale, org.apache.poi.hssf.record.PaletteRecord, org.apache.poi.hssf.util.HSSFColor, .HSSFColor.HSSFColorPredefined, org.apache.poi.util.StringUtil

Represents a workbook color palette. Internally, the XLS format refers to colors using an offset into the palette record. Thus, the first color in the palette has the index 0x8, the second has the index 0x9, etc. through 0x40

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private PaletteRecord

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public HSSFColor

Returns:

The new custom color.
addColor
(byte
The red component
red
,
byte
The green component
green
,
byte
The blue component
blue
)

Adds a new color into an empty color slot.

public HSSFColor

Returns:

the color, or null if the color does not exist in this palette
findColor
(byte
the RGB red component, between 0 and 255 inclusive
red
,
byte
the RGB green component, between 0 and 255 inclusive
green
,
byte
the RGB blue component, between 0 and 255 inclusive
blue
)

Finds the first occurrence of a given color

public HSSFColor

Returns:

The closest color or null if there are no custom colors currently defined.
findSimilarColor
(byte
The red component of the color to match.
red
,
byte
The green component of the color to match.
green
,
byte
The blue component of the color to match.
blue
)

Finds the closest matching color in the custom palette.

public HSSFColor

Returns:

The closest color or null if there are no custom colors currently defined.
findSimilarColor
(int
The red component of the color to match.
red
,
int
The green component of the color to match.
green
,
int
The blue component of the color to match.
blue
)

Finds the closest matching color in the custom palette.

public HSSFColor

Returns:

the color, or null if the index is not populated
getColor
(short
the palette index, between 0x8 to 0x40 inclusive
index
)

Retrieves the color at a given index

public HSSFColor

Returns:

the color, or null if the index is not populated
getColor
(int
the palette index, between 0x8 to 0x40 inclusive
index
)

Retrieves the color at a given index

public void
setColorAtIndex(short
the palette index, between 0x8 to 0x40 inclusive
index
,
byte
the RGB red component, between 0 and 255 inclusive
red
,
byte
the RGB green component, between 0 and 255 inclusive
green
,
byte
the RGB blue component, between 0 and 255 inclusive
blue
)

Sets the color at the given offset

private int
unsignedInt(byte b)

Turn a byte of between -127 and 127 into something between 0 and 255, so distance calculations work as expected.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_paletteback to summary
private PaletteRecord _palette

Constructor Detail

HSSFPaletteback to summary
protected HSSFPalette(PaletteRecord palette)

Method Detail

addColorback to summary
public HSSFColor addColor(byte red, byte green, byte blue)

Adds a new color into an empty color slot.

Parameters
red:byte

The red component

green:byte

The green component

blue:byte

The blue component

Returns:HSSFColor

The new custom color.

Exceptions
IllegalStateException:
if there are more more free color indexes.
findColorback to summary
public HSSFColor findColor(byte red, byte green, byte blue)

Finds the first occurrence of a given color

Parameters
red:byte

the RGB red component, between 0 and 255 inclusive

green:byte

the RGB green component, between 0 and 255 inclusive

blue:byte

the RGB blue component, between 0 and 255 inclusive

Returns:HSSFColor

the color, or null if the color does not exist in this palette

findSimilarColorback to summary
public HSSFColor findSimilarColor(byte red, byte green, byte blue)

Finds the closest matching color in the custom palette. The method for finding the distance between the colors is fairly primative.

Parameters
red:byte

The red component of the color to match.

green:byte

The green component of the color to match.

blue:byte

The blue component of the color to match.

Returns:HSSFColor

The closest color or null if there are no custom colors currently defined.

findSimilarColorback to summary
public HSSFColor findSimilarColor(int red, int green, int blue)

Finds the closest matching color in the custom palette. The method for finding the distance between the colors is fairly primative.

Parameters
red:int

The red component of the color to match.

green:int

The green component of the color to match.

blue:int

The blue component of the color to match.

Returns:HSSFColor

The closest color or null if there are no custom colors currently defined.

getColorback to summary
public HSSFColor getColor(short index)

Retrieves the color at a given index

Parameters
index:short

the palette index, between 0x8 to 0x40 inclusive

Returns:HSSFColor

the color, or null if the index is not populated

getColorback to summary
public HSSFColor getColor(int index)

Retrieves the color at a given index

Parameters
index:int

the palette index, between 0x8 to 0x40 inclusive

Returns:HSSFColor

the color, or null if the index is not populated

setColorAtIndexback to summary
public void setColorAtIndex(short index, byte red, byte green, byte blue)

Sets the color at the given offset

Parameters
index:short

the palette index, between 0x8 to 0x40 inclusive

red:byte

the RGB red component, between 0 and 255 inclusive

green:byte

the RGB green component, between 0 and 255 inclusive

blue:byte

the RGB blue component, between 0 and 255 inclusive

unsignedIntback to summary
private int unsignedInt(byte b)

Turn a byte of between -127 and 127 into something between 0 and 255, so distance calculations work as expected.

org.apache.poi.hssf.usermodel back to summary

private final Class HSSFPalette.CustomColor

extends HSSFColor
Class Inheritance

Field Summary

Modifier and TypeField and Description
private byte
private short
private byte
private byte

Constructor Summary

AccessConstructor and Description
public
CustomColor(short byteOffset, byte[] colors)

private
CustomColor(short byteOffset, byte red, byte green, byte blue)

Method Summary

Modifier and TypeMethod and Description
private String
getGnumericPart(byte color)

public String
getHexString()

Overrides org.apache.poi.hssf.util.HSSFColor.getHexString.

returns colon-delimited hex string "0:0:0"

public short
getIndex()

Overrides org.apache.poi.hssf.util.HSSFColor.getIndex.

returns color standard palette index

public short[]
getTriplet()

Overrides org.apache.poi.hssf.util.HSSFColor.getTriplet.

returns RGB triplet (0, 0, 0)

Inherited from org.apache.poi.hssf.util.HSSFColor:
equalsgetIndex2getIndexHashgetMutableIndexHashgetTripletHashhashCodetoHSSFColor

Field Detail

_blueback to summary
private byte _blue
_byteOffsetback to summary
private short _byteOffset
_greenback to summary
private byte _green
_redback to summary
private byte _red

Constructor Detail

CustomColorback to summary
public CustomColor(short byteOffset, byte[] colors)
CustomColorback to summary
private CustomColor(short byteOffset, byte red, byte green, byte blue)

Method Detail

getGnumericPartback to summary
private String getGnumericPart(byte color)
getHexStringback to summary
public String getHexString()

Overrides org.apache.poi.hssf.util.HSSFColor.getHexString.

Doc from org.apache.poi.hssf.util.HSSFColor.getHexString.

returns colon-delimited hex string "0:0:0"

Returns:String

a hex string exactly like a gnumeric triplet

Annotations
@Override
getIndexback to summary
public short getIndex()

Overrides org.apache.poi.hssf.util.HSSFColor.getIndex.

Doc from org.apache.poi.hssf.util.HSSFColor.getIndex.

returns color standard palette index

Returns:short

index to the standard palette

Annotations
@Override
getTripletback to summary
public short[] getTriplet()

Overrides org.apache.poi.hssf.util.HSSFColor.getTriplet.

Doc from org.apache.poi.hssf.util.HSSFColor.getTriplet.

returns RGB triplet (0, 0, 0)

Returns:short[]

triplet representation like that in Excel

Annotations
@Override