KickJava   Java API By Example, From Geeks To Geeks.

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


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: Use Natural Language Formulas Flag<P>
25  * Description: Tells the GUI if this was written by something that can use
26  * "natural language" formulas. HSSF can't.<P>
27  * REFERENCE: PG 420 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 UseSelFSRecord
33     extends Record
34 {
35     public final static short sid = 0x160;
36     public final static short TRUE = 1;
37     public final static short FALSE = 0;
38     private short field_1_flag;
39
40     public UseSelFSRecord()
41     {
42     }
43
44     /**
45      * Constructs a UseSelFS record and sets its fields appropriately.
46      *
47      * @param id id must be 0x160 or an exception will be throw upon validation
48      * @param size the size of the data area of the record
49      * @param data data of the record (should not contain sid/len)
50      */

51
52     public UseSelFSRecord(short id, short size, byte [] data)
53     {
54         super(id, size, data);
55     }
56
57     /**
58      * Constructs a UseSelFS record and sets its fields appropriately.
59      *
60      * @param id id must be 0x160 or an exception will be throw upon validation
61      * @param size the size of the data area of the record
62      * @param data data of the record (should not contain sid/len)
63      * @param offset of record
64      */

65
66     public UseSelFSRecord(short id, short size, byte [] data, int offset)
67     {
68         super(id, size, data, offset);
69     }
70
71     protected void validateSid(short id)
72     {
73         if (id != sid)
74         {
75             throw new RecordFormatException("NOT A UseSelFS RECORD");
76         }
77     }
78
79     protected void fillFields(byte [] data, short size, int offset)
80     {
81         field_1_flag = LittleEndian.getShort(data, 0 + offset);
82     }
83
84     /**
85      * turn the flag on or off
86      *
87      * @param flag whether to use natural language formulas or not
88      * @see #TRUE
89      * @see #FALSE
90      */

91
92     public void setFlag(short flag)
93     {
94         field_1_flag = flag;
95     }
96
97     /**
98      * returns whether we use natural language formulas or not
99      *
100      * @return whether to use natural language formulas or not
101      * @see #TRUE
102      * @see #FALSE
103      */

104
105     public short getFlag()
106     {
107         return field_1_flag;
108     }
109
110     public String JavaDoc toString()
111     {
112         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
113
114         buffer.append("[USESELFS]\n");
115         buffer.append(" .flag = ")
116             .append(Integer.toHexString(getFlag())).append("\n");
117         buffer.append("[/USESELFS]\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, getFlag());
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