KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BlankRecord.java
21  *
22  * Created on December 10, 2001, 12:07 PM
23  */

24 package org.apache.poi.hssf.record;
25
26 import org.apache.poi.util.LittleEndian;
27
28 /**
29  * Title: Blank cell record <P>
30  * Description: Represents a column in a row with no value but with styling.<P>
31  * REFERENCE: PG 287 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
32  * @author Andrew C. Oliver (acoliver at apache dot org)
33  * @author Jason Height (jheight at chariot dot net dot au)
34  * @version 2.0-pre
35  */

36
37 public class BlankRecord
38     extends Record
39     implements CellValueRecordInterface, Comparable JavaDoc
40 {
41     public final static short sid = 0x201;
42     //private short field_1_row;
43
private int field_1_row;
44     private short field_2_col;
45     private short field_3_xf;
46
47     /** Creates a new instance of BlankRecord */
48
49     public BlankRecord()
50     {
51     }
52
53     /**
54      * Constructs a BlankRecord and sets its fields appropriately
55      *
56      * @param id id must be 0x201 or an exception will be throw upon validation
57      * @param size the size of the data area of the record
58      * @param data data of the record (should not contain sid/len)
59      */

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

74
75     public BlankRecord(short id, short size, byte [] data, int offset)
76     {
77         super(id, size, data, offset);
78     }
79
80     protected void fillFields(byte [] data, short size, int offset)
81     {
82         //field_1_row = LittleEndian.getShort(data, 0 + offset);
83
field_1_row = LittleEndian.getUShort(data, 0 + offset);
84         field_2_col = LittleEndian.getShort(data, 2 + offset);
85         field_3_xf = LittleEndian.getShort(data, 4 + offset);
86     }
87
88     /**
89      * called by constructor, should throw runtime exception in the event of a
90      * record passed with a differing ID.
91      *
92      * @param id alleged id for this record
93      */

94
95     protected void validateSid(short id)
96     {
97         if (id != sid)
98         {
99             throw new RecordFormatException("NOT A BLANKRECORD!");
100         }
101     }
102
103     /**
104      * set the row this cell occurs on
105      * @param row the row this cell occurs within
106      */

107
108     //public void setRow(short row)
109
public void setRow(int row)
110     {
111         field_1_row = row;
112     }
113
114     /**
115      * get the row this cell occurs on
116      *
117      * @return the row
118      */

119
120     //public short getRow()
121
public int getRow()
122     {
123         return field_1_row;
124     }
125
126     /**
127      * get the column this cell defines within the row
128      *
129      * @return the column
130      */

131
132     public short getColumn()
133     {
134         return field_2_col;
135     }
136
137     /**
138      * set the index of the extended format record to style this cell with
139      *
140      * @param xf - the 0-based index of the extended format
141      * @see org.apache.poi.hssf.record.ExtendedFormatRecord
142      */

143
144     public void setXFIndex(short xf)
145     {
146         field_3_xf = xf;
147     }
148
149     /**
150      * get the index of the extended format record to style this cell with
151      *
152      * @return extended format index
153      */

154
155     public short getXFIndex()
156     {
157         return field_3_xf;
158     }
159
160     /**
161      * set the column this cell defines within the row
162      *
163      * @param col the column this cell defines
164      */

165
166     public void setColumn(short col)
167     {
168         field_2_col = col;
169     }
170
171     public boolean isBefore(CellValueRecordInterface i)
172     {
173         if (this.getRow() > i.getRow())
174         {
175             return false;
176         }
177         if ((this.getRow() == i.getRow())
178                 && (this.getColumn() > i.getColumn()))
179         {
180             return false;
181         }
182         if ((this.getRow() == i.getRow())
183                 && (this.getColumn() == i.getColumn()))
184         {
185             return false;
186         }
187         return true;
188     }
189
190     public boolean isAfter(CellValueRecordInterface i)
191     {
192         if (this.getRow() < i.getRow())
193         {
194             return false;
195         }
196         if ((this.getRow() == i.getRow())
197                 && (this.getColumn() < i.getColumn()))
198         {
199             return false;
200         }
201         if ((this.getRow() == i.getRow())
202                 && (this.getColumn() == i.getColumn()))
203         {
204             return false;
205         }
206         return true;
207     }
208
209     public boolean isEqual(CellValueRecordInterface i)
210     {
211         return ((this.getRow() == i.getRow())
212                 && (this.getColumn() == i.getColumn()));
213     }
214
215     public boolean isInValueSection()
216     {
217         return true;
218     }
219
220     public boolean isValue()
221     {
222         return true;
223     }
224
225     /**
226      * return the non static version of the id for this record.
227      */

228
229     public short getSid()
230     {
231         return BlankRecord.sid;
232     }
233
234     public String JavaDoc toString()
235     {
236         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
237
238         buffer.append("[BLANK]\n");
239         buffer.append("row = ").append(Integer.toHexString(getRow()))
240             .append("\n");
241         buffer.append("col = ").append(Integer.toHexString(getColumn()))
242             .append("\n");
243         buffer.append("xf = ")
244             .append(Integer.toHexString(getXFIndex())).append("\n");
245         buffer.append("[/BLANK]\n");
246         return buffer.toString();
247     }
248
249     /**
250      * called by the class that is responsible for writing this sucker.
251      * Subclasses should implement this so that their data is passed back in a
252      * byte array.
253      *
254      * @return byte array containing instance data
255      */

256
257     public int serialize(int offset, byte [] data)
258     {
259         LittleEndian.putShort(data, 0 + offset, sid);
260         LittleEndian.putShort(data, 2 + offset, ( short ) 6);
261         //LittleEndian.putShort(data, 4 + offset, getRow());
262
LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
263         LittleEndian.putShort(data, 6 + offset, getColumn());
264         LittleEndian.putShort(data, 8 + offset, getXFIndex());
265         return getRecordSize();
266     }
267
268     public int getRecordSize()
269     {
270         return 10;
271     }
272
273     public int compareTo(Object JavaDoc obj)
274     {
275         CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
276
277         if ((this.getRow() == loc.getRow())
278                 && (this.getColumn() == loc.getColumn()))
279         {
280             return 0;
281         }
282         if (this.getRow() < loc.getRow())
283         {
284             return -1;
285         }
286         if (this.getRow() > loc.getRow())
287         {
288             return 1;
289         }
290         if (this.getColumn() < loc.getColumn())
291         {
292             return -1;
293         }
294         if (this.getColumn() > loc.getColumn())
295         {
296             return 1;
297         }
298         return -1;
299     }
300
301     public boolean equals(Object JavaDoc obj)
302     {
303         if (!(obj instanceof CellValueRecordInterface))
304         {
305             return false;
306         }
307         CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
308
309         if ((this.getRow() == loc.getRow())
310                 && (this.getColumn() == loc.getColumn()))
311         {
312             return true;
313         }
314         return false;
315     }
316
317     public Object JavaDoc clone() {
318       BlankRecord rec = new BlankRecord();
319       rec.field_1_row = field_1_row;
320       rec.field_2_col = field_2_col;
321       rec.field_3_xf = field_3_xf;
322       return rec;
323     }
324 }
325
Popular Tags