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: Label SST Record<P>
024: * Description: Refers to a string in the shared string table and is a column
025: * value. <P>
026: * REFERENCE: PG 325 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 LabelSSTRecord extends Record implements
033: CellValueRecordInterface, Comparable {
034: public final static short sid = 0xfd;
035: //private short field_1_row;
036: private int field_1_row;
037: private short field_2_column;
038: private short field_3_xf_index;
039: private int field_4_sst_index;
040:
041: public LabelSSTRecord() {
042: }
043:
044: /**
045: * Constructs an LabelSST record and sets its fields appropriately.
046: * @param in the RecordInputstream to read the record from
047: */
048:
049: public LabelSSTRecord(RecordInputStream in) {
050: super (in);
051: }
052:
053: protected void validateSid(short id) {
054: if (id != sid) {
055: throw new RecordFormatException(
056: "NOT A valid LabelSST RECORD");
057: }
058: }
059:
060: protected void fillFields(RecordInputStream in) {
061: //field_1_row = LittleEndian.getShort(data, 0 + offset);
062: field_1_row = in.readUShort();
063: field_2_column = in.readShort();
064: field_3_xf_index = in.readShort();
065: field_4_sst_index = in.readInt();
066: }
067:
068: //public void setRow(short row)
069: public void setRow(int row) {
070: field_1_row = row;
071: }
072:
073: public void setColumn(short col) {
074: field_2_column = col;
075: }
076:
077: /**
078: * set the index to the extended format record
079: *
080: * @see org.apache.poi.hssf.record.ExtendedFormatRecord
081: * @param index - the index to the XF record
082: */
083:
084: public void setXFIndex(short index) {
085: field_3_xf_index = index;
086: }
087:
088: /**
089: * set the index to the string in the SSTRecord
090: *
091: * @param index - of string in the SST Table
092: * @see org.apache.poi.hssf.record.SSTRecord
093: */
094:
095: public void setSSTIndex(int index) {
096: field_4_sst_index = index;
097: }
098:
099: //public short getRow()
100: public int getRow() {
101: return field_1_row;
102: }
103:
104: public short getColumn() {
105: return field_2_column;
106: }
107:
108: /**
109: * get the index to the extended format record
110: *
111: * @see org.apache.poi.hssf.record.ExtendedFormatRecord
112: * @return the index to the XF record
113: */
114:
115: public short getXFIndex() {
116: return field_3_xf_index;
117: }
118:
119: /**
120: * get the index to the string in the SSTRecord
121: *
122: * @return index of string in the SST Table
123: * @see org.apache.poi.hssf.record.SSTRecord
124: */
125:
126: public int getSSTIndex() {
127: return field_4_sst_index;
128: }
129:
130: public String toString() {
131: StringBuffer buffer = new StringBuffer();
132:
133: buffer.append("[LABELSST]\n");
134: buffer.append(" .row = ").append(
135: Integer.toHexString(getRow())).append("\n");
136: buffer.append(" .column = ").append(
137: Integer.toHexString(getColumn())).append("\n");
138: buffer.append(" .xfindex = ").append(
139: Integer.toHexString(getXFIndex())).append("\n");
140: buffer.append(" .sstindex = ").append(
141: Integer.toHexString(getSSTIndex())).append("\n");
142: buffer.append("[/LABELSST]\n");
143: return buffer.toString();
144: }
145:
146: public int serialize(int offset, byte[] data) {
147: LittleEndian.putShort(data, 0 + offset, sid);
148: LittleEndian.putShort(data, 2 + offset, (short) 10);
149: //LittleEndian.putShort(data, 4 + offset, getRow());
150: LittleEndian.putShort(data, 4 + offset, (short) getRow());
151: LittleEndian.putShort(data, 6 + offset, getColumn());
152: LittleEndian.putShort(data, 8 + offset, getXFIndex());
153: LittleEndian.putInt(data, 10 + offset, getSSTIndex());
154: return getRecordSize();
155: }
156:
157: public int getRecordSize() {
158: return 14;
159: }
160:
161: public short getSid() {
162: return sid;
163: }
164:
165: public boolean isBefore(CellValueRecordInterface i) {
166: if (this .getRow() > i.getRow()) {
167: return false;
168: }
169: if ((this .getRow() == i.getRow())
170: && (this .getColumn() > i.getColumn())) {
171: return false;
172: }
173: if ((this .getRow() == i.getRow())
174: && (this .getColumn() == i.getColumn())) {
175: return false;
176: }
177: return true;
178: }
179:
180: public boolean isAfter(CellValueRecordInterface i) {
181: if (this .getRow() < i.getRow()) {
182: return false;
183: }
184: if ((this .getRow() == i.getRow())
185: && (this .getColumn() < i.getColumn())) {
186: return false;
187: }
188: if ((this .getRow() == i.getRow())
189: && (this .getColumn() == i.getColumn())) {
190: return false;
191: }
192: return true;
193: }
194:
195: public boolean isEqual(CellValueRecordInterface i) {
196: return ((this .getRow() == i.getRow()) && (this .getColumn() == i
197: .getColumn()));
198: }
199:
200: public boolean isInValueSection() {
201: return true;
202: }
203:
204: public boolean isValue() {
205: return true;
206: }
207:
208: public int compareTo(Object obj) {
209: CellValueRecordInterface loc = (CellValueRecordInterface) obj;
210:
211: if ((this .getRow() == loc.getRow())
212: && (this .getColumn() == loc.getColumn())) {
213: return 0;
214: }
215: if (this .getRow() < loc.getRow()) {
216: return -1;
217: }
218: if (this .getRow() > loc.getRow()) {
219: return 1;
220: }
221: if (this .getColumn() < loc.getColumn()) {
222: return -1;
223: }
224: if (this .getColumn() > loc.getColumn()) {
225: return 1;
226: }
227: return -1;
228: }
229:
230: public boolean equals(Object obj) {
231: if (!(obj instanceof CellValueRecordInterface)) {
232: return false;
233: }
234: CellValueRecordInterface loc = (CellValueRecordInterface) obj;
235:
236: if ((this .getRow() == loc.getRow())
237: && (this .getColumn() == loc.getColumn())) {
238: return true;
239: }
240: return false;
241: }
242:
243: public Object clone() {
244: LabelSSTRecord rec = new LabelSSTRecord();
245: rec.field_1_row = field_1_row;
246: rec.field_2_column = field_2_column;
247: rec.field_3_xf_index = field_3_xf_index;
248: rec.field_4_sst_index = field_4_sst_index;
249: return rec;
250: }
251: }
|