KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > GutsRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Title: Guts Record <P>
25  * Description: Row/column gutter sizes <P>
26  * REFERENCE: PG 320 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
27  * @author Andrew C. Oliver (acoliver at apache dot org)
28  * @author Jason Height (jheight at chariot dot net dot au)
29  * @version 2.0-pre
30  */

31
32 public class GutsRecord
33     extends Record
34 {
35     public final static short sid = 0x80;
36     private short field_1_left_row_gutter; // size of the row gutter to the left of the rows
37
private short field_2_top_col_gutter; // size of the column gutter above the columns
38
private short field_3_row_level_max; // maximum outline level for row gutters
39
private short field_4_col_level_max; // maximum outline level for column gutters
40

41     public GutsRecord()
42     {
43     }
44
45     /**
46      * Constructs a Guts record and sets its fields appropriately.
47      *
48      * @param id id must be 0x80 or an exception will be throw upon validation
49      * @param size the size of the data area of the record
50      * @param data data of the record (should not contain sid/len)
51      */

52
53     public GutsRecord(short id, short size, byte [] data)
54     {
55         super(id, size, data);
56     }
57
58     /**
59      * Constructs a Guts record and sets its fields appropriately.
60      *
61      * @param id id must be 0x80 or an exception will be throw upon validation
62      * @param size the size of the data area of the record
63      * @param data data of the record (should not contain sid/len)
64      * @param offset of the record's data
65      */

66
67     public GutsRecord(short id, short size, byte [] data, int offset)
68     {
69         super(id, size, data, offset);
70     }
71
72     protected void validateSid(short id)
73     {
74         if (id != sid)
75         {
76             throw new RecordFormatException("NOT A Guts RECORD");
77         }
78     }
79
80     protected void fillFields(byte [] data, short size, int offset)
81     {
82         field_1_left_row_gutter = LittleEndian.getShort(data, 0 + offset);
83         field_2_top_col_gutter = LittleEndian.getShort(data, 2 + offset);
84         field_3_row_level_max = LittleEndian.getShort(data, 4 + offset);
85         field_4_col_level_max = LittleEndian.getShort(data, 6 + offset);
86     }
87
88     /**
89      * set the size of the gutter that appears at the left of the rows
90      *
91      * @param gut gutter size in screen units
92      */

93
94     public void setLeftRowGutter(short gut)
95     {
96         field_1_left_row_gutter = gut;
97     }
98
99     /**
100      * set the size of the gutter that appears at the above the columns
101      *
102      * @param gut gutter size in screen units
103      */

104
105     public void setTopColGutter(short gut)
106     {
107         field_2_top_col_gutter = gut;
108     }
109
110     /**
111      * set the maximum outline level for the row gutter.
112      *
113      * @param max maximum outline level
114      */

115
116     public void setRowLevelMax(short max)
117     {
118         field_3_row_level_max = max;
119     }
120
121     /**
122      * set the maximum outline level for the col gutter.
123      *
124      * @param max maximum outline level
125      */

126
127     public void setColLevelMax(short max)
128     {
129         field_4_col_level_max = max;
130     }
131
132     /**
133      * get the size of the gutter that appears at the left of the rows
134      *
135      * @return gutter size in screen units
136      */

137
138     public short getLeftRowGutter()
139     {
140         return field_1_left_row_gutter;
141     }
142
143     /**
144      * get the size of the gutter that appears at the above the columns
145      *
146      * @return gutter size in screen units
147      */

148
149     public short getTopColGutter()
150     {
151         return field_2_top_col_gutter;
152     }
153
154     /**
155      * get the maximum outline level for the row gutter.
156      *
157      * @return maximum outline level
158      */

159
160     public short getRowLevelMax()
161     {
162         return field_3_row_level_max;
163     }
164
165     /**
166      * get the maximum outline level for the col gutter.
167      *
168      * @return maximum outline level
169      */

170
171     public short getColLevelMax()
172     {
173         return field_4_col_level_max;
174     }
175
176     public String JavaDoc toString()
177     {
178         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
179
180         buffer.append("[GUTS]\n");
181         buffer.append(" .leftgutter = ")
182             .append(Integer.toHexString(getLeftRowGutter())).append("\n");
183         buffer.append(" .topgutter = ")
184             .append(Integer.toHexString(getTopColGutter())).append("\n");
185         buffer.append(" .rowlevelmax = ")
186             .append(Integer.toHexString(getRowLevelMax())).append("\n");
187         buffer.append(" .collevelmax = ")
188             .append(Integer.toHexString(getColLevelMax())).append("\n");
189         buffer.append("[/GUTS]\n");
190         return buffer.toString();
191     }
192
193     public int serialize(int offset, byte [] data)
194     {
195         LittleEndian.putShort(data, 0 + offset, sid);
196         LittleEndian.putShort(data, 2 + offset, ( short ) 0x8);
197         LittleEndian.putShort(data, 4 + offset, getLeftRowGutter());
198         LittleEndian.putShort(data, 6 + offset, getTopColGutter());
199         LittleEndian.putShort(data, 8 + offset, getRowLevelMax());
200         LittleEndian.putShort(data, 10 + offset, getColLevelMax());
201         return getRecordSize();
202     }
203
204     public int getRecordSize()
205     {
206         return 12;
207     }
208
209     public short getSid()
210     {
211         return this.sid;
212     }
213
214     public Object JavaDoc clone() {
215       GutsRecord rec = new GutsRecord();
216       rec.field_1_left_row_gutter = field_1_left_row_gutter;
217       rec.field_2_top_col_gutter = field_2_top_col_gutter;
218       rec.field_3_row_level_max = field_3_row_level_max;
219       rec.field_4_col_level_max = field_4_col_level_max;
220       return rec;
221     }
222 }
223
Popular Tags