KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > FnGroupCountRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Title: Function Group Count Record<P>
25  * Description: Number of built in function groups in the current version of the
26  * Spreadsheet (probably only used on Windoze)<P>
27  * REFERENCE: PG 315 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
28  * @author Andrew C. Oliver (acoliver at apache dot org)
29  * @version 2.0-pre
30  */

31
32 public class FnGroupCountRecord
33     extends Record
34 {
35     public final static short sid = 0x9c;
36
37     /**
38      * suggested default (14 dec)
39      */

40
41     public final static short COUNT = 14;
42     private short field_1_count;
43
44     public FnGroupCountRecord()
45     {
46     }
47
48     /**
49      * Constructs a FnGroupCount record and sets its fields appropriately.
50      *
51      * @param id id must be 0x9c or an exception will be throw upon validation
52      * @param size the size of the data area of the record
53      * @param data data of the record (should not contain sid/len)
54      */

55
56     public FnGroupCountRecord(short id, short size, byte [] data)
57     {
58         super(id, size, data);
59     }
60
61     /**
62      * Constructs a FnGroupCount record and sets its fields appropriately.
63      *
64      * @param id id must be 0x9c or an exception will be throw upon validation
65      * @param size the size of the data area of the record
66      * @param data data of the record (should not contain sid/len)
67      * @param offset of the record's data
68      */

69
70     public FnGroupCountRecord(short id, short size, byte [] data, int offset)
71     {
72         super(id, size, data, offset);
73     }
74
75     protected void validateSid(short id)
76     {
77         if (id != sid)
78         {
79             throw new RecordFormatException("NOT A FNGROUPCOUNT RECORD");
80         }
81     }
82
83     protected void fillFields(byte [] data, short size, int offset)
84     {
85         field_1_count = LittleEndian.getShort(data, 0 + offset);
86     }
87
88     /**
89      * set the number of built-in functions
90      *
91      * @param count - number of functions
92      */

93
94     public void setCount(short count)
95     {
96         field_1_count = count;
97     }
98
99     /**
100      * get the number of built-in functions
101      *
102      * @return number of built-in functions
103      */

104
105     public short getCount()
106     {
107         return field_1_count;
108     }
109
110     public String JavaDoc toString()
111     {
112         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
113
114         buffer.append("[FNGROUPCOUNT]\n");
115         buffer.append(" .count = ").append(getCount())
116             .append("\n");
117         buffer.append("[/FNGROUPCOUNT]\n");
118         return buffer.toString();
119     }
120
121     public int serialize(int offset, byte [] data)
122     {
123         LittleEndian.putShort(data, 0 + offset, sid);
124         LittleEndian.putShort(data, 2 + offset,
125                               (( short ) 0x02)); // 2 bytes (6 total)
126
LittleEndian.putShort(data, 4 + offset, getCount());
127         return getRecordSize();
128     }
129
130     public int getRecordSize()
131     {
132         return 6;
133     }
134
135     public short getSid()
136     {
137         return this.sid;
138     }
139 }
140
Popular Tags