KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
23  * The base class for all escher records. This class contains
24  * the common header data and is basically a wrapper for the EscherRecordData
25  * object
26  */

27 abstract class EscherRecord
28 {
29   /**
30    * The escher data
31    */

32   // private EscherRecordData data;
33
protected EscherRecordData data;
34
35   /**
36    * The length of the escher header on all records
37    */

38   protected final static int HEADER_LENGTH = 8;
39
40   /**
41    * Constructor
42    *
43    * @param erd the data
44    */

45   protected EscherRecord(EscherRecordData erd)
46   {
47     data = erd;
48   }
49
50   /**
51    * Constructor
52    *
53    * @param type the type
54    */

55   protected EscherRecord(EscherRecordType type)
56   {
57     data = new EscherRecordData(type);
58   }
59
60   /**
61    * Identifies whether this item is a container
62    *
63    * @param cont TRUE if this is a container, FALSE otherwise
64    */

65   protected void setContainer(boolean cont)
66   {
67     data.setContainer(cont);
68   }
69
70   /**
71    * Gets the entire length of the record, including the header
72    *
73    * @return the length of the record, including the header data
74    */

75   public int getLength()
76   {
77     return data.getLength() + HEADER_LENGTH;
78   }
79
80   /**
81    * Accessor for the escher stream
82    *
83    * @return the escher stream
84    */

85   protected final EscherStream getEscherStream()
86   {
87     return data.getEscherStream();
88   }
89
90   /**
91    * The position of this escher record in the stream
92    *
93    * @return the position
94    */

95   protected final int getPos()
96   {
97     return data.getPos();
98   }
99
100   /**
101    * Accessor for the instance
102    *
103    * @return the instance
104    */

105   protected final int getInstance()
106   {
107     return data.getInstance();
108   }
109
110   /**
111    * Sets the instance number when writing out the escher data
112    *
113    * @param i the instance
114    */

115   protected final void setInstance(int i)
116   {
117     data.setInstance(i);
118   }
119
120   /**
121    * Sets the version when writing out the escher data
122    *
123    * @param v the version
124    */

125   protected final void setVersion (int v)
126   {
127     data.setVersion(v);
128   }
129
130   /**
131    * Accessor for the escher type
132    *
133    * @return the type
134    */

135   public EscherRecordType getType()
136   {
137     return data.getType();
138   }
139
140   /**
141    * Abstract method used to retrieve the generated escher data when writing
142    * out image information
143    *
144    * @return the escher data
145    */

146   abstract byte[] getData();
147
148   /**
149    * Prepends the standard header data to the first eight bytes of the array
150    * and returns it
151    */

152   final byte[] setHeaderData(byte[] d)
153   {
154     return data.setHeaderData(d);
155   }
156
157   /**
158    * Gets the data that was read in, excluding the header data
159    *
160    * @return the bytes read in, excluding the header data
161    */

162   byte[] getBytes()
163   {
164     return data.getBytes();
165   }
166
167   /**
168    * Accessor for the stream length
169    *
170    * @return the stream length
171    */

172   protected int getStreamLength()
173   {
174     return data.getStreamLength();
175   }
176 }
177
Popular Tags