KickJava   Java API By Example, From Geeks To Geeks.

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


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: Dimensions Record<P>
25  * Description: provides the minumum and maximum bounds
26  * of a sheet.<P>
27  * REFERENCE: PG 303 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 DimensionsRecord
34     extends Record
35 {
36     public final static short sid = 0x200;
37     private int field_1_first_row;
38     private int field_2_last_row; // plus 1
39
private short field_3_first_col;
40     private short field_4_last_col;
41     private short field_5_zero; // must be 0 (reserved)
42

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

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

68
69     public DimensionsRecord(short id, short size, byte [] data, int offset)
70     {
71         super(id, size, data, offset);
72     }
73
74     protected void validateSid(short id)
75     {
76         if (id != sid)
77         {
78             throw new RecordFormatException("NOT A valid DIMENSIONS RECORD");
79         }
80     }
81
82     protected void fillFields(byte [] data, short size, int offset)
83     {
84         field_1_first_row = LittleEndian.getInt(data, 0 + offset);
85         field_2_last_row = LittleEndian.getInt(data, 4 + offset);
86         field_3_first_col = LittleEndian.getShort(data, 8 + offset);
87         field_4_last_col = LittleEndian.getShort(data, 10 + offset);
88         field_5_zero = LittleEndian.getShort(data, 12 + offset);
89     }
90
91     /**
92      * set the first row number for the sheet
93      * @param row - first row on the sheet
94      */

95
96     public void setFirstRow(int row)
97     {
98         field_1_first_row = row;
99     }
100
101     /**
102      * set the last row number for the sheet
103      * @param row - last row on the sheet
104      */

105
106     public void setLastRow(int row)
107     {
108         field_2_last_row = row;
109     }
110
111     /**
112      * set the first column number for the sheet
113      * @param col first column on the sheet
114      */

115
116     public void setFirstCol(short col)
117     {
118         field_3_first_col = col;
119     }
120
121     /**
122      * set the last col number for the sheet
123      * @param col last column on the sheet
124      */

125
126     public void setLastCol(short col)
127     {
128         field_4_last_col = col;
129     }
130
131     /**
132      * get the first row number for the sheet
133      * @return row - first row on the sheet
134      */

135
136     public int getFirstRow()
137     {
138         return field_1_first_row;
139     }
140
141     /**
142      * get the last row number for the sheet
143      * @return row - last row on the sheet
144      */

145
146     public int getLastRow()
147     {
148         return field_2_last_row;
149     }
150
151     /**
152      * get the first column number for the sheet
153      * @return column - first column on the sheet
154      */

155
156     public short getFirstCol()
157     {
158         return field_3_first_col;
159     }
160
161     /**
162      * get the last col number for the sheet
163      * @return column - last column on the sheet
164      */

165
166     public short getLastCol()
167     {
168         return field_4_last_col;
169     }
170
171     public String JavaDoc toString()
172     {
173         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
174
175         buffer.append("[DIMENSIONS]\n");
176         buffer.append(" .firstrow = ")
177             .append(Integer.toHexString(getFirstRow())).append("\n");
178         buffer.append(" .lastrow = ")
179             .append(Integer.toHexString(getLastRow())).append("\n");
180         buffer.append(" .firstcol = ")
181             .append(Integer.toHexString(getFirstCol())).append("\n");
182         buffer.append(" .lastcol = ")
183             .append(Integer.toHexString(getLastCol())).append("\n");
184         buffer.append(" .zero = ")
185             .append(Integer.toHexString(field_5_zero)).append("\n");
186         buffer.append("[/DIMENSIONS]\n");
187         return buffer.toString();
188     }
189
190     public int serialize(int offset, byte [] data)
191     {
192         LittleEndian.putShort(data, 0 + offset, sid);
193         LittleEndian.putShort(data, 2 + offset, ( short ) 14);
194         LittleEndian.putInt(data, 4 + offset, getFirstRow());
195         LittleEndian.putInt(data, 8 + offset, getLastRow());
196         LittleEndian.putShort(data, 12 + offset, getFirstCol());
197         LittleEndian.putShort(data, 14 + offset, getLastCol());
198         LittleEndian.putShort(data, 16 + offset, ( short ) 0);
199         return getRecordSize();
200     }
201
202     public int getRecordSize()
203     {
204         return 18;
205     }
206
207     public short getSid()
208     {
209         return this.sid;
210     }
211
212     public Object JavaDoc clone() {
213       DimensionsRecord rec = new DimensionsRecord();
214       rec.field_1_first_row = field_1_first_row;
215       rec.field_2_last_row = field_2_last_row;
216       rec.field_3_first_col = field_3_first_col;
217       rec.field_4_last_col = field_4_last_col;
218       rec.field_5_zero = field_5_zero;
219       return rec;
220     }
221 }
222
Popular Tags