KickJava   Java API By Example, From Geeks To Geeks.

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


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 jxl.biff.IntegerHelper;
23
24 /**
25  * The Drawing Group
26  */

27 class Dg extends EscherAtom
28 {
29   /**
30    * The data
31    */

32   private byte[] data;
33
34   /**
35    * The id of this drawing
36    */

37   private int drawingId;
38
39   /**
40    * The number of shapes
41    */

42   private int shapeCount;
43
44   /**
45    * The seed for drawing ids
46    */

47   private int seed;
48
49   /**
50    * Constructor invoked when reading in an escher stream
51    *
52    * @param erd the escher record
53    */

54   public Dg(EscherRecordData erd)
55   {
56     super(erd);
57     drawingId = getInstance();
58
59     byte[] bytes = getBytes();
60     shapeCount = IntegerHelper.getInt(bytes[0], bytes[1], bytes[2], bytes[3]);
61     seed = IntegerHelper.getInt(bytes[4], bytes[5], bytes[6], bytes[7]);
62   }
63
64   /**
65    * Constructor invoked when writing out an escher stream
66    *
67    * @param numDrawings the number of drawings
68    */

69   public Dg(int numDrawings)
70   {
71     super(EscherRecordType.DG);
72     drawingId = 1;
73     shapeCount = numDrawings+1;
74     seed = 1024+shapeCount+1;
75     setInstance(drawingId);
76   }
77
78   /**
79    * Gets the drawing id
80    *
81    * @return the drawing id
82    */

83   public int getDrawingId()
84   {
85     return drawingId;
86   }
87
88   /**
89    * Used to generate the drawing data
90    *
91    * @return the data
92    */

93   byte[] getData()
94   {
95     data = new byte[8];
96     IntegerHelper.getFourBytes(shapeCount, data, 0);
97     IntegerHelper.getFourBytes(seed, data, 4);
98
99     return setHeaderData(data);
100   }
101 }
102
Popular Tags