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 Column Width Record<P>
024: * Description: Specifies the default width for columns that have no specific
025: * width set.<P>
026: * REFERENCE: PG 302 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 DefaultColWidthRecord extends Record {
033: public final static short sid = 0x55;
034: private short field_1_col_width;
035:
036: public DefaultColWidthRecord() {
037: }
038:
039: /**
040: * Constructs a DefaultColumnWidth record and sets its fields appropriately.
041: * @param in the RecordInputstream to read the record from
042: */
043:
044: public DefaultColWidthRecord(RecordInputStream in) {
045: super (in);
046: }
047:
048: protected void validateSid(short id) {
049: if (id != sid) {
050: throw new RecordFormatException(
051: "NOT A DefaultColWidth RECORD");
052: }
053: }
054:
055: protected void fillFields(RecordInputStream in) {
056: field_1_col_width = in.readShort();
057: }
058:
059: /**
060: * set the default column width
061: * @param height defaultwidth for columns
062: */
063:
064: public void setColWidth(short height) {
065: field_1_col_width = height;
066: }
067:
068: /**
069: * get the default column width
070: * @return defaultwidth for columns
071: */
072:
073: public short getColWidth() {
074: return field_1_col_width;
075: }
076:
077: public String toString() {
078: StringBuffer buffer = new StringBuffer();
079:
080: buffer.append("[DEFAULTCOLWIDTH]\n");
081: buffer.append(" .colwidth = ").append(
082: Integer.toHexString(getColWidth())).append("\n");
083: buffer.append("[/DEFAULTCOLWIDTH]\n");
084: return buffer.toString();
085: }
086:
087: public int serialize(int offset, byte[] data) {
088: LittleEndian.putShort(data, 0 + offset, sid);
089: LittleEndian.putShort(data, 2 + offset, (short) 0x2);
090: LittleEndian.putShort(data, 4 + offset, getColWidth());
091: return getRecordSize();
092: }
093:
094: public int getRecordSize() {
095: return 6;
096: }
097:
098: public short getSid() {
099: return sid;
100: }
101:
102: public Object clone() {
103: DefaultColWidthRecord rec = new DefaultColWidthRecord();
104: rec.field_1_col_width = field_1_col_width;
105: return rec;
106: }
107: }
|