FileDocCategorySizeDatePackage
StyleRecord.javaAPI DocApache Poi 3.0.110409Mon Jan 01 12:39:40 GMT 2007org.apache.poi.hssf.record

StyleRecord

public class StyleRecord extends Record
Title: Style Record

Description: Describes a builtin to the gui or user defined style

REFERENCE: PG 390 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)

author
Andrew C. Oliver (acoliver at apache dot org)
author
aviks : string fixes for UserDefined Style
version
2.0-pre

Fields Summary
public static final short
sid
public static final short
STYLE_USER_DEFINED
public static final short
STYLE_BUILT_IN
private short
field_1_xf_index
private byte
field_2_builtin_style
private byte
field_3_outline_style_level
private short
field_2_name_length
private byte
field_3_string_options
private BitField
fHighByte
private String
field_4_name
Constructors Summary
public StyleRecord()


     
    
    
public StyleRecord(RecordInputStream in)
Constructs a Style record and sets its fields appropriately.

param
id id must be 0x293 or an exception will be throw upon validation
param
size the size of the data area of the record
param
data data of the record (should not contain sid/len)

        super(in);
    
Methods Summary
protected voidfillFields(org.apache.poi.hssf.record.RecordInputStream in)

        fHighByte = BitFieldFactory.getInstance(0x01); //have to init here, since we are being called
                                        //from super, and class level init hasnt been done. 
        field_1_xf_index = in.readShort();
        if (getType() == STYLE_BUILT_IN)
        {
            field_2_builtin_style       = in.readByte();
            field_3_outline_style_level = in.readByte();
        }
        else if (getType() == STYLE_USER_DEFINED)
        {
            field_2_name_length = in.readShort();
            field_3_string_options = in.readByte();
            
            byte[] string = in.readRemainder();
            if (fHighByte.isSet(field_3_string_options)) {
                field_4_name= StringUtil.getFromUnicodeBE(string, 0, field_2_name_length);
            }else {
                field_4_name=StringUtil.getFromCompressedUnicode(string, 0, field_2_name_length);
            }
        }

        // todo sanity check exception to make sure we're one or the other
    
public bytegetBuiltin()
if this is a builtin style get the number of the built in style

return
builtin style number (0-7)

        return field_2_builtin_style;
    
public shortgetIndex()
get the entire index field (including the type) (see bit getters that reference this method)

return
bitmask

        return field_1_xf_index;
    
public java.lang.StringgetName()
get the style's name

return
name of the style
see
#getNameLength()

        return field_4_name;
    
public shortgetNameLength()
if this is a user defined record get the length of the style name

return
length of the style's name
see
#getName()

        return field_2_name_length;
    
public bytegetOutlineStyleLevel()
get the row or column level of the style (if builtin 1||2)

        return field_3_outline_style_level;
    
public intgetRecordSize()

        int retval;

        if (getType() == STYLE_BUILT_IN)
        {
            retval = 8;
        }
        else
        {
             if (fHighByte.isSet(field_3_string_options))  {
                 retval= 9+2*getNameLength();
             }else {
                retval = 9 + getNameLength();
             }
        }
        return retval;
    
public shortgetSid()

        return sid;
    
public shortgetType()
get the type of the style (builtin or user-defined)

see
#STYLE_USER_DEFINED
see
#STYLE_BUILT_IN
return
type of style (userdefined/builtin)
see
#getIndex()

        return ( short ) ((field_1_xf_index & 0x8000) >> 15);
    
public shortgetXFIndex()
get the actual index of the style extended format record

see
#getIndex()
return
index of the xf record

        return ( short ) (field_1_xf_index & 0x1FFF);
    
public intserialize(int offset, byte[] data)

        LittleEndian.putShort(data, 0 + offset, sid);
        if (getType() == STYLE_BUILT_IN)
        {
            LittleEndian.putShort(data, 2 + offset,
                                  (( short ) 0x04));   // 4 bytes (8 total)
        }
        else
        {
            LittleEndian.putShort(data, 2 + offset,
                                  (( short ) (getRecordSize()-4)));
        }
        LittleEndian.putShort(data, 4 + offset, getIndex());
        if (getType() == STYLE_BUILT_IN)
        {
            data[ 6 + offset ] = getBuiltin();
            data[ 7 + offset ] = getOutlineStyleLevel();
        }
        else
        {
            LittleEndian.putShort(data, 6 + offset , getNameLength());
            data[8+offset]=this.field_3_string_options;
            StringUtil.putCompressedUnicode(getName(), data, 9 + offset);
        }
        return getRecordSize();
    
public voidsetBuiltin(byte builtin)
if this is a builtin style set teh number of the built in style

param
builtin style number (0-7)

        field_2_builtin_style = builtin;
    
private shortsetField(int fieldValue, int new_value, int mask, int shiftLeft)

        return ( short ) ((fieldValue & ~mask)
                          | ((new_value << shiftLeft) & mask));
    
public voidsetIndex(short index)
set the entire index field (including the type) (see bit setters that reference this method)

param
index bitmask

        field_1_xf_index = index;
    
public voidsetName(java.lang.String name)
set the style's name

param
name of the style
see
#setNameLength(byte)

        field_4_name = name;
        //TODO set name length and string options
    
public voidsetNameLength(byte length)
if this is a user defined record set the length of the style name

param
length of the style's name
see
#setName(String)

        field_2_name_length = length;
    
public voidsetOutlineStyleLevel(byte level)
set the row or column level of the style (if builtin 1||2)

        field_3_outline_style_level = level;
    
public voidsetType(short type)
set the type of the style (builtin or user-defined)

see
#STYLE_USER_DEFINED
see
#STYLE_BUILT_IN
param
type of style (userdefined/builtin)
see
#setIndex(short)

        field_1_xf_index = setField(field_1_xf_index, type, 0x8000, 15);
    
public voidsetXFIndex(short index)
set the actual index of the style extended format record

see
#setIndex(short)
param
index of the xf record

        field_1_xf_index = setField(field_1_xf_index, index, 0x1FFF, 0);
    
public java.lang.StringtoString()

        StringBuffer buffer = new StringBuffer();

        buffer.append("[STYLE]\n");
        buffer.append("    .xf_index_raw    = ")
            .append(Integer.toHexString(getIndex())).append("\n");
        buffer.append("        .type        = ")
            .append(Integer.toHexString(getType())).append("\n");
        buffer.append("        .xf_index    = ")
            .append(Integer.toHexString(getXFIndex())).append("\n");
        if (getType() == STYLE_BUILT_IN)
        {
            buffer.append("    .builtin_style   = ")
                .append(Integer.toHexString(getBuiltin())).append("\n");
            buffer.append("    .outline_level   = ")
                .append(Integer.toHexString(getOutlineStyleLevel()))
                .append("\n");
        }
        else if (getType() == STYLE_USER_DEFINED)
        {
            buffer.append("    .name_length     = ")
                .append(Integer.toHexString(getNameLength())).append("\n");
            buffer.append("    .name            = ").append(getName())
                .append("\n");
        }
        buffer.append("[/STYLE]\n");
        return buffer.toString();
    
protected voidvalidateSid(short id)

        if (id != sid)
        {
            throw new RecordFormatException("NOT A STYLE RECORD");
        }