KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > write > biff > IndexRecord


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.write.biff;
21
22 import jxl.biff.Type;
23 import jxl.biff.IntegerHelper;
24 import jxl.biff.WritableRecordData;
25
26 /**
27  * Index into the cell rows in an worksheet
28  */

29 class IndexRecord extends WritableRecordData
30 {
31   /**
32    * The binary data
33    */

34   private byte[] data;
35   /**
36    * The numbe of rows served by this index record
37    */

38   private int rows;
39   /**
40    * The position of the BOF record in the excel output stream
41    */

42   private int bofPosition;
43   /**
44    * The number of blocks needed to hold all the rows
45    */

46   private int blocks;
47
48   /**
49    * The position of the current 'pointer' within the byte array
50    */

51   private int dataPos;
52   
53   /**
54    * Constructor
55    *
56    * @param pos the position of the BOF record
57    * @param bl the number of blocks
58    * @param r the number of rows
59    */

60   public IndexRecord(int pos, int r, int bl)
61   {
62     super(Type.INDEX);
63     bofPosition = pos;
64     rows = r;
65     blocks = bl;
66
67     // Allocate the amount of bytes required to hold all the blocks
68
data = new byte[16 + 4 * blocks];
69     dataPos = 16;
70   }
71
72   /**
73    * Gets the binary data for output. This writes out an empty data block, and
74    * the information is filled in later on when the information becomes
75    * available
76    *
77    * @return the binary data
78    */

79   protected byte[] getData()
80   {
81     IntegerHelper.getFourBytes(rows, data, 8);
82     return data;
83   }
84
85   /**
86    * Adds another index record into the array
87    *
88    * @param pos the position in the output file
89    */

90   void addBlockPosition(int pos)
91   {
92     IntegerHelper.getFourBytes(pos - bofPosition, data, dataPos);
93     dataPos += 4;
94   }
95
96   /**
97    * Sets the position of the data start. This happens to be the position
98    * of the DEFCOLWIDTH record
99    */

100   void setDataStartPosition(int pos)
101   {
102     IntegerHelper.getFourBytes(pos - bofPosition, data, 12);
103   }
104 }
105
Popular Tags