KickJava   Java API By Example, From Geeks To Geeks.

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


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: Label SST Record<P>
25  * Description: Refers to a string in the shared string table and is a column
26  * value. <P>
27  * REFERENCE: PG 325 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 LabelSSTRecord
34     extends Record
35     implements CellValueRecordInterface, Comparable JavaDoc
36 {
37     public final static short sid = 0xfd;
38     //private short field_1_row;
39
private int field_1_row;
40     private short field_2_column;
41     private short field_3_xf_index;
42     private int field_4_sst_index;
43
44     public LabelSSTRecord()
45     {
46     }
47
48     /**
49      * Constructs an LabelSST record and sets its fields appropriately.
50      *
51      * @param id id must be 0xfd or an exception will be throw upon validation
52      * @param size the size of the data area of the record
53      * @param data data of the record (should not contain sid/len)
54      */

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

69
70     public LabelSSTRecord(short id, short size, byte [] data, int offset)
71     {
72         super(id, size, data, offset);
73     }
74
75     protected void validateSid(short id)
76     {
77         if (id != sid)
78         {
79             throw new RecordFormatException("NOT A valid LabelSST RECORD");
80         }
81     }
82
83     protected void fillFields(byte [] data, short size, int offset)
84     {
85         //field_1_row = LittleEndian.getShort(data, 0 + offset);
86
field_1_row = LittleEndian.getUShort(data, 0 + offset);
87         field_2_column = LittleEndian.getShort(data, 2 + offset);
88         field_3_xf_index = LittleEndian.getShort(data, 4 + offset);
89         field_4_sst_index = LittleEndian.getInt(data, 6 + offset);
90     }
91
92     //public void setRow(short row)
93
public void setRow(int row)
94     {
95         field_1_row = row;
96     }
97
98     public void setColumn(short col)
99     {
100         field_2_column = col;
101     }
102
103     /**
104      * set the index to the extended format record
105      *
106      * @see org.apache.poi.hssf.record.ExtendedFormatRecord
107      * @param index - the index to the XF record
108      */

109
110     public void setXFIndex(short index)
111     {
112         field_3_xf_index = index;
113     }
114
115     /**
116      * set the index to the string in the SSTRecord
117      *
118      * @param index - of string in the SST Table
119      * @see org.apache.poi.hssf.record.SSTRecord
120      */

121
122     public void setSSTIndex(int index)
123     {
124         field_4_sst_index = index;
125     }
126
127     //public short getRow()
128
public int getRow()
129     {
130         return field_1_row;
131     }
132
133     public short getColumn()
134     {
135         return field_2_column;
136     }
137
138     /**
139      * get the index to the extended format record
140      *
141      * @see org.apache.poi.hssf.record.ExtendedFormatRecord
142      * @return the index to the XF record
143      */

144
145     public short getXFIndex()
146     {
147         return field_3_xf_index;
148     }
149
150     /**
151      * get the index to the string in the SSTRecord
152      *
153      * @return index of string in the SST Table
154      * @see org.apache.poi.hssf.record.SSTRecord
155      */

156
157     public int getSSTIndex()
158     {
159         return field_4_sst_index;
160     }
161
162     public String JavaDoc toString()
163     {
164         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
165
166         buffer.append("[LABELSST]\n");
167         buffer.append(" .row = ")
168             .append(Integer.toHexString(getRow())).append("\n");
169         buffer.append(" .column = ")
170             .append(Integer.toHexString(getColumn())).append("\n");
171         buffer.append(" .xfindex = ")
172             .append(Integer.toHexString(getXFIndex())).append("\n");
173         buffer.append(" .sstindex = ")
174             .append(Integer.toHexString(getSSTIndex())).append("\n");
175         buffer.append("[/LABELSST]\n");
176         return buffer.toString();
177     }
178
179     public int serialize(int offset, byte [] data)
180     {
181         LittleEndian.putShort(data, 0 + offset, sid);
182         LittleEndian.putShort(data, 2 + offset, ( short ) 10);
183         //LittleEndian.putShort(data, 4 + offset, getRow());
184
LittleEndian.putShort(data, 4 + offset, ( short )getRow());
185         LittleEndian.putShort(data, 6 + offset, getColumn());
186         LittleEndian.putShort(data, 8 + offset, getXFIndex());
187         LittleEndian.putInt(data, 10 + offset, getSSTIndex());
188         return getRecordSize();
189     }
190
191     public int getRecordSize()
192     {
193         return 14;
194     }
195
196     public short getSid()
197     {
198         return this.sid;
199     }
200
201     public boolean isBefore(CellValueRecordInterface i)
202     {
203         if (this.getRow() > i.getRow())
204         {
205             return false;
206         }
207         if ((this.getRow() == i.getRow())
208                 && (this.getColumn() > i.getColumn()))
209         {
210             return false;
211         }
212         if ((this.getRow() == i.getRow())
213                 && (this.getColumn() == i.getColumn()))
214         {
215             return false;
216         }
217         return true;
218     }
219
220     public boolean isAfter(CellValueRecordInterface i)
221     {
222         if (this.getRow() < i.getRow())
223         {
224             return false;
225         }
226         if ((this.getRow() == i.getRow())
227                 && (this.getColumn() < i.getColumn()))
228         {
229             return false;
230         }
231         if ((this.getRow() == i.getRow())
232                 && (this.getColumn() == i.getColumn()))
233         {
234             return false;
235         }
236         return true;
237     }
238
239     public boolean isEqual(CellValueRecordInterface i)
240     {
241         return ((this.getRow() == i.getRow())
242                 && (this.getColumn() == i.getColumn()));
243     }
244
245     public boolean isInValueSection()
246     {
247         return true;
248     }
249
250     public boolean isValue()
251     {
252         return true;
253     }
254
255     public int compareTo(Object JavaDoc obj)
256     {
257         CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
258
259         if ((this.getRow() == loc.getRow())
260                 && (this.getColumn() == loc.getColumn()))
261         {
262             return 0;
263         }
264         if (this.getRow() < loc.getRow())
265         {
266             return -1;
267         }
268         if (this.getRow() > loc.getRow())
269         {
270             return 1;
271         }
272         if (this.getColumn() < loc.getColumn())
273         {
274             return -1;
275         }
276         if (this.getColumn() > loc.getColumn())
277         {
278             return 1;
279         }
280         return -1;
281     }
282
283     public boolean equals(Object JavaDoc obj)
284     {
285         if (!(obj instanceof CellValueRecordInterface))
286         {
287             return false;
288         }
289         CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
290
291         if ((this.getRow() == loc.getRow())
292                 && (this.getColumn() == loc.getColumn()))
293         {
294             return true;
295         }
296         return false;
297     }
298
299     public Object JavaDoc clone() {
300       LabelSSTRecord rec = new LabelSSTRecord();
301       rec.field_1_row = field_1_row;
302       rec.field_2_column = field_2_column;
303       rec.field_3_xf_index = field_3_xf_index;
304       rec.field_4_sst_index = field_4_sst_index;
305       return rec;
306     }
307 }
308
Popular Tags