KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*********************************************************************
2 *
3 * Copyright (C) 2004 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 common.Assert;
23 import common.Logger;
24
25 /**
26  * Class used to concatenate all the data for the various drawing objects
27  * into one continuous stream
28  */

29 public class DrawingData implements EscherStream
30 {
31   /**
32    * The logger
33    */

34   private static Logger logger = Logger.getLogger(DrawingData.class);
35
36   /**
37    * The drawing data
38    */

39   private byte[] drawingData;
40
41   /**
42    * The number of drawings
43    */

44   private int numDrawings;
45
46   /**
47    * Initialized flag
48    */

49   private boolean initialized;
50
51   /**
52    * The spgr container. The contains the SpContainer for each drawing
53    */

54   private EscherRecord[] spgrChildren;
55
56   /**
57    * Constructor
58    */

59   public DrawingData()
60   {
61     numDrawings = 0;
62     drawingData = null;
63     initialized = false;
64   }
65
66   /**
67    * Initialization
68    */

69   private void initialize()
70   {
71     EscherRecordData er = new EscherRecordData(this,0);
72     Assert.verify(er.isContainer());
73     
74     EscherContainer dgContainer = new EscherContainer(er);
75     EscherRecord[] children = dgContainer.getChildren();
76
77     children = dgContainer.getChildren();
78     // Dg dg = (Dg) children[0];
79

80     EscherContainer spgrContainer = null;
81
82     for (int i = 0 ; i < children.length && spgrContainer == null; i++)
83     {
84       EscherRecord child = children[i];
85       if (child.getType() == EscherRecordType.SPGR_CONTAINER)
86       {
87         spgrContainer = (EscherContainer) child;
88       }
89     }
90     Assert.verify(spgrContainer != null);
91
92     spgrChildren = spgrContainer.getChildren();
93     initialized = true;
94   }
95
96   /**
97    * Adds the byte stream to the drawing data
98    *
99    * @param data
100    */

101   public /*??*/void addData(byte[] data)
102   {
103     addRawData(data);
104     numDrawings++;
105   }
106   
107   /**
108    * Adds the data to the array without incrementing the drawing number.
109    * This is used by comments, which for some bizarre and inexplicable
110    * reason split out the data
111    */

112   public /*??*/ void addRawData(byte[] data)
113   {
114     if (drawingData == null)
115     {
116       drawingData = data;
117       return;
118     }
119
120     // Resize the array
121
byte[] newArray = new byte[drawingData.length + data.length];
122     System.arraycopy(drawingData, 0, newArray, 0, drawingData.length);
123     System.arraycopy(data, 0, newArray, drawingData.length, data.length);
124     drawingData = newArray;
125     
126     // Dirty up this object
127
initialized = false;
128   }
129
130   /**
131    * Accessor for the number of drawings
132    *
133    * @return the current count of drawings
134    */

135   final int getNumDrawings()
136   {
137     return numDrawings;
138   }
139
140   /**
141    * Gets the sp container for the specified drawing number
142    *
143    * @param drawingNum the drawing number for which to return the spContainer
144    * @return the spcontainer
145    */

146   EscherContainer getSpContainer(int drawingNum)
147   {
148     if (!initialized)
149     {
150       initialize();
151     }
152
153     EscherContainer spContainer = (EscherContainer)spgrChildren[drawingNum+1];
154
155     Assert.verify(spContainer != null);
156
157     return spContainer;
158   }
159
160   /**
161    * Gets the data which was read in for the drawings
162    *
163    * @return the drawing data
164    */

165   public byte[] getData()
166   {
167     return drawingData;
168   }
169 }
170
Popular Tags