KickJava   Java API By Example, From Geeks To Geeks.

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


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 jxl.LabelCell;
23 import jxl.CellType;
24 import jxl.WorkbookSettings;
25 import jxl.biff.IntegerHelper;
26 import jxl.biff.FormattingRecords;
27 import jxl.biff.StringHelper;
28
29 /**
30  * A label which is stored in the cell
31  */

32 class LabelRecord extends CellValue implements LabelCell
33 {
34   /**
35    * The length of the label in characters
36    */

37   private int length;
38
39   /**
40    * The label
41    */

42   private String JavaDoc string;
43
44   /**
45    * Dummy indicators for overloading the constructor
46    */

47   private static class Biff7 {};
48   public static Biff7 biff7 = new Biff7();
49
50   /**
51    * Constructs this object from the raw data
52    *
53    * @param t the raw data
54    * @param fr the formatting records
55    * @param si the sheet
56    * @param ws the workbook settings
57    */

58   public LabelRecord(Record t, FormattingRecords fr,
59                      SheetImpl si, WorkbookSettings ws)
60   {
61     super(t, fr, si);
62     byte[] data = getRecord().getData();
63     length = IntegerHelper.getInt(data[6], data[7]);
64
65     if (data[8] == 0x0)
66     {
67       string = StringHelper.getString(data, length, 9, ws);
68     }
69     else
70     {
71       string = StringHelper.getUnicodeString(data, length, 9);
72     }
73   }
74
75   /**
76    * Constructs this object from the raw data
77    *
78    * @param t the raw data
79    * @param fr the formatting records
80    * @param si the sheet
81    * @param ws the workbook settings
82    * @param dummy dummy overload to indicate a biff 7 workbook
83    */

84   public LabelRecord(Record t, FormattingRecords fr, SheetImpl si,
85                      WorkbookSettings ws, Biff7 dummy)
86   {
87     super(t, fr, si);
88     byte[] data = getRecord().getData();
89     length = IntegerHelper.getInt(data[6], data[7]);
90
91     string = StringHelper.getString(data, length, 8, ws);
92   }
93
94   /**
95    * Gets the label
96    *
97    * @return the label
98    */

99   public String JavaDoc getString()
100   {
101     return string;
102   }
103
104   /**
105    * Gets the cell contents as a string
106    *
107    * @return the label
108    */

109   public String JavaDoc getContents()
110   {
111     return string;
112   }
113
114   /**
115    * Accessor for the cell type
116    *
117    * @return the cell type
118    */

119   public CellType getType()
120   {
121     return CellType.LABEL;
122   }
123 }
124
Popular Tags