KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*********************************************************************
2 *
3 * Copyright (C) 2001 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.text.NumberFormat JavaDoc;
23
24 import jxl.CellType;
25 import jxl.NumberCell;
26 import jxl.biff.Type;
27 import jxl.biff.DoubleHelper;
28 import jxl.format.CellFormat;
29
30 /**
31  * The record which contains numerical values. All values are stored
32  * as 64bit IEEE floating point values
33  */

34 public abstract class NumberRecord extends CellValue
35 {
36   /**
37    * The number
38    */

39   private double value;
40
41   /**
42    * Constructor invoked by the user API
43    *
44    * @param c the column
45    * @param r the row
46    * @param val the value
47    */

48   protected NumberRecord(int c, int r, double val)
49   {
50     super(Type.NUMBER, c, r);
51     value = val;
52   }
53
54   /**
55    * Overloaded constructor invoked from the API, which takes a cell
56    * format
57    *
58    * @param c the column
59    * @param r the row
60    * @param val the value
61    * @param st the cell format
62    */

63   protected NumberRecord(int c, int r, double val, CellFormat st)
64   {
65     super(Type.NUMBER, c, r, st);
66     value = val;
67   }
68
69   /**
70    * Constructor used when copying a workbook
71    *
72    * @param nc the number to copy
73    */

74   protected NumberRecord(NumberCell nc)
75   {
76     super(Type.NUMBER, nc);
77     value = nc.getValue();
78   }
79
80   /**
81    * Copy constructor
82    *
83    * @param c the column
84    * @param r the row
85    * @param nr the record to copy
86    */

87   protected NumberRecord(int c, int r, NumberRecord nr)
88   {
89     super(Type.NUMBER, c, r, nr);
90     value = nr.value;
91   }
92
93   /**
94    * Returns the content type of this cell
95    *
96    * @return the content type for this cell
97    */

98   public CellType getType()
99   {
100     return CellType.NUMBER;
101   }
102
103   /**
104    * Gets the binary data for output to file
105    *
106    * @return the binary data
107    */

108   public byte[] getData()
109   {
110     byte[] celldata = super.getData();
111     byte[] data = new byte[celldata.length + 8];
112     System.arraycopy(celldata, 0, data, 0, celldata.length);
113     DoubleHelper.getIEEEBytes(value, data, celldata.length);
114
115     return data;
116   }
117
118   /**
119    * Quick and dirty function to return the contents of this cell as a string.
120    * For more complex manipulation of the contents, it is necessary to cast
121    * this interface to correct subinterface
122    *
123    * @return the contents of this cell as a string
124    */

125   public String JavaDoc getContents()
126   {
127     return Double.toString(value);
128   }
129
130   /**
131    * Gets the double contents for this cell.
132    *
133    * @return the cell contents
134    */

135   public double getValue()
136   {
137     return value;
138   }
139
140   /**
141    * Sets the value of the contents for this cell
142    *
143    * @param val the new value
144    */

145   public void setValue(double val)
146   {
147     value = val;
148   }
149
150   /**
151    * Gets the NumberFormat used to format this cell. This is the java
152    * equivalent of the Excel format
153    *
154    * @return the NumberFormat used to format the cell
155    */

156   public NumberFormat JavaDoc getNumberFormat()
157   {
158     return null;
159   }
160 }
161
162
163
164
Popular Tags