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: /*
019: * MulBlankRecord.java
020: *
021: * Created on December 10, 2001, 12:49 PM
022: */
023: package org.apache.poi.hssf.record;
024:
025: /**
026: * Title: Mulitple Blank cell record <P>
027: * Description: Represents a set of columns in a row with no value but with styling.
028: * In this release we have read-only support for this record type.
029: * The RecordFactory converts this to a set of BlankRecord objects.<P>
030: * REFERENCE: PG 329 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
031: * @author Andrew C. Oliver (acoliver at apache dot org)
032: * @author Glen Stampoultzis (glens at apache.org)
033: * @version 2.0-pre
034: * @see org.apache.poi.hssf.record.BlankRecord
035: */
036:
037: public class MulBlankRecord extends Record {
038: public final static short sid = 0xbe;
039: //private short field_1_row;
040: private int field_1_row;
041: private short field_2_first_col;
042: private short[] field_3_xfs;
043: private short field_4_last_col;
044:
045: /** Creates new MulBlankRecord */
046:
047: public MulBlankRecord() {
048: }
049:
050: /**
051: * Constructs a MulBlank record and sets its fields appropriately.
052: *
053: * @param in the RecordInputstream to read the record from
054: */
055:
056: public MulBlankRecord(RecordInputStream in) {
057: super (in);
058: }
059:
060: /**
061: * get the row number of the cells this represents
062: *
063: * @return row number
064: */
065:
066: //public short getRow()
067: public int getRow() {
068: return field_1_row;
069: }
070:
071: /**
072: * starting column (first cell this holds in the row)
073: * @return first column number
074: */
075:
076: public short getFirstColumn() {
077: return field_2_first_col;
078: }
079:
080: /**
081: * ending column (last cell this holds in the row)
082: * @return first column number
083: */
084:
085: public short getLastColumn() {
086: return field_4_last_col;
087: }
088:
089: /**
090: * get the number of columns this contains (last-first +1)
091: * @return number of columns (last - first +1)
092: */
093:
094: public int getNumColumns() {
095: return field_4_last_col - field_2_first_col + 1;
096: }
097:
098: /**
099: * returns the xf index for column (coffset = column - field_2_first_col)
100: * @param coffset the column (coffset = column - field_2_first_col)
101: * @return the XF index for the column
102: */
103:
104: public short getXFAt(int coffset) {
105: return field_3_xfs[coffset];
106: }
107:
108: /**
109: * @param in the RecordInputstream to read the record from
110: */
111: protected void fillFields(RecordInputStream in) {
112: //field_1_row = LittleEndian.getShort(data, 0 + offset);
113: field_1_row = in.readUShort();
114: field_2_first_col = in.readShort();
115: field_3_xfs = parseXFs(in);
116: field_4_last_col = in.readShort();
117: }
118:
119: private short[] parseXFs(RecordInputStream in) {
120: short[] retval = new short[(in.remaining() - 2) / 2];
121:
122: for (int idx = 0; idx < retval.length; idx++) {
123: retval[idx] = in.readShort();
124: }
125: return retval;
126: }
127:
128: public String toString() {
129: StringBuffer buffer = new StringBuffer();
130:
131: buffer.append("[MULBLANK]\n");
132: buffer.append("row = ").append(Integer.toHexString(getRow()))
133: .append("\n");
134: buffer.append("firstcol = ").append(
135: Integer.toHexString(getFirstColumn())).append("\n");
136: buffer.append(" lastcol = ").append(
137: Integer.toHexString(getLastColumn())).append("\n");
138: for (int k = 0; k < getNumColumns(); k++) {
139: buffer.append("xf").append(k).append(" = ").append(
140: Integer.toHexString(getXFAt(k))).append("\n");
141: }
142: buffer.append("[/MULBLANK]\n");
143: return buffer.toString();
144: }
145:
146: /**
147: * called by constructor, should throw runtime exception in the event of a
148: * record passed with a differing ID.
149: *
150: * @param id alleged id for this record
151: */
152:
153: protected void validateSid(short id) {
154: if (id != sid) {
155: throw new RecordFormatException("Not a MulBlankRecord!");
156: }
157: }
158:
159: public short getSid() {
160: return sid;
161: }
162:
163: public int serialize(int offset, byte[] data) {
164: throw new RecordFormatException(
165: "Sorry, you can't serialize a MulBlank in this release");
166: }
167: }
|