KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
20  * ColumnInfoRecord.java
21  *
22  * Created on December 8, 2001, 8:44 AM
23  */

24 package org.apache.poi.hssf.record;
25
26 import org.apache.poi.util.LittleEndian;
27 import org.apache.poi.util.BitField;
28
29 /**
30  * Title: ColumnInfo Record<P>
31  * Description: Defines with width and formatting for a range of columns<P>
32  * REFERENCE: PG 293 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
33  * @author Andrew C. Oliver (acoliver at apache dot org)
34  * @version 2.0-pre
35  */

36
37 public class ColumnInfoRecord
38     extends Record
39 {
40     public static final short sid = 0x7d;
41     private short field_1_first_col;
42     private short field_2_last_col;
43     private short field_3_col_width;
44     private short field_4_xf_index;
45     private short field_5_options;
46     static final private BitField hidden = new BitField(0x01);
47     static final private BitField outlevel = new BitField(0x0700);
48     static final private BitField collapsed = new BitField(0x1000);
49     private short field_6_reserved;
50
51     public ColumnInfoRecord()
52     {
53     }
54
55     /**
56      * Constructs a ColumnInfo record and sets its fields appropriately
57      *
58      * @param id id must be 0x7d or an exception will be throw upon validation
59      * @param size the size of the data area of the record
60      * @param data data of the record (should not contain sid/len)
61      */

62
63     public ColumnInfoRecord(short id, short size, byte [] data)
64     {
65         super(id, size, data);
66     }
67
68     /**
69      * Constructs a ColumnInfo record and sets its fields appropriately
70      *
71      * @param id id must be 0x7d or an exception will be throw upon validation
72      * @param size the size of the data area of the record
73      * @param data data of the record (should not contain sid/len)
74      * @param offset of the record's data
75      */

76
77     public ColumnInfoRecord(short id, short size, byte [] data, int offset)
78     {
79         super(id, size, data);
80     }
81
82     protected void fillFields(byte [] data, short size, int offset)
83     {
84         field_1_first_col = LittleEndian.getShort(data, 0 + offset);
85         field_2_last_col = LittleEndian.getShort(data, 2 + offset);
86         field_3_col_width = LittleEndian.getShort(data, 4 + offset);
87         field_4_xf_index = LittleEndian.getShort(data, 6 + offset);
88         field_5_options = LittleEndian.getShort(data, 8 + offset);
89         field_6_reserved = data[ 10 + offset ];
90     }
91
92     protected void validateSid(short id)
93     {
94         if (id != sid)
95         {
96             throw new RecordFormatException("NOT A COLINFO RECORD!!");
97         }
98     }
99
100     /**
101      * set the first column this record defines formatting info for
102      * @param fc - the first column index (0-based)
103      */

104
105     public void setFirstColumn(short fc)
106     {
107         field_1_first_col = fc;
108     }
109
110     /**
111      * set the last column this record defines formatting info for
112      * @param lc - the last column index (0-based)
113      */

114
115     public void setLastColumn(short lc)
116     {
117         field_2_last_col = lc;
118     }
119
120     /**
121      * set the columns' width in 1/256 of a character width
122      * @param cw - column width
123      */

124
125     public void setColumnWidth(short cw)
126     {
127         field_3_col_width = cw;
128     }
129
130     /**
131      * set the columns' default format info
132      * @param xfi - the extended format index
133      * @see org.apache.poi.hssf.record.ExtendedFormatRecord
134      */

135
136     public void setXFIndex(short xfi)
137     {
138         field_4_xf_index = xfi;
139     }
140
141     /**
142      * set the options bitfield - use the bitsetters instead
143      * @param options - the bitfield raw value
144      */

145
146     public void setOptions(short options)
147     {
148         field_5_options = options;
149     }
150
151     // start options bitfield
152

153     /**
154      * set whether or not these cells are hidden
155      * @param ishidden - whether the cells are hidden.
156      * @see #setOptions(short)
157      */

158
159     public void setHidden(boolean ishidden)
160     {
161         field_5_options = hidden.setShortBoolean(field_5_options, ishidden);
162     }
163
164     /**
165      * set the outline level for the cells
166      * @see #setOptions(short)
167      * @param olevel -outline level for the cells
168      */

169
170     public void setOutlineLevel(short olevel)
171     {
172         field_5_options = outlevel.setShortValue(field_5_options, olevel);
173     }
174
175     /**
176      * set whether the cells are collapsed
177      * @param iscollapsed - wether the cells are collapsed
178      * @see #setOptions(short)
179      */

180
181     public void setCollapsed(boolean iscollapsed)
182     {
183         field_5_options = collapsed.setShortBoolean(field_5_options,
184                                                     iscollapsed);
185     }
186
187     // end options bitfield
188

189     /**
190      * get the first column this record defines formatting info for
191      * @return the first column index (0-based)
192      */

193
194     public short getFirstColumn()
195     {
196         return field_1_first_col;
197     }
198
199     /**
200      * get the last column this record defines formatting info for
201      * @return the last column index (0-based)
202      */

203
204     public short getLastColumn()
205     {
206         return field_2_last_col;
207     }
208
209     /**
210      * get the columns' width in 1/256 of a character width
211      * @return column width
212      */

213
214     public short getColumnWidth()
215     {
216         return field_3_col_width;
217     }
218
219     /**
220      * get the columns' default format info
221      * @return the extended format index
222      * @see org.apache.poi.hssf.record.ExtendedFormatRecord
223      */

224
225     public short getXFIndex()
226     {
227         return field_4_xf_index;
228     }
229
230     /**
231      * get the options bitfield - use the bitsetters instead
232      * @return the bitfield raw value
233      */

234
235     public short getOptions()
236     {
237         return field_5_options;
238     }
239
240     // start options bitfield
241

242     /**
243      * get whether or not these cells are hidden
244      * @return whether the cells are hidden.
245      * @see #setOptions(short)
246      */

247
248     public boolean getHidden()
249     {
250         return hidden.isSet(field_5_options);
251     }
252
253     /**
254      * get the outline level for the cells
255      * @see #setOptions(short)
256      * @return outline level for the cells
257      */

258
259     public short getOutlineLevel()
260     {
261         return outlevel.getShortValue(field_5_options);
262     }
263
264     /**
265      * get whether the cells are collapsed
266      * @return wether the cells are collapsed
267      * @see #setOptions(short)
268      */

269
270     public boolean getCollapsed()
271     {
272         return collapsed.isSet(field_5_options);
273     }
274
275     // end options bitfield
276
public short getSid()
277     {
278         return sid;
279     }
280
281     public int serialize(int offset, byte [] data)
282     {
283         LittleEndian.putShort(data, 0 + offset, sid);
284         LittleEndian.putShort(data, 2 + offset, ( short ) 12);
285         LittleEndian.putShort(data, 4 + offset, getFirstColumn());
286         LittleEndian.putShort(data, 6 + offset, getLastColumn());
287         LittleEndian.putShort(data, 8 + offset, getColumnWidth());
288         LittleEndian.putShort(data, 10 + offset, getXFIndex());
289         LittleEndian.putShort(data, 12 + offset, getOptions());
290         LittleEndian.putShort(data, 14 + offset,
291                               ( short ) 0x0); // retval[14] = 0;
292
return getRecordSize();
293     }
294
295     public int getRecordSize()
296     {
297         return 16;
298     }
299
300     public String JavaDoc toString()
301     {
302         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
303
304         buffer.append("[COLINFO]\n");
305         buffer.append("colfirst = ").append(getFirstColumn())
306             .append("\n");
307         buffer.append("collast = ").append(getLastColumn())
308             .append("\n");
309         buffer.append("colwidth = ").append(getColumnWidth())
310             .append("\n");
311         buffer.append("xfindex = ").append(getXFIndex()).append("\n");
312         buffer.append("options = ").append(getOptions()).append("\n");
313         buffer.append(" hidden = ").append(getHidden()).append("\n");
314         buffer.append(" olevel = ").append(getOutlineLevel())
315             .append("\n");
316         buffer.append(" collapsed = ").append(getCollapsed())
317             .append("\n");
318         buffer.append("[/COLINFO]\n");
319         return buffer.toString();
320     }
321
322     public Object JavaDoc clone() {
323         ColumnInfoRecord rec = new ColumnInfoRecord();
324         rec.field_1_first_col = field_1_first_col;
325         rec.field_2_last_col = field_2_last_col;
326         rec.field_3_col_width = field_3_col_width;
327         rec.field_4_xf_index = field_4_xf_index;
328         rec.field_5_options = field_5_options;
329         rec.field_6_reserved = field_6_reserved;
330         return rec;
331     }
332 }
333
Popular Tags