KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
23
24 import jxl.write.Number;
25 import jxl.biff.Type;
26 import jxl.biff.IntegerHelper;
27 import jxl.biff.WritableRecordData;
28
29 /**
30  * Contains an array of RK numbers
31  */

32 class MulRKRecord extends WritableRecordData
33 {
34   /**
35    * The row containing these numbers
36    */

37   private int row;
38   /**
39    * The first column these rk number occur on
40    */

41   private int colFirst;
42   /**
43    * The last column these rk number occur on
44    */

45   private int colLast;
46   /**
47    * The array of rk numbers
48    */

49   private int[] rknumbers;
50   /**
51    * The array of xf indices
52    */

53   private int[] xfIndices;
54
55   /**
56    * Constructs the rk numbers from the integer cells
57    *
58    * @param numbers A list of jxl.write.Number objects
59    */

60   public MulRKRecord(List JavaDoc numbers)
61   {
62     super(Type.MULRK);
63     row = ((Number JavaDoc)numbers.get(0)).getRow();
64     colFirst = ((Number JavaDoc)numbers.get(0)).getColumn();
65     colLast = colFirst + numbers.size() - 1;
66
67     rknumbers = new int[numbers.size()];
68     xfIndices = new int[numbers.size()];
69
70     for (int i = 0; i < numbers.size(); i++)
71     {
72       rknumbers[i] = (int) ((Number JavaDoc)numbers.get(i)).getValue();
73       xfIndices[i] = ( (CellValue) numbers.get(i)).getXFIndex();
74     }
75   }
76
77   /**
78    * Gets the binary data for output to file
79    *
80    * @return the binary data
81    */

82   public byte[] getData()
83   {
84     byte[] data = new byte[rknumbers.length * 6 + 6];
85
86     // Set up the row and the first column
87
IntegerHelper.getTwoBytes(row, data, 0);
88     IntegerHelper.getTwoBytes(colFirst, data, 2);
89
90     // Add all the rk numbers
91
int pos = 4;
92     int rkValue = 0;
93     int rkBits = 0;
94     byte[] rkBytes = new byte[4];
95     for (int i = 0; i < rknumbers.length; i++)
96     {
97       IntegerHelper.getTwoBytes(xfIndices[i], data, pos);
98       
99       // To represent an int as an Excel RK value, we have to
100
// undergo some outrageous jiggery pokery, as follows:
101

102       // Gets the bit representation of the number
103
rkValue = rknumbers[i] << 2;
104
105       // Set the integer bit
106
rkValue |= 0x2;
107       IntegerHelper.getFourBytes(rkValue, data, pos+2);
108
109       pos+=6;
110     }
111
112     // Write the number of rk numbers in this record
113
IntegerHelper.getTwoBytes(colLast, data, pos);
114
115     return data;
116   }
117 }
118
119
120
121
122
Popular Tags