KickJava   Java API By Example, From Geeks To Geeks.

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


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

24 package org.apache.poi.hssf.record;
25
26 import org.apache.poi.util.LittleEndian;
27
28 /**
29  * Title: Mulitple Blank cell record <P>
30  * Description: Represents a set of columns in a row with no value but with styling.
31  * In this release we have read-only support for this record type.
32  * The RecordFactory converts this to a set of BlankRecord objects.<P>
33  * REFERENCE: PG 329 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
34  * @author Andrew C. Oliver (acoliver at apache dot org)
35  * @author Glen Stampoultzis (glens at apache.org)
36  * @version 2.0-pre
37  * @see org.apache.poi.hssf.record.RecordFactory
38  * @see org.apache.poi.hssf.record.BlankRecord
39  */

40
41 public class MulBlankRecord
42     extends Record
43 {
44     public final static short sid = 0xbe;
45     //private short field_1_row;
46
private int field_1_row;
47     private short field_2_first_col;
48     private short[] field_3_xfs;
49     private short field_4_last_col;
50
51     /** Creates new MulBlankRecord */
52
53     public MulBlankRecord()
54     {
55     }
56
57     /**
58      * Constructs a MulBlank record and sets its fields appropriately.
59      *
60      * @param id id must be 0xbe 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      */

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

78
79     public MulBlankRecord(short id, short size, byte [] data, int offset)
80     {
81         super(id, size, data, offset);
82     }
83
84     /**
85      * get the row number of the cells this represents
86      *
87      * @return row number
88      */

89
90     //public short getRow()
91
public int getRow()
92     {
93         return field_1_row;
94     }
95
96     /**
97      * starting column (first cell this holds in the row)
98      * @return first column number
99      */

100
101     public short getFirstColumn()
102     {
103         return field_2_first_col;
104     }
105
106     /**
107      * ending column (last cell this holds in the row)
108      * @return first column number
109      */

110
111     public short getLastColumn()
112     {
113         return field_4_last_col;
114     }
115
116     /**
117      * get the number of columns this contains (last-first +1)
118      * @return number of columns (last - first +1)
119      */

120
121     public int getNumColumns()
122     {
123         return field_4_last_col - field_2_first_col + 1;
124     }
125
126     /**
127      * returns the xf index for column (coffset = column - field_2_first_col)
128      * @param coffset the column (coffset = column - field_2_first_col)
129      * @return the XF index for the column
130      */

131
132     public short getXFAt(int coffset)
133     {
134         return field_3_xfs[ coffset ];
135     }
136
137     /**
138      * called by the constructor, should set class level fields. Should throw
139      * runtime exception for bad/icomplete data.
140      *
141      * @param data raw data
142      * @param size size of data
143      */

144
145     protected void fillFields(byte [] data, short size, int offset)
146     {
147         //field_1_row = LittleEndian.getShort(data, 0 + offset);
148
field_1_row = LittleEndian.getUShort(data, 0 + offset);
149         field_2_first_col = LittleEndian.getShort(data, 2 + offset);
150         field_3_xfs = parseXFs(data, 4, offset, size);
151         field_4_last_col = LittleEndian.getShort(data,
152                                                   (field_3_xfs.length * 2)
153                                                   + 4 + offset);
154     }
155
156     private short [] parseXFs(byte [] data, int offset, int recoffset,
157                               short size)
158     {
159         short[] retval = new short[ ((size - offset) - 2) / 2 ];
160         int idx = 0;
161
162         for (; offset < size - 2; )
163         {
164             short xf = 0;
165
166             xf = LittleEndian.getShort(data, offset + recoffset);
167             offset += 2;
168             retval[ idx ] = xf;
169             idx++;
170         }
171         return retval;
172     }
173
174     public String JavaDoc toString()
175     {
176         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
177
178         buffer.append("[MULBLANK]\n");
179         buffer.append("row = ")
180             .append(Integer.toHexString(getRow())).append("\n");
181         buffer.append("firstcol = ")
182             .append(Integer.toHexString(getFirstColumn())).append("\n");
183         buffer.append(" lastcol = ")
184             .append(Integer.toHexString(getLastColumn())).append("\n");
185         for (int k = 0; k < getNumColumns(); k++)
186         {
187             buffer.append("xf").append(k).append(" = ")
188                 .append(Integer.toHexString(getXFAt(k))).append("\n");
189         }
190         buffer.append("[/MULBLANK]\n");
191         return buffer.toString();
192     }
193
194     /**
195      * called by constructor, should throw runtime exception in the event of a
196      * record passed with a differing ID.
197      *
198      * @param id alleged id for this record
199      */

200
201     protected void validateSid(short id)
202     {
203         if (id != sid)
204         {
205             throw new RecordFormatException("Not a MulBlankRecord!");
206         }
207     }
208
209     public short getSid()
210     {
211         return this.sid;
212     }
213
214     public int serialize(int offset, byte [] data)
215     {
216         throw new RecordFormatException(
217             "Sorry, you can't serialize a MulBlank in this release");
218     }
219 }
220
Popular Tags