KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > read > biff > CellValue


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.read.biff;
21
22 import common.Logger;
23
24 import jxl.Cell;
25 import jxl.CellFeatures;
26 import jxl.format.CellFormat;
27 import jxl.biff.IntegerHelper;
28 import jxl.biff.RecordData;
29 import jxl.biff.XFRecord;
30 import jxl.biff.FormattingRecords;
31
32 /**
33  * Abstract class for all records which actually contain cell values
34  */

35 public abstract class CellValue extends RecordData
36   implements Cell, CellFeaturesAccessor
37 {
38   /**
39    * The logger
40    */

41   private static Logger logger = Logger.getLogger(CellValue.class);
42
43   /**
44    * The row number of this cell record
45    */

46   private int row;
47
48   /**
49    * The column number of this cell record
50    */

51   private int column;
52
53   /**
54    * The XF index
55    */

56   private int xfIndex;
57
58   /**
59    * A handle to the formatting records, so that we can
60    * retrieve the formatting information
61    */

62   private FormattingRecords formattingRecords;
63
64   /**
65    * A lazy initialize flag for the cell format
66    */

67   private boolean initialized;
68
69   /**
70    * The cell format
71    */

72   private XFRecord format;
73
74   /**
75    * A handle back to the sheet
76    */

77   private SheetImpl sheet;
78
79   /**
80    * The cell features
81    */

82   private CellFeatures features;
83
84   /**
85    * Constructs this object from the raw cell data
86    *
87    * @param t the raw cell data
88    * @param fr the formatting records
89    * @param si the sheet containing this cell
90    */

91   protected CellValue(Record t, FormattingRecords fr, SheetImpl si)
92   {
93     super(t);
94     byte[] data = getRecord().getData();
95     row = IntegerHelper.getInt(data[0], data[1]);
96     column = IntegerHelper.getInt(data[2], data[3]);
97     xfIndex = IntegerHelper.getInt(data[4], data[5]);
98     sheet = si;
99     formattingRecords = fr;
100     initialized = false;
101   }
102
103   /**
104    * Interface method which returns the row number of this cell
105    *
106    * @return the zero base row number
107    */

108   public final int getRow()
109   {
110     return row;
111   }
112
113   /**
114    * Interface method which returns the column number of this cell
115    *
116    * @return the zero based column number
117    */

118   public final int getColumn()
119   {
120     return column;
121   }
122
123   /**
124    * Gets the XFRecord corresponding to the index number. Used when
125    * copying a spreadsheet
126    *
127    * @return the xf index for this cell
128    */

129   public final int getXFIndex()
130   {
131     return xfIndex;
132   }
133
134   /**
135    * Gets the CellFormat object for this cell. Used by the WritableWorkbook
136    * API
137    *
138    * @return the CellFormat used for this cell
139    */

140   public CellFormat getCellFormat()
141   {
142     if (!initialized)
143     {
144       format = formattingRecords.getXFRecord(xfIndex);
145       initialized = true;
146     }
147
148     return format;
149   }
150
151   /**
152    * Determines whether or not this cell has been hidden
153    *
154    * @return TRUE if this cell has been hidden, FALSE otherwise
155    */

156   public boolean isHidden()
157   {
158     ColumnInfoRecord cir = sheet.getColumnInfo(column);
159
160     if (cir != null && (cir.getWidth() == 0 || cir.getHidden()))
161     {
162       return true;
163     }
164
165     RowRecord rr = sheet.getRowInfo(row);
166
167     if (rr != null && (rr.getRowHeight() == 0 || rr.isCollapsed()))
168     {
169       return true;
170     }
171
172     return false;
173   }
174
175   /**
176    * Accessor for the sheet
177    *
178    * @return the sheet
179    */

180   protected SheetImpl getSheet()
181   {
182     return sheet;
183   }
184
185   /**
186    * Accessor for the cell features
187    *
188    * @return the cell features or NULL if this cell doesn't have any
189    */

190   public CellFeatures getCellFeatures()
191   {
192     return features;
193   }
194
195   /**
196    * Sets the cell features during the reading process
197    *
198    * @param cf the cell features
199    */

200   public void setCellFeatures(CellFeatures cf)
201   {
202     if (features != null)
203     {
204       logger.warn("current cell features not null - overwriting");
205     }
206
207     features = cf;
208   }
209 }
210
211
Popular Tags