KickJava   Java API By Example, From Geeks To Geeks.

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


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: Calc Mode Record<P>
25  * Description: Tells the gui whether to calculate formulas
26  * automatically, manually or automatically
27  * except for tables.<P>
28  * REFERENCE: PG 292 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
29  * @author Andrew C. Oliver (acoliver at apache dot org)
30  * @author Jason Height (jheight at chariot dot net dot au)
31  * @version 2.0-pre
32  * @see org.apache.poi.hssf.record.CalcCountRecord
33  */

34
35 public class CalcModeRecord
36     extends Record
37 {
38     public final static short sid = 0xD;
39
40     /**
41      * manually calculate formulas (0)
42      */

43
44     public final static short MANUAL = 0;
45
46     /**
47      * automatically calculate formulas (1)
48      */

49
50     public final static short AUTOMATIC = 1;
51
52     /**
53      * automatically calculate formulas except for tables (-1)
54      */

55
56     public final static short AUTOMATIC_EXCEPT_TABLES = -1;
57     private short field_1_calcmode;
58
59     public CalcModeRecord()
60     {
61     }
62
63     /**
64      * Constructs a CalcModeRecord and sets its fields appropriately
65      *
66      * @param id id must be 0xD or an exception will be throw upon validation
67      * @param size the size of the data area of the record
68      * @param data data of the record (should not contain sid/len)
69      */

70
71     public CalcModeRecord(short id, short size, byte [] data)
72     {
73         super(id, size, data);
74     }
75
76     /**
77      * Constructs a CalcModeRecord and sets its fields appropriately
78      *
79      * @param id id must be 0xD or an exception will be throw upon validation
80      * @param size the size of the data area of the record
81      * @param data data of the record (should not contain sid/len)
82      * @param offset of the record's start data
83      */

84
85     public CalcModeRecord(short id, short size, byte [] data, int offset)
86     {
87         super(id, size, data, offset);
88     }
89
90     protected void validateSid(short id)
91     {
92         if (id != sid)
93         {
94             throw new RecordFormatException("NOT An Calc Mode RECORD");
95         }
96     }
97
98     protected void fillFields(byte [] data, short size, int offset)
99     {
100         field_1_calcmode = LittleEndian.getShort(data, 0 + offset);
101     }
102
103     /**
104      * set the calc mode flag for formulas
105      *
106      * @see #MANUAL
107      * @see #AUTOMATIC
108      * @see #AUTOMATIC_EXCEPT_TABLES
109      *
110      * @param calcmode one of the three flags above
111      */

112
113     public void setCalcMode(short calcmode)
114     {
115         field_1_calcmode = calcmode;
116     }
117
118     /**
119      * get the calc mode flag for formulas
120      *
121      * @see #MANUAL
122      * @see #AUTOMATIC
123      * @see #AUTOMATIC_EXCEPT_TABLES
124      *
125      * @return calcmode one of the three flags above
126      */

127
128     public short getCalcMode()
129     {
130         return field_1_calcmode;
131     }
132
133     public String JavaDoc toString()
134     {
135         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
136
137         buffer.append("[CALCMODE]\n");
138         buffer.append(" .calcmode = ")
139             .append(Integer.toHexString(getCalcMode())).append("\n");
140         buffer.append("[/CALCMODE]\n");
141         return buffer.toString();
142     }
143
144     public int serialize(int offset, byte [] data)
145     {
146         LittleEndian.putShort(data, 0 + offset, sid);
147         LittleEndian.putShort(data, 2 + offset, ( short ) 0x2);
148         LittleEndian.putShort(data, 4 + offset, getCalcMode());
149         return getRecordSize();
150     }
151
152     public int getRecordSize()
153     {
154         return 6;
155     }
156
157     public short getSid()
158     {
159         return this.sid;
160     }
161
162     public Object JavaDoc clone() {
163       CalcModeRecord rec = new CalcModeRecord();
164       rec.field_1_calcmode = field_1_calcmode;
165       return rec;
166     }
167 }
168
Popular Tags