KickJava   Java API By Example, From Geeks To Geeks.

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


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 Row Height Record
25  * Description: Row height for rows with undefined or not explicitly defined
26  * heights.
27  * REFERENCE: PG 301 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 DefaultRowHeightRecord
34     extends Record
35 {
36     public final static short sid = 0x225;
37     private short field_1_option_flags;
38     private short field_2_row_height;
39
40     public DefaultRowHeightRecord()
41     {
42     }
43
44     /**
45      * Constructs a DefaultRowHeight record and sets its fields appropriately.
46      *
47      * @param id id must be 0x225 or an exception will be throw upon validation
48      * @param size the size of the data area of the record
49      * @param data data of the record (should not contain sid/len)
50      */

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

65
66     public DefaultRowHeightRecord(short id, short size, byte [] data,
67                                   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 DefaultRowHeight RECORD");
77         }
78     }
79
80     protected void fillFields(byte [] data, short size, int offset)
81     {
82         field_1_option_flags = LittleEndian.getShort(data, 0 + offset);
83         field_2_row_height = LittleEndian.getShort(data, 2 + offset);
84     }
85
86     /**
87      * set the (currently unimportant to HSSF) option flags
88      * @param flags the bitmask to set
89      */

90
91     public void setOptionFlags(short flags)
92     {
93         field_1_option_flags = flags;
94     }
95
96     /**
97      * set the default row height
98      * @param height for undefined rows/rows w/undefined height
99      */

100
101     public void setRowHeight(short height)
102     {
103         field_2_row_height = height;
104     }
105
106     /**
107      * get the (currently unimportant to HSSF) option flags
108      * @return flags - the current bitmask
109      */

110
111     public short getOptionFlags()
112     {
113         return field_1_option_flags;
114     }
115
116     /**
117      * get the default row height
118      * @return rowheight for undefined rows/rows w/undefined height
119      */

120
121     public short getRowHeight()
122     {
123         return field_2_row_height;
124     }
125
126     public String JavaDoc toString()
127     {
128         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
129
130         buffer.append("[DEFAULTROWHEIGHT]\n");
131         buffer.append(" .optionflags = ")
132             .append(Integer.toHexString(getOptionFlags())).append("\n");
133         buffer.append(" .rowheight = ")
134             .append(Integer.toHexString(getRowHeight())).append("\n");
135         buffer.append("[/DEFAULTROWHEIGHT]\n");
136         return buffer.toString();
137     }
138
139     public int serialize(int offset, byte [] data)
140     {
141         LittleEndian.putShort(data, 0 + offset, sid);
142         LittleEndian.putShort(data, 2 + offset, ( short ) 0x4);
143         LittleEndian.putShort(data, 4 + offset, getOptionFlags());
144         LittleEndian.putShort(data, 6 + offset, getRowHeight());
145         return getRecordSize();
146     }
147
148     public int getRecordSize()
149     {
150         return 8;
151     }
152
153     public short getSid()
154     {
155         return this.sid;
156     }
157
158     public Object JavaDoc clone() {
159       DefaultRowHeightRecord rec = new DefaultRowHeightRecord();
160       rec.field_1_option_flags = field_1_option_flags;
161       rec.field_2_row_height = field_2_row_height;
162       return rec;
163     }
164 }
165
Popular Tags