PaletteRecordpublic class PaletteRecord extends Record PaletteRecord - Supports custom palettes. |
Fields Summary |
---|
public static final short | sid | public static final byte | STANDARD_PALETTE_SIZEThe standard size of an XLS palette | public static final short | FIRST_COLOR_INDEXThe byte index of the first color | private short | field_1_numcolors | private List | field_2_colors |
Constructors Summary |
---|
public PaletteRecord()
createDefaultPalette();
| public PaletteRecord(RecordInputStream in)Constructs a PaletteRecord record and sets its fields appropriately.
super(in);
|
Methods Summary |
---|
private void | createDefaultPalette()Creates the default palette as PaletteRecord binary data
field_1_numcolors = STANDARD_PALETTE_SIZE;
field_2_colors = new ArrayList(field_1_numcolors);
byte[] palette = new byte[]
{
(byte) 0, (byte) 0, (byte) 0, (byte) 0, //color 0...
(byte) 255, (byte) 255, (byte) 255, (byte) 0,
(byte) 255, (byte) 0, (byte) 0, (byte) 0,
(byte) 0, (byte) 255, (byte) 0, (byte) 0,
(byte) 0, (byte) 0, (byte) 255, (byte) 0,
(byte) 255, (byte) 255, (byte) 0, (byte) 0,
(byte) 255, (byte) 0, (byte) 255, (byte) 0,
(byte) 0, (byte) 255, (byte) 255, (byte) 0,
(byte) 128, (byte) 0, (byte) 0, (byte) 0,
(byte) 0, (byte) 128, (byte) 0, (byte) 0,
(byte) 0, (byte) 0, (byte) 128, (byte) 0,
(byte) 128, (byte) 128, (byte) 0, (byte) 0,
(byte) 128, (byte) 0, (byte) 128, (byte) 0,
(byte) 0, (byte) 128, (byte) 128, (byte) 0,
(byte) 192, (byte) 192, (byte) 192, (byte) 0,
(byte) 128, (byte) 128, (byte) 128, (byte) 0,
(byte) 153, (byte) 153, (byte) 255, (byte) 0,
(byte) 153, (byte) 51, (byte) 102, (byte) 0,
(byte) 255, (byte) 255, (byte) 204, (byte) 0,
(byte) 204, (byte) 255, (byte) 255, (byte) 0,
(byte) 102, (byte) 0, (byte) 102, (byte) 0,
(byte) 255, (byte) 128, (byte) 128, (byte) 0,
(byte) 0, (byte) 102, (byte) 204, (byte) 0,
(byte) 204, (byte) 204, (byte) 255, (byte) 0,
(byte) 0, (byte) 0, (byte) 128, (byte) 0,
(byte) 255, (byte) 0, (byte) 255, (byte) 0,
(byte) 255, (byte) 255, (byte) 0, (byte) 0,
(byte) 0, (byte) 255, (byte) 255, (byte) 0,
(byte) 128, (byte) 0, (byte) 128, (byte) 0,
(byte) 128, (byte) 0, (byte) 0, (byte) 0,
(byte) 0, (byte) 128, (byte) 128, (byte) 0,
(byte) 0, (byte) 0, (byte) 255, (byte) 0,
(byte) 0, (byte) 204, (byte) 255, (byte) 0,
(byte) 204, (byte) 255, (byte) 255, (byte) 0,
(byte) 204, (byte) 255, (byte) 204, (byte) 0,
(byte) 255, (byte) 255, (byte) 153, (byte) 0,
(byte) 153, (byte) 204, (byte) 255, (byte) 0,
(byte) 255, (byte) 153, (byte) 204, (byte) 0,
(byte) 204, (byte) 153, (byte) 255, (byte) 0,
(byte) 255, (byte) 204, (byte) 153, (byte) 0,
(byte) 51, (byte) 102, (byte) 255, (byte) 0,
(byte) 51, (byte) 204, (byte) 204, (byte) 0,
(byte) 153, (byte) 204, (byte) 0, (byte) 0,
(byte) 255, (byte) 204, (byte) 0, (byte) 0,
(byte) 255, (byte) 153, (byte) 0, (byte) 0,
(byte) 255, (byte) 102, (byte) 0, (byte) 0,
(byte) 102, (byte) 102, (byte) 153, (byte) 0,
(byte) 150, (byte) 150, (byte) 150, (byte) 0,
(byte) 0, (byte) 51, (byte) 102, (byte) 0,
(byte) 51, (byte) 153, (byte) 102, (byte) 0,
(byte) 0, (byte) 51, (byte) 0, (byte) 0,
(byte) 51, (byte) 51, (byte) 0, (byte) 0,
(byte) 153, (byte) 51, (byte) 0, (byte) 0,
(byte) 153, (byte) 51, (byte) 102, (byte) 0,
(byte) 51, (byte) 51, (byte) 153, (byte) 0,
(byte) 51, (byte) 51, (byte) 51, (byte) 0
};
for (int k = 0; k < field_1_numcolors; k++) {
field_2_colors.add(new PColor(
palette[k*4],
palette[k*4+1],
palette[k*4+2]
)
);
}
| protected void | fillFields(org.apache.poi.hssf.record.RecordInputStream in)
field_1_numcolors = in.readShort();
field_2_colors = new ArrayList(field_1_numcolors);
for (int k = 0; k < field_1_numcolors; k++) {
field_2_colors.add(new PColor(
in.readByte(),
in.readByte(),
in.readByte()
)
);
//Read unused byte.
in.readByte();
}
| public byte[] | getColor(short byteIndex)Returns the color value at a given index
int i = byteIndex - FIRST_COLOR_INDEX;
if (i < 0 || i >= field_2_colors.size())
{
return null;
}
PColor color = (PColor) field_2_colors.get(i);
return new byte[] { color.red, color.green, color.blue };
| public int | getRecordSize()
return 4 + 2 + (field_1_numcolors * 4);
| public short | getSid()
return sid;
| public int | serialize(int offset, byte[] data)
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, (short) (getRecordSize() - 4));
LittleEndian.putShort(data, 4 + offset, field_1_numcolors);
for (int k = 0; k < field_1_numcolors; k++) {
PColor c = (PColor)field_2_colors.get(k);
c.serialize(data, (6+offset+(k*4)));
}
return getRecordSize();
| public void | setColor(short byteIndex, byte red, byte green, byte blue)Sets the color value at a given index
If the given index is greater than the current last color index,
then black is inserted at every index required to make the palette continuous.
int i = byteIndex - FIRST_COLOR_INDEX;
if (i < 0 || i >= STANDARD_PALETTE_SIZE)
{
return;
}
while (field_2_colors.size() <= i)
{
field_2_colors.add(new PColor((byte) 0, (byte) 0, (byte) 0));
}
PColor custColor = new PColor(red, green, blue);
field_2_colors.set(i, custColor);
| public java.lang.String | toString()
StringBuffer buffer = new StringBuffer();
buffer.append("[PALETTE]\n");
buffer.append(" numcolors = ").append(field_1_numcolors)
.append('\n");
for (int k = 0; k < field_1_numcolors; k++) {
PColor c = (PColor) field_2_colors.get(k);
buffer.append("* colornum = ").append(k)
.append('\n");
buffer.append(c.toString());
buffer.append("/*colornum = ").append(k)
.append('\n");
}
buffer.append("[/PALETTE]\n");
return buffer.toString();
| protected void | validateSid(short id)
if (id != sid)
{
throw new RecordFormatException("NOT An Palette RECORD");
}
|
|