FileDocCategorySizeDatePackage
EscherDggRecord.javaAPI DocApache Poi 3.0.19453Mon Jan 01 12:39:40 GMT 2007org.apache.poi.ddf

EscherDggRecord

public class EscherDggRecord extends EscherRecord
This record defines the drawing groups used for a particular sheet.

Fields Summary
public static final short
RECORD_ID
public static final String
RECORD_DESCRIPTION
private int
field_1_shapeIdMax
private int
field_3_numShapesSaved
private int
field_4_drawingsSaved
private FileIdCluster[]
field_5_fileIdClusters
Constructors Summary
Methods Summary
public voidaddCluster(int dgId, int numShapedUsed)

        List clusters = new ArrayList(Arrays.asList(field_5_fileIdClusters));
        clusters.add(new FileIdCluster(dgId, numShapedUsed));
        Collections.sort(clusters, new Comparator()
        {
            public int compare( Object o1, Object o2 )
            {
                FileIdCluster f1 = (FileIdCluster) o1;
                FileIdCluster f2 = (FileIdCluster) o2;
                if (f1.getDrawingGroupId() == f2.getDrawingGroupId())
                    return 0;
                if (f1.getDrawingGroupId() < f2.getDrawingGroupId())
                    return -1;
                else
                    return +1;
            }
        } );
        field_5_fileIdClusters = (FileIdCluster[]) clusters.toArray( new FileIdCluster[clusters.size()] );
    
public intfillFields(byte[] data, int offset, org.apache.poi.ddf.EscherRecordFactory recordFactory)
This method deserializes the record from a byte array.

param
data The byte array containing the escher record information
param
offset The starting offset into data.
param
recordFactory May be null since this is not a container record.
return
The number of bytes read from the byte array.

        int bytesRemaining = readHeader( data, offset );
        int pos            = offset + 8;
        int size           = 0;
        field_1_shapeIdMax     =  LittleEndian.getInt( data, pos + size );size+=4;
        int field_2_numIdClusters  =  LittleEndian.getInt( data, pos + size );size+=4;
        field_3_numShapesSaved =  LittleEndian.getInt( data, pos + size );size+=4;
        field_4_drawingsSaved  =  LittleEndian.getInt( data, pos + size );size+=4;
        field_5_fileIdClusters = new FileIdCluster[(bytesRemaining-size) / 8];  // Can't rely on field_2_numIdClusters
        for (int i = 0; i < field_5_fileIdClusters.length; i++)
        {
            field_5_fileIdClusters[i] = new FileIdCluster(LittleEndian.getInt( data, pos + size ), LittleEndian.getInt( data, pos + size + 4 ));
            size += 8;
        }
        bytesRemaining         -= size;
        if (bytesRemaining != 0)
            throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
        return 8 + size + bytesRemaining;
    
public intgetDrawingsSaved()

        return field_4_drawingsSaved;
    
public org.apache.poi.ddf.EscherDggRecord$FileIdCluster[]getFileIdClusters()

        return field_5_fileIdClusters;
    
public intgetNumIdClusters()
Number of id clusters + 1

        return field_5_fileIdClusters.length + 1;
    
public intgetNumShapesSaved()

        return field_3_numShapesSaved;
    
public shortgetRecordId()

        return RECORD_ID;
    
public java.lang.StringgetRecordName()
The short name for this record

        return "Dgg";
    
public intgetRecordSize()
Returns the number of bytes that are required to serialize this record.

return
Number of bytes

        return 8 + 16 + (8 * field_5_fileIdClusters.length);
    
public intgetShapeIdMax()

        return field_1_shapeIdMax;
    
public intserialize(int offset, byte[] data, org.apache.poi.ddf.EscherSerializationListener listener)
This method serializes this escher record into a byte array.

param
offset The offset into data to start writing the record data to.
param
data The byte array to serialize to.
param
listener A listener to retrieve start and end callbacks. Use a NullEscherSerailizationListener to ignore these events.
return
The number of bytes written.
see
NullEscherSerializationListener

        listener.beforeRecordSerialize( offset, getRecordId(), this );

        int pos = offset;
        LittleEndian.putShort( data, pos, getOptions() );     pos += 2;
        LittleEndian.putShort( data, pos, getRecordId() );    pos += 2;
        int remainingBytes = getRecordSize() - 8;
        LittleEndian.putInt( data, pos, remainingBytes );              pos += 4;

        LittleEndian.putInt( data, pos, field_1_shapeIdMax );          pos += 4;
        LittleEndian.putInt( data, pos, getNumIdClusters() );          pos += 4;
        LittleEndian.putInt( data, pos, field_3_numShapesSaved );      pos += 4;
        LittleEndian.putInt( data, pos, field_4_drawingsSaved );       pos += 4;
        for ( int i = 0; i < field_5_fileIdClusters.length; i++ )
        {
            LittleEndian.putInt( data, pos, field_5_fileIdClusters[i].field_1_drawingGroupId );   pos += 4;
            LittleEndian.putInt( data, pos, field_5_fileIdClusters[i].field_2_numShapeIdsUsed );  pos += 4;
        }

        listener.afterRecordSerialize( pos, getRecordId(), getRecordSize(), this );
        return getRecordSize();
    
public voidsetDrawingsSaved(int field_4_drawingsSaved)

        this.field_4_drawingsSaved = field_4_drawingsSaved;
    
public voidsetFileIdClusters(org.apache.poi.ddf.EscherDggRecord$FileIdCluster[] field_5_fileIdClusters)

        this.field_5_fileIdClusters = field_5_fileIdClusters;
    
public voidsetNumShapesSaved(int field_3_numShapesSaved)

        this.field_3_numShapesSaved = field_3_numShapesSaved;
    
public voidsetShapeIdMax(int field_1_shapeIdMax)
The maximum is actually the next available. shape id.

        this.field_1_shapeIdMax = field_1_shapeIdMax;
    
public java.lang.StringtoString()

        String nl = System.getProperty("line.separator");

//        String extraData;
//        ByteArrayOutputStream b = new ByteArrayOutputStream();
//        try
//        {
//            HexDump.dump(this.remainingData, 0, b, 0);
//            extraData = b.toString();
//        }
//        catch ( Exception e )
//        {
//            extraData = "error";
//        }
        StringBuffer field_5_string = new StringBuffer();
        for ( int i = 0; i < field_5_fileIdClusters.length; i++ )
        {
            field_5_string.append("  DrawingGroupId").append(i+1).append(": ");
            field_5_string.append(field_5_fileIdClusters[i].field_1_drawingGroupId);
            field_5_string.append(nl);
            field_5_string.append("  NumShapeIdsUsed").append(i+1).append(": ");
            field_5_string.append(field_5_fileIdClusters[i].field_2_numShapeIdsUsed);
            field_5_string.append(nl);
        }
        return getClass().getName() + ":" + nl +
                "  RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
                "  Options: 0x" + HexDump.toHex(getOptions()) + nl +
                "  ShapeIdMax: " + field_1_shapeIdMax + nl +
                "  NumIdClusters: " + getNumIdClusters() + nl +
                "  NumShapesSaved: " + field_3_numShapesSaved + nl +
                "  DrawingsSaved: " + field_4_drawingsSaved + nl +
                "" + field_5_string.toString();