KickJava   Java API By Example, From Geeks To Geeks.

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


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 common.Assert;
23 import jxl.BooleanCell;
24 import jxl.CellType;
25 import jxl.format.CellFormat;
26 import jxl.biff.Type;
27
28 /**
29  * A boolean cell's last calculated value
30  */

31 public abstract class BooleanRecord extends CellValue
32 {
33   /**
34    * The boolean value of this cell. If this cell represents an error,
35    * this will be false
36    */

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

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

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

72   protected BooleanRecord(BooleanCell nc)
73   {
74     super(Type.BOOLERR, nc);
75     value = nc.getValue();
76   }
77
78   /**
79    * Copy constructor
80    *
81    * @param c the column
82    * @param r the row
83    * @param br the record to copy
84    */

85   protected BooleanRecord(int c, int r, BooleanRecord br)
86   {
87     super(Type.BOOLERR, c, r, br);
88     value = br.value;
89   }
90
91   /**
92    * Interface method which Gets the boolean value stored in this cell. If
93    * this cell contains an error, then returns FALSE. Always query this cell
94    * type using the accessor method isError() prior to calling this method
95    *
96    * @return TRUE if this cell contains TRUE, FALSE if it contains FALSE or
97    * an error code
98    */

99   public boolean getValue()
100   {
101     return value;
102   }
103   
104   /**
105    * Returns the numerical value as a string
106    *
107    * @return The numerical value of the formula as a string
108    */

109   public String JavaDoc getContents()
110   {
111     // return Boolean.toString(value) - only available in 1.4 or later
112
return (new Boolean JavaDoc(value)).toString();
113   }
114
115   /**
116    * Returns the cell type
117    *
118    * @return The cell type
119    */

120   public CellType getType()
121   {
122     return CellType.BOOLEAN;
123   }
124
125   /**
126    * Sets the value
127    *
128    * @param val the boolean value
129    */

130   protected void setValue(boolean val)
131   {
132     value = val;
133   }
134
135   /**
136    * Gets the binary data for output to file
137    *
138    * @return the binary data
139    */

140   public byte[] getData()
141   {
142     byte[] celldata = super.getData();
143     byte[] data = new byte[celldata.length + 2];
144     System.arraycopy(celldata, 0, data, 0, celldata.length);
145
146     if (value)
147     {
148       data[celldata.length] = 1;
149     }
150
151     return data;
152   }
153
154 }
155
156
157
158
159
160
161
Popular Tags