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.ddf;
019:
020: import org.apache.poi.util.HexDump;
021: import org.apache.poi.util.LittleEndian;
022: import org.apache.poi.hssf.record.RecordFormatException;
023:
024: /**
025: * A list of the most recently used colours for the drawings contained in
026: * this document.
027: *
028: * @author Glen Stampoultzis (glens at apache.org)
029: */
030: public class EscherSplitMenuColorsRecord extends EscherRecord {
031: public static final short RECORD_ID = (short) 0xF11E;
032: public static final String RECORD_DESCRIPTION = "MsofbtSplitMenuColors";
033:
034: private int field_1_color1;
035: private int field_2_color2;
036: private int field_3_color3;
037: private int field_4_color4;
038:
039: /**
040: * This method deserializes the record from a byte array.
041: *
042: * @param data The byte array containing the escher record information
043: * @param offset The starting offset into <code>data</code>.
044: * @param recordFactory May be null since this is not a container record.
045: * @return The number of bytes read from the byte array.
046: */
047: public int fillFields(byte[] data, int offset,
048: EscherRecordFactory recordFactory) {
049: int bytesRemaining = readHeader(data, offset);
050: int pos = offset + 8;
051: int size = 0;
052: field_1_color1 = LittleEndian.getInt(data, pos + size);
053: size += 4;
054: field_2_color2 = LittleEndian.getInt(data, pos + size);
055: size += 4;
056: field_3_color3 = LittleEndian.getInt(data, pos + size);
057: size += 4;
058: field_4_color4 = LittleEndian.getInt(data, pos + size);
059: size += 4;
060: bytesRemaining -= size;
061: if (bytesRemaining != 0)
062: throw new RecordFormatException(
063: "Expecting no remaining data but got "
064: + bytesRemaining + " byte(s).");
065: return 8 + size + bytesRemaining;
066: }
067:
068: /**
069: * This method serializes this escher record into a byte array.
070: *
071: * @param offset The offset into <code>data</code> to start writing the record data to.
072: * @param data The byte array to serialize to.
073: * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events.
074: * @return The number of bytes written.
075: *
076: * @see NullEscherSerializationListener
077: */
078: public int serialize(int offset, byte[] data,
079: EscherSerializationListener listener) {
080: // int field_2_numIdClusters = field_5_fileIdClusters.length + 1;
081: listener.beforeRecordSerialize(offset, getRecordId(), this );
082:
083: int pos = offset;
084: LittleEndian.putShort(data, pos, getOptions());
085: pos += 2;
086: LittleEndian.putShort(data, pos, getRecordId());
087: pos += 2;
088: int remainingBytes = getRecordSize() - 8;
089:
090: LittleEndian.putInt(data, pos, remainingBytes);
091: pos += 4;
092: LittleEndian.putInt(data, pos, field_1_color1);
093: pos += 4;
094: LittleEndian.putInt(data, pos, field_2_color2);
095: pos += 4;
096: LittleEndian.putInt(data, pos, field_3_color3);
097: pos += 4;
098: LittleEndian.putInt(data, pos, field_4_color4);
099: pos += 4;
100: listener.afterRecordSerialize(pos, getRecordId(), pos - offset,
101: this );
102: return getRecordSize();
103: }
104:
105: /**
106: * Returns the number of bytes that are required to serialize this record.
107: *
108: * @return Number of bytes
109: */
110: public int getRecordSize() {
111: return 8 + 4 * 4;
112: }
113:
114: /**
115: * @return the 16 bit identifer for this record.
116: */
117: public short getRecordId() {
118: return RECORD_ID;
119: }
120:
121: /**
122: * The short name for this record
123: */
124: public String getRecordName() {
125: return "SplitMenuColors";
126: }
127:
128: /**
129: * @return a string representation of this record.
130: */
131: public String toString() {
132: String nl = System.getProperty("line.separator");
133:
134: // String extraData;
135: // ByteArrayOutputStream b = new ByteArrayOutputStream();
136: // try
137: // {
138: // HexDump.dump(this.remainingData, 0, b, 0);
139: // extraData = b.toString();
140: // }
141: // catch ( Exception e )
142: // {
143: // extraData = "error";
144: // }
145: return getClass().getName() + ":" + nl + " RecordId: 0x"
146: + HexDump.toHex(RECORD_ID) + nl + " Options: 0x"
147: + HexDump.toHex(getOptions()) + nl + " Color1: 0x"
148: + HexDump.toHex(field_1_color1) + nl + " Color2: 0x"
149: + HexDump.toHex(field_2_color2) + nl + " Color3: 0x"
150: + HexDump.toHex(field_3_color3) + nl + " Color4: 0x"
151: + HexDump.toHex(field_4_color4) + nl + "";
152:
153: }
154:
155: public int getColor1() {
156: return field_1_color1;
157: }
158:
159: public void setColor1(int field_1_color1) {
160: this .field_1_color1 = field_1_color1;
161: }
162:
163: public int getColor2() {
164: return field_2_color2;
165: }
166:
167: public void setColor2(int field_2_color2) {
168: this .field_2_color2 = field_2_color2;
169: }
170:
171: public int getColor3() {
172: return field_3_color3;
173: }
174:
175: public void setColor3(int field_3_color3) {
176: this .field_3_color3 = field_3_color3;
177: }
178:
179: public int getColor4() {
180: return field_4_color4;
181: }
182:
183: public void setColor4(int field_4_color4) {
184: this.field_4_color4 = field_4_color4;
185: }
186:
187: }
|