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: Default Row Height Record
024: * Description: Row height for rows with undefined or not explicitly defined
025: * heights.
026: * REFERENCE: PG 301 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 DefaultRowHeightRecord extends Record {
033: public final static short sid = 0x225;
034: private short field_1_option_flags;
035: private short field_2_row_height;
036:
037: public DefaultRowHeightRecord() {
038: }
039:
040: /**
041: * Constructs a DefaultRowHeight record and sets its fields appropriately.
042: * @param in the RecordInputstream to read the record from
043: */
044:
045: public DefaultRowHeightRecord(RecordInputStream in) {
046: super (in);
047: }
048:
049: protected void validateSid(short id) {
050: if (id != sid) {
051: throw new RecordFormatException(
052: "NOT A DefaultRowHeight RECORD");
053: }
054: }
055:
056: protected void fillFields(RecordInputStream in) {
057: field_1_option_flags = in.readShort();
058: field_2_row_height = in.readShort();
059: }
060:
061: /**
062: * set the (currently unimportant to HSSF) option flags
063: * @param flags the bitmask to set
064: */
065:
066: public void setOptionFlags(short flags) {
067: field_1_option_flags = flags;
068: }
069:
070: /**
071: * set the default row height
072: * @param height for undefined rows/rows w/undefined height
073: */
074:
075: public void setRowHeight(short height) {
076: field_2_row_height = height;
077: }
078:
079: /**
080: * get the (currently unimportant to HSSF) option flags
081: * @return flags - the current bitmask
082: */
083:
084: public short getOptionFlags() {
085: return field_1_option_flags;
086: }
087:
088: /**
089: * get the default row height
090: * @return rowheight for undefined rows/rows w/undefined height
091: */
092:
093: public short getRowHeight() {
094: return field_2_row_height;
095: }
096:
097: public String toString() {
098: StringBuffer buffer = new StringBuffer();
099:
100: buffer.append("[DEFAULTROWHEIGHT]\n");
101: buffer.append(" .optionflags = ").append(
102: Integer.toHexString(getOptionFlags())).append("\n");
103: buffer.append(" .rowheight = ").append(
104: Integer.toHexString(getRowHeight())).append("\n");
105: buffer.append("[/DEFAULTROWHEIGHT]\n");
106: return buffer.toString();
107: }
108:
109: public int serialize(int offset, byte[] data) {
110: LittleEndian.putShort(data, 0 + offset, sid);
111: LittleEndian.putShort(data, 2 + offset, (short) 0x4);
112: LittleEndian.putShort(data, 4 + offset, getOptionFlags());
113: LittleEndian.putShort(data, 6 + offset, getRowHeight());
114: return getRecordSize();
115: }
116:
117: public int getRecordSize() {
118: return 8;
119: }
120:
121: public short getSid() {
122: return sid;
123: }
124:
125: public Object clone() {
126: DefaultRowHeightRecord rec = new DefaultRowHeightRecord();
127: rec.field_1_option_flags = field_1_option_flags;
128: rec.field_2_row_height = field_2_row_height;
129: return rec;
130: }
131: }
|