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: RefMode Record<P>
024: * Description: Describes which reference mode to use<P>
025: * REFERENCE: PG 376 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
026: * @author Andrew C. Oliver (acoliver at apache dot org)
027: * @author Jason Height (jheight at chariot dot net dot au)
028: * @version 2.0-pre
029: */
030:
031: public class RefModeRecord extends Record {
032: public final static short sid = 0xf;
033: public final static short USE_A1_MODE = 1;
034: public final static short USE_R1C1_MODE = 0;
035: private short field_1_mode;
036:
037: public RefModeRecord() {
038: }
039:
040: /**
041: * Constructs a RefMode record and sets its fields appropriately.
042: * @param in the RecordInputstream to read the record from
043: */
044:
045: public RefModeRecord(RecordInputStream in) {
046: super (in);
047: }
048:
049: protected void validateSid(short id) {
050: if (id != sid) {
051: throw new RecordFormatException("NOT An RefMode RECORD");
052: }
053: }
054:
055: protected void fillFields(RecordInputStream in) {
056: field_1_mode = in.readShort();
057: }
058:
059: /**
060: * set the reference mode to use (HSSF uses/assumes A1)
061: * @param mode the mode to use
062: * @see #USE_A1_MODE
063: * @see #USE_R1C1_MODE
064: *
065: */
066:
067: public void setMode(short mode) {
068: field_1_mode = mode;
069: }
070:
071: /**
072: * get the reference mode to use (HSSF uses/assumes A1)
073: * @return mode to use
074: * @see #USE_A1_MODE
075: * @see #USE_R1C1_MODE
076: */
077:
078: public short getMode() {
079: return field_1_mode;
080: }
081:
082: public String toString() {
083: StringBuffer buffer = new StringBuffer();
084:
085: buffer.append("[REFMODE]\n");
086: buffer.append(" .mode = ").append(
087: Integer.toHexString(getMode())).append("\n");
088: buffer.append("[/REFMODE]\n");
089: return buffer.toString();
090: }
091:
092: public int serialize(int offset, byte[] data) {
093: LittleEndian.putShort(data, 0 + offset, sid);
094: LittleEndian.putShort(data, 2 + offset, (short) 0x2);
095: LittleEndian.putShort(data, 4 + offset, getMode());
096: return getRecordSize();
097: }
098:
099: public int getRecordSize() {
100: return 6;
101: }
102:
103: public short getSid() {
104: return sid;
105: }
106:
107: public Object clone() {
108: RefModeRecord rec = new RefModeRecord();
109: rec.field_1_mode = field_1_mode;
110: return rec;
111: }
112: }
|