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: * BlankRecord.java
020: *
021: * Created on December 10, 2001, 12:07 PM
022: */
023: package org.apache.poi.hssf.record;
024:
025: import org.apache.poi.util.LittleEndian;
026:
027: /**
028: * Title: Blank cell record <P>
029: * Description: Represents a column in a row with no value but with styling.<P>
030: * REFERENCE: PG 287 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
031: * @author Andrew C. Oliver (acoliver at apache dot org)
032: * @author Jason Height (jheight at chariot dot net dot au)
033: * @version 2.0-pre
034: */
035:
036: public class BlankRecord extends Record implements
037: CellValueRecordInterface, Comparable {
038: public final static short sid = 0x201;
039: //private short field_1_row;
040: private int field_1_row;
041: private short field_2_col;
042: private short field_3_xf;
043:
044: /** Creates a new instance of BlankRecord */
045:
046: public BlankRecord() {
047: }
048:
049: /**
050: * Constructs a BlankRecord and sets its fields appropriately
051: * @param in the RecordInputstream to read the record from
052: */
053:
054: public BlankRecord(RecordInputStream in) {
055: super (in);
056: }
057:
058: protected void fillFields(RecordInputStream in) {
059: //field_1_row = LittleEndian.getShort(data, 0 + offset);
060: field_1_row = in.readUShort();
061: field_2_col = in.readShort();
062: field_3_xf = in.readShort();
063: }
064:
065: /**
066: * called by constructor, should throw runtime exception in the event of a
067: * record passed with a differing ID.
068: *
069: * @param id alleged id for this record
070: */
071:
072: protected void validateSid(short id) {
073: if (id != sid) {
074: throw new RecordFormatException("NOT A BLANKRECORD!");
075: }
076: }
077:
078: /**
079: * set the row this cell occurs on
080: * @param row the row this cell occurs within
081: */
082:
083: //public void setRow(short row)
084: public void setRow(int row) {
085: field_1_row = row;
086: }
087:
088: /**
089: * get the row this cell occurs on
090: *
091: * @return the row
092: */
093:
094: //public short getRow()
095: public int getRow() {
096: return field_1_row;
097: }
098:
099: /**
100: * get the column this cell defines within the row
101: *
102: * @return the column
103: */
104:
105: public short getColumn() {
106: return field_2_col;
107: }
108:
109: /**
110: * set the index of the extended format record to style this cell with
111: *
112: * @param xf - the 0-based index of the extended format
113: * @see org.apache.poi.hssf.record.ExtendedFormatRecord
114: */
115:
116: public void setXFIndex(short xf) {
117: field_3_xf = xf;
118: }
119:
120: /**
121: * get the index of the extended format record to style this cell with
122: *
123: * @return extended format index
124: */
125:
126: public short getXFIndex() {
127: return field_3_xf;
128: }
129:
130: /**
131: * set the column this cell defines within the row
132: *
133: * @param col the column this cell defines
134: */
135:
136: public void setColumn(short col) {
137: field_2_col = col;
138: }
139:
140: public boolean isBefore(CellValueRecordInterface i) {
141: if (this .getRow() > i.getRow()) {
142: return false;
143: }
144: if ((this .getRow() == i.getRow())
145: && (this .getColumn() > i.getColumn())) {
146: return false;
147: }
148: if ((this .getRow() == i.getRow())
149: && (this .getColumn() == i.getColumn())) {
150: return false;
151: }
152: return true;
153: }
154:
155: public boolean isAfter(CellValueRecordInterface i) {
156: if (this .getRow() < i.getRow()) {
157: return false;
158: }
159: if ((this .getRow() == i.getRow())
160: && (this .getColumn() < i.getColumn())) {
161: return false;
162: }
163: if ((this .getRow() == i.getRow())
164: && (this .getColumn() == i.getColumn())) {
165: return false;
166: }
167: return true;
168: }
169:
170: public boolean isEqual(CellValueRecordInterface i) {
171: return ((this .getRow() == i.getRow()) && (this .getColumn() == i
172: .getColumn()));
173: }
174:
175: public boolean isInValueSection() {
176: return true;
177: }
178:
179: public boolean isValue() {
180: return true;
181: }
182:
183: /**
184: * return the non static version of the id for this record.
185: */
186:
187: public short getSid() {
188: return sid;
189: }
190:
191: public String toString() {
192: StringBuffer buffer = new StringBuffer();
193:
194: buffer.append("[BLANK]\n");
195: buffer.append("row = ").append(
196: Integer.toHexString(getRow())).append("\n");
197: buffer.append("col = ").append(
198: Integer.toHexString(getColumn())).append("\n");
199: buffer.append("xf = ").append(
200: Integer.toHexString(getXFIndex())).append("\n");
201: buffer.append("[/BLANK]\n");
202: return buffer.toString();
203: }
204:
205: /**
206: * called by the class that is responsible for writing this sucker.
207: * Subclasses should implement this so that their data is passed back in a
208: * byte array.
209: *
210: * @return byte array containing instance data
211: */
212:
213: public int serialize(int offset, byte[] data) {
214: LittleEndian.putShort(data, 0 + offset, sid);
215: LittleEndian.putShort(data, 2 + offset, (short) 6);
216: //LittleEndian.putShort(data, 4 + offset, getRow());
217: LittleEndian.putShort(data, 4 + offset, (short) getRow());
218: LittleEndian.putShort(data, 6 + offset, getColumn());
219: LittleEndian.putShort(data, 8 + offset, getXFIndex());
220: return getRecordSize();
221: }
222:
223: public int getRecordSize() {
224: return 10;
225: }
226:
227: public int compareTo(Object obj) {
228: CellValueRecordInterface loc = (CellValueRecordInterface) obj;
229:
230: if ((this .getRow() == loc.getRow())
231: && (this .getColumn() == loc.getColumn())) {
232: return 0;
233: }
234: if (this .getRow() < loc.getRow()) {
235: return -1;
236: }
237: if (this .getRow() > loc.getRow()) {
238: return 1;
239: }
240: if (this .getColumn() < loc.getColumn()) {
241: return -1;
242: }
243: if (this .getColumn() > loc.getColumn()) {
244: return 1;
245: }
246: return -1;
247: }
248:
249: public boolean equals(Object obj) {
250: if (!(obj instanceof CellValueRecordInterface)) {
251: return false;
252: }
253: CellValueRecordInterface loc = (CellValueRecordInterface) obj;
254:
255: if ((this .getRow() == loc.getRow())
256: && (this .getColumn() == loc.getColumn())) {
257: return true;
258: }
259: return false;
260: }
261:
262: public Object clone() {
263: BlankRecord rec = new BlankRecord();
264: rec.field_1_row = field_1_row;
265: rec.field_2_col = field_2_col;
266: rec.field_3_xf = field_3_xf;
267: return rec;
268: }
269: }
|