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: Print Headers Record<P>
024: * Description: Whether or not to print the row/column headers when you
025: * enjoy your spreadsheet in the physical form.<P>
026: * REFERENCE: PG 373 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
027: * @author Andrew C. Oliver (acoliver at apache dot org)
028: * @author Jason Height (jheight at chariot dot net dot au)
029: * @version 2.0-pre
030: */
031:
032: public class PrintHeadersRecord extends Record {
033: public final static short sid = 0x2a;
034: private short field_1_print_headers;
035:
036: public PrintHeadersRecord() {
037: }
038:
039: /**
040: * Constructs a PrintHeaders record and sets its fields appropriately.
041: * @param in the RecordInputstream to read the record from
042: */
043:
044: public PrintHeadersRecord(RecordInputStream in) {
045: super (in);
046: }
047:
048: protected void validateSid(short id) {
049: if (id != sid) {
050: throw new RecordFormatException("NOT A PrintHeaders RECORD");
051: }
052: }
053:
054: protected void fillFields(RecordInputStream in) {
055: field_1_print_headers = in.readShort();
056: }
057:
058: /**
059: * set to print the headers - y/n
060: * @param p printheaders or not
061: */
062:
063: public void setPrintHeaders(boolean p) {
064: if (p == true) {
065: field_1_print_headers = 1;
066: } else {
067: field_1_print_headers = 0;
068: }
069: }
070:
071: /**
072: * get whether to print the headers - y/n
073: * @return printheaders or not
074: */
075:
076: public boolean getPrintHeaders() {
077: return (field_1_print_headers == 1);
078: }
079:
080: public String toString() {
081: StringBuffer buffer = new StringBuffer();
082:
083: buffer.append("[PRINTHEADERS]\n");
084: buffer.append(" .printheaders = ").append(
085: getPrintHeaders()).append("\n");
086: buffer.append("[/PRINTHEADERS]\n");
087: return buffer.toString();
088: }
089:
090: public int serialize(int offset, byte[] data) {
091: LittleEndian.putShort(data, 0 + offset, sid);
092: LittleEndian.putShort(data, 2 + offset, (short) 0x2);
093: LittleEndian.putShort(data, 4 + offset, field_1_print_headers);
094: return getRecordSize();
095: }
096:
097: public int getRecordSize() {
098: return 6;
099: }
100:
101: public short getSid() {
102: return sid;
103: }
104:
105: public Object clone() {
106: PrintHeadersRecord rec = new PrintHeadersRecord();
107: rec.field_1_print_headers = field_1_print_headers;
108: return rec;
109: }
110: }
|