KickJava   Java API By Example, From Geeks To Geeks.

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


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: Default Column Width Record<P>
25  * Description: Specifies the default width for columns that have no specific
26  * width set.<P>
27  * REFERENCE: PG 302 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
28  * @author Andrew C. Oliver (acoliver at apache dot org)
29  * @author Jason Height (jheight at chariot dot net dot au)
30  * @version 2.0-pre
31  */

32
33 public class DefaultColWidthRecord
34     extends Record
35 {
36     public final static short sid = 0x55;
37     private short field_1_col_width;
38
39     public DefaultColWidthRecord()
40     {
41     }
42
43     /**
44      * Constructs a DefaultColumnWidth record and sets its fields appropriately.
45      *
46      * @param id id must be 0x55 or an exception will be throw upon validation
47      * @param size the size of the data area of the record
48      * @param data data of the record (should not contain sid/len)
49      */

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

64
65     public DefaultColWidthRecord(short id, short size, byte [] data,
66                                  int offset)
67     {
68         super(id, size, data, offset);
69     }
70
71     protected void validateSid(short id)
72     {
73         if (id != sid)
74         {
75             throw new RecordFormatException("NOT A DefaultColWidth RECORD");
76         }
77     }
78
79     protected void fillFields(byte [] data, short size, int offset)
80     {
81         field_1_col_width = LittleEndian.getShort(data, 0 + offset);
82     }
83
84     /**
85      * set the default column width
86      * @param height defaultwidth for columns
87      */

88
89     public void setColWidth(short height)
90     {
91         field_1_col_width = height;
92     }
93
94     /**
95      * get the default column width
96      * @return defaultwidth for columns
97      */

98
99     public short getColWidth()
100     {
101         return field_1_col_width;
102     }
103
104     public String JavaDoc toString()
105     {
106         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
107
108         buffer.append("[DEFAULTCOLWIDTH]\n");
109         buffer.append(" .colwidth = ")
110             .append(Integer.toHexString(getColWidth())).append("\n");
111         buffer.append("[/DEFAULTCOLWIDTH]\n");
112         return buffer.toString();
113     }
114
115     public int serialize(int offset, byte [] data)
116     {
117         LittleEndian.putShort(data, 0 + offset, sid);
118         LittleEndian.putShort(data, 2 + offset, ( short ) 0x2);
119         LittleEndian.putShort(data, 4 + offset, getColWidth());
120         return getRecordSize();
121     }
122
123     public int getRecordSize()
124     {
125         return 6;
126     }
127
128     public short getSid()
129     {
130         return this.sid;
131     }
132
133     public Object JavaDoc clone() {
134       DefaultColWidthRecord rec = new DefaultColWidthRecord();
135       rec.field_1_col_width = field_1_col_width;
136       return rec;
137     }
138 }
139
Popular Tags