KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > drawing > Dgg


1 /*********************************************************************
2 *
3 * Copyright (C) 2003 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff.drawing;
21
22 import java.util.ArrayList JavaDoc;
23 import common.Logger;
24 import jxl.biff.IntegerHelper;
25
26 /**
27  * Dgg record
28  */

29 class Dgg extends EscherAtom
30 {
31   /**
32    * The logger
33    */

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 JavaDoc 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 JavaDoc();
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 JavaDoc();
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     // The max shape id
101
IntegerHelper.getFourBytes(1024 + shapesSaved, data, 0);
102
103     // The number of clusters
104
IntegerHelper.getFourBytes(numClusters, data, 4);
105
106     // The number of shapes saved
107
IntegerHelper.getFourBytes(shapesSaved, data, 8);
108
109     // The number of drawings saved
110
// IntegerHelper.getFourBytes(drawingsSaved, data, 12);
111
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