1 19 20 package jxl.biff.drawing; 21 22 import java.util.ArrayList ; 23 import common.Logger; 24 import jxl.biff.IntegerHelper; 25 26 29 class Dgg extends EscherAtom 30 { 31 34 private static Logger logger = Logger.getLogger(Dgg.class); 35 36 private byte[] data; 37 private int numClusters; 38 private int maxShapeId; 39 private int shapesSaved; 40 private int drawingsSaved; 41 42 private ArrayList clusters; 43 44 final static class Cluster 45 { 46 int drawingGroupId; 47 int shapeIdsUsed; 48 49 Cluster(int dgId, int sids) 50 { 51 drawingGroupId = dgId; 52 shapeIdsUsed = sids; 53 } 54 } 55 56 public Dgg(EscherRecordData erd) 57 { 58 super(erd); 59 clusters = new ArrayList (); 60 byte[] bytes = getBytes(); 61 maxShapeId = IntegerHelper.getInt 62 (bytes[0], bytes[1], bytes[2], bytes[3]); 63 numClusters = IntegerHelper.getInt 64 (bytes[4], bytes[5], bytes[6], bytes[7]); 65 shapesSaved = IntegerHelper.getInt 66 (bytes[8], bytes[9], bytes[10], bytes[11]); 67 drawingsSaved = IntegerHelper.getInt 68 (bytes[12], bytes[13], bytes[14], bytes[15]); 69 70 int pos = 16; 71 for (int i = 0 ; i < numClusters ; i++) 72 { 73 int dgId = IntegerHelper.getInt(bytes[pos], bytes[pos+1]); 74 int sids = IntegerHelper.getInt(bytes[pos+2], bytes[pos+3]); 75 Cluster c = new Cluster(dgId, sids); 76 clusters.add(c); 77 pos += 4; 78 } 79 } 80 81 public Dgg(int numShapes, int numDrawings) 82 { 83 super(EscherRecordType.DGG); 84 shapesSaved = numShapes; 85 drawingsSaved = numDrawings; 86 clusters = new ArrayList (); 87 } 88 89 void addCluster(int dgid, int sids) 90 { 91 Cluster c = new Cluster(dgid, sids); 92 clusters.add(c); 93 } 94 95 byte[] getData() 96 { 97 numClusters = clusters.size(); 98 data = new byte[16 + numClusters * 4]; 99 100 IntegerHelper.getFourBytes(1024 + shapesSaved, data, 0); 102 103 IntegerHelper.getFourBytes(numClusters, data, 4); 105 106 IntegerHelper.getFourBytes(shapesSaved, data, 8); 108 109 IntegerHelper.getFourBytes(1, data, 12); 112 113 int pos = 16; 114 for (int i = 0 ; i < numClusters ; i++) 115 { 116 Cluster c = (Cluster) clusters.get(i); 117 IntegerHelper.getTwoBytes(c.drawingGroupId, data, pos); 118 IntegerHelper.getTwoBytes(c.shapeIdsUsed, data, pos+2); 119 pos += 4; 120 } 121 122 return setHeaderData(data); 123 } 124 125 int getShapesSaved() 126 { 127 return shapesSaved; 128 } 129 130 int getDrawingsSaved() 131 { 132 return drawingsSaved; 133 } 134 135 Cluster getCluster(int i) 136 { 137 return (Cluster) clusters.get(i); 138 } 139 } 140 | Popular Tags |