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: Use Natural Language Formulas Flag<P>
024: * Description: Tells the GUI if this was written by something that can use
025: * "natural language" formulas. HSSF can't.<P>
026: * REFERENCE: PG 420 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
027: * @author Andrew C. Oliver (acoliver at apache dot org)
028: * @version 2.0-pre
029: */
030:
031: public class UseSelFSRecord extends Record {
032: public final static short sid = 0x160;
033: public final static short TRUE = 1;
034: public final static short FALSE = 0;
035: private short field_1_flag;
036:
037: public UseSelFSRecord() {
038: }
039:
040: /**
041: * Constructs a UseSelFS record and sets its fields appropriately.
042: * @param in the RecordInputstream to read the record from
043: */
044:
045: public UseSelFSRecord(RecordInputStream in) {
046: super (in);
047: }
048:
049: protected void validateSid(short id) {
050: if (id != sid) {
051: throw new RecordFormatException("NOT A UseSelFS RECORD");
052: }
053: }
054:
055: protected void fillFields(RecordInputStream in) {
056: field_1_flag = in.readShort();
057: }
058:
059: /**
060: * turn the flag on or off
061: *
062: * @param flag whether to use natural language formulas or not
063: * @see #TRUE
064: * @see #FALSE
065: */
066:
067: public void setFlag(short flag) {
068: field_1_flag = flag;
069: }
070:
071: /**
072: * returns whether we use natural language formulas or not
073: *
074: * @return whether to use natural language formulas or not
075: * @see #TRUE
076: * @see #FALSE
077: */
078:
079: public short getFlag() {
080: return field_1_flag;
081: }
082:
083: public String toString() {
084: StringBuffer buffer = new StringBuffer();
085:
086: buffer.append("[USESELFS]\n");
087: buffer.append(" .flag = ").append(
088: Integer.toHexString(getFlag())).append("\n");
089: buffer.append("[/USESELFS]\n");
090: return buffer.toString();
091: }
092:
093: public int serialize(int offset, byte[] data) {
094: LittleEndian.putShort(data, 0 + offset, sid);
095: LittleEndian.putShort(data, 2 + offset, ((short) 0x02)); // 2 bytes (6 total)
096: LittleEndian.putShort(data, 4 + offset, getFlag());
097: return getRecordSize();
098: }
099:
100: public int getRecordSize() {
101: return 6;
102: }
103:
104: public short getSid() {
105: return sid;
106: }
107: }
|