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: HCenter record<P>
024: * Description: whether to center between horizontal margins<P>
025: * REFERENCE: PG 320 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 HCenterRecord extends Record {
032: public final static short sid = 0x83;
033: private short field_1_hcenter;
034:
035: public HCenterRecord() {
036: }
037:
038: /**
039: * Constructs an HCenter record and sets its fields appropriately.
040: * @param in the RecordInputstream to read the record from
041: */
042:
043: public HCenterRecord(RecordInputStream in) {
044: super (in);
045: }
046:
047: protected void validateSid(short id) {
048: if (id != sid) {
049: throw new RecordFormatException("NOT A HCenter RECORD");
050: }
051: }
052:
053: protected void fillFields(RecordInputStream in) {
054: field_1_hcenter = in.readShort();
055: }
056:
057: /**
058: * set whether or not to horizonatally center this sheet.
059: * @param hc center - t/f
060: */
061:
062: public void setHCenter(boolean hc) {
063: if (hc == true) {
064: field_1_hcenter = 1;
065: } else {
066: field_1_hcenter = 0;
067: }
068: }
069:
070: /**
071: * get whether or not to horizonatally center this sheet.
072: * @return center - t/f
073: */
074:
075: public boolean getHCenter() {
076: return (field_1_hcenter == 1);
077: }
078:
079: public String toString() {
080: StringBuffer buffer = new StringBuffer();
081:
082: buffer.append("[HCENTER]\n");
083: buffer.append(" .hcenter = ").append(getHCenter())
084: .append("\n");
085: buffer.append("[/HCENTER]\n");
086: return buffer.toString();
087: }
088:
089: public int serialize(int offset, byte[] data) {
090: LittleEndian.putShort(data, 0 + offset, sid);
091: LittleEndian.putShort(data, 2 + offset, (short) 0x2);
092: LittleEndian
093: .putShort(data, 4 + offset, (short) field_1_hcenter);
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: HCenterRecord rec = new HCenterRecord();
107: rec.field_1_hcenter = field_1_hcenter;
108: return rec;
109: }
110: }
|