001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Title: Calc Mode Record<P>
024: * Description: Tells the gui whether to calculate formulas
025: * automatically, manually or automatically
026: * except for tables.<P>
027: * REFERENCE: PG 292 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
028: * @author Andrew C. Oliver (acoliver at apache dot org)
029: * @author Jason Height (jheight at chariot dot net dot au)
030: * @version 2.0-pre
031: * @see org.apache.poi.hssf.record.CalcCountRecord
032: */
033:
034: public class CalcModeRecord extends Record {
035: public final static short sid = 0xD;
036:
037: /**
038: * manually calculate formulas (0)
039: */
040:
041: public final static short MANUAL = 0;
042:
043: /**
044: * automatically calculate formulas (1)
045: */
046:
047: public final static short AUTOMATIC = 1;
048:
049: /**
050: * automatically calculate formulas except for tables (-1)
051: */
052:
053: public final static short AUTOMATIC_EXCEPT_TABLES = -1;
054: private short field_1_calcmode;
055:
056: public CalcModeRecord() {
057: }
058:
059: /**
060: * Constructs a CalcModeRecord and sets its fields appropriately
061: * @param in the RecordInputstream to read the record from
062: */
063:
064: public CalcModeRecord(RecordInputStream in) {
065: super (in);
066: }
067:
068: protected void validateSid(short id) {
069: if (id != sid) {
070: throw new RecordFormatException("NOT An Calc Mode RECORD");
071: }
072: }
073:
074: protected void fillFields(RecordInputStream in) {
075: field_1_calcmode = in.readShort();
076: }
077:
078: /**
079: * set the calc mode flag for formulas
080: *
081: * @see #MANUAL
082: * @see #AUTOMATIC
083: * @see #AUTOMATIC_EXCEPT_TABLES
084: *
085: * @param calcmode one of the three flags above
086: */
087:
088: public void setCalcMode(short calcmode) {
089: field_1_calcmode = calcmode;
090: }
091:
092: /**
093: * get the calc mode flag for formulas
094: *
095: * @see #MANUAL
096: * @see #AUTOMATIC
097: * @see #AUTOMATIC_EXCEPT_TABLES
098: *
099: * @return calcmode one of the three flags above
100: */
101:
102: public short getCalcMode() {
103: return field_1_calcmode;
104: }
105:
106: public String toString() {
107: StringBuffer buffer = new StringBuffer();
108:
109: buffer.append("[CALCMODE]\n");
110: buffer.append(" .calcmode = ").append(
111: Integer.toHexString(getCalcMode())).append("\n");
112: buffer.append("[/CALCMODE]\n");
113: return buffer.toString();
114: }
115:
116: public int serialize(int offset, byte[] data) {
117: LittleEndian.putShort(data, 0 + offset, sid);
118: LittleEndian.putShort(data, 2 + offset, (short) 0x2);
119: LittleEndian.putShort(data, 4 + offset, getCalcMode());
120: return getRecordSize();
121: }
122:
123: public int getRecordSize() {
124: return 6;
125: }
126:
127: public short getSid() {
128: return sid;
129: }
130:
131: public Object clone() {
132: CalcModeRecord rec = new CalcModeRecord();
133: rec.field_1_calcmode = field_1_calcmode;
134: return rec;
135: }
136: }
|