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.*;
021:
022: /**
023: * The area format record is used to define the colours and patterns for an area.
024: * NOTE: This source is automatically generated please do not modify this file. Either subclass or
025: * remove the record in src/records/definitions.
026:
027: * @author Glen Stampoultzis (glens at apache.org)
028: */
029: public class AreaFormatRecord extends Record {
030: public final static short sid = 0x100a;
031: private int field_1_foregroundColor;
032: private int field_2_backgroundColor;
033: private short field_3_pattern;
034: private short field_4_formatFlags;
035: private BitField automatic = BitFieldFactory.getInstance(0x1);
036: private BitField invert = BitFieldFactory.getInstance(0x2);
037: private short field_5_forecolorIndex;
038: private short field_6_backcolorIndex;
039:
040: public AreaFormatRecord() {
041:
042: }
043:
044: /**
045: * Constructs a AreaFormat record and sets its fields appropriately.
046: *
047: * @param in the RecordInputstream to read the record from
048: */
049:
050: public AreaFormatRecord(RecordInputStream in) {
051: super (in);
052:
053: }
054:
055: /**
056: * Checks the sid matches the expected side for this record
057: *
058: * @param id the expected sid.
059: */
060: protected void validateSid(short id) {
061: if (id != sid) {
062: throw new RecordFormatException("Not a AreaFormat record");
063: }
064: }
065:
066: protected void fillFields(RecordInputStream in) {
067: field_1_foregroundColor = in.readInt();
068: field_2_backgroundColor = in.readInt();
069: field_3_pattern = in.readShort();
070: field_4_formatFlags = in.readShort();
071: field_5_forecolorIndex = in.readShort();
072: field_6_backcolorIndex = in.readShort();
073:
074: }
075:
076: public String toString() {
077: StringBuffer buffer = new StringBuffer();
078:
079: buffer.append("[AREAFORMAT]\n");
080: buffer.append(" .foregroundColor = ").append("0x")
081: .append(HexDump.toHex(getForegroundColor())).append(
082: " (").append(getForegroundColor()).append(" )");
083: buffer.append(System.getProperty("line.separator"));
084: buffer.append(" .backgroundColor = ").append("0x")
085: .append(HexDump.toHex(getBackgroundColor())).append(
086: " (").append(getBackgroundColor()).append(" )");
087: buffer.append(System.getProperty("line.separator"));
088: buffer.append(" .pattern = ").append("0x")
089: .append(HexDump.toHex(getPattern())).append(" (")
090: .append(getPattern()).append(" )");
091: buffer.append(System.getProperty("line.separator"));
092: buffer.append(" .formatFlags = ").append("0x")
093: .append(HexDump.toHex(getFormatFlags())).append(" (")
094: .append(getFormatFlags()).append(" )");
095: buffer.append(System.getProperty("line.separator"));
096: buffer.append(" .automatic = ").append(
097: isAutomatic()).append('\n');
098: buffer.append(" .invert = ").append(
099: isInvert()).append('\n');
100: buffer.append(" .forecolorIndex = ").append("0x")
101: .append(HexDump.toHex(getForecolorIndex()))
102: .append(" (").append(getForecolorIndex()).append(" )");
103: buffer.append(System.getProperty("line.separator"));
104: buffer.append(" .backcolorIndex = ").append("0x")
105: .append(HexDump.toHex(getBackcolorIndex()))
106: .append(" (").append(getBackcolorIndex()).append(" )");
107: buffer.append(System.getProperty("line.separator"));
108:
109: buffer.append("[/AREAFORMAT]\n");
110: return buffer.toString();
111: }
112:
113: public int serialize(int offset, byte[] data) {
114: int pos = 0;
115:
116: LittleEndian.putShort(data, 0 + offset, sid);
117: LittleEndian.putShort(data, 2 + offset,
118: (short) (getRecordSize() - 4));
119:
120: LittleEndian.putInt(data, 4 + offset + pos,
121: field_1_foregroundColor);
122: LittleEndian.putInt(data, 8 + offset + pos,
123: field_2_backgroundColor);
124: LittleEndian.putShort(data, 12 + offset + pos, field_3_pattern);
125: LittleEndian.putShort(data, 14 + offset + pos,
126: field_4_formatFlags);
127: LittleEndian.putShort(data, 16 + offset + pos,
128: field_5_forecolorIndex);
129: LittleEndian.putShort(data, 18 + offset + pos,
130: field_6_backcolorIndex);
131:
132: return getRecordSize();
133: }
134:
135: /**
136: * Size of record (exluding 4 byte header)
137: */
138: public int getRecordSize() {
139: return 4 + 4 + 4 + 2 + 2 + 2 + 2;
140: }
141:
142: public short getSid() {
143: return sid;
144: }
145:
146: public Object clone() {
147: AreaFormatRecord rec = new AreaFormatRecord();
148:
149: rec.field_1_foregroundColor = field_1_foregroundColor;
150: rec.field_2_backgroundColor = field_2_backgroundColor;
151: rec.field_3_pattern = field_3_pattern;
152: rec.field_4_formatFlags = field_4_formatFlags;
153: rec.field_5_forecolorIndex = field_5_forecolorIndex;
154: rec.field_6_backcolorIndex = field_6_backcolorIndex;
155: return rec;
156: }
157:
158: /**
159: * Get the foreground color field for the AreaFormat record.
160: */
161: public int getForegroundColor() {
162: return field_1_foregroundColor;
163: }
164:
165: /**
166: * Set the foreground color field for the AreaFormat record.
167: */
168: public void setForegroundColor(int field_1_foregroundColor) {
169: this .field_1_foregroundColor = field_1_foregroundColor;
170: }
171:
172: /**
173: * Get the background color field for the AreaFormat record.
174: */
175: public int getBackgroundColor() {
176: return field_2_backgroundColor;
177: }
178:
179: /**
180: * Set the background color field for the AreaFormat record.
181: */
182: public void setBackgroundColor(int field_2_backgroundColor) {
183: this .field_2_backgroundColor = field_2_backgroundColor;
184: }
185:
186: /**
187: * Get the pattern field for the AreaFormat record.
188: */
189: public short getPattern() {
190: return field_3_pattern;
191: }
192:
193: /**
194: * Set the pattern field for the AreaFormat record.
195: */
196: public void setPattern(short field_3_pattern) {
197: this .field_3_pattern = field_3_pattern;
198: }
199:
200: /**
201: * Get the format flags field for the AreaFormat record.
202: */
203: public short getFormatFlags() {
204: return field_4_formatFlags;
205: }
206:
207: /**
208: * Set the format flags field for the AreaFormat record.
209: */
210: public void setFormatFlags(short field_4_formatFlags) {
211: this .field_4_formatFlags = field_4_formatFlags;
212: }
213:
214: /**
215: * Get the forecolor index field for the AreaFormat record.
216: */
217: public short getForecolorIndex() {
218: return field_5_forecolorIndex;
219: }
220:
221: /**
222: * Set the forecolor index field for the AreaFormat record.
223: */
224: public void setForecolorIndex(short field_5_forecolorIndex) {
225: this .field_5_forecolorIndex = field_5_forecolorIndex;
226: }
227:
228: /**
229: * Get the backcolor index field for the AreaFormat record.
230: */
231: public short getBackcolorIndex() {
232: return field_6_backcolorIndex;
233: }
234:
235: /**
236: * Set the backcolor index field for the AreaFormat record.
237: */
238: public void setBackcolorIndex(short field_6_backcolorIndex) {
239: this .field_6_backcolorIndex = field_6_backcolorIndex;
240: }
241:
242: /**
243: * Sets the automatic field value.
244: * automatic formatting
245: */
246: public void setAutomatic(boolean value) {
247: field_4_formatFlags = automatic.setShortBoolean(
248: field_4_formatFlags, value);
249: }
250:
251: /**
252: * automatic formatting
253: * @return the automatic field value.
254: */
255: public boolean isAutomatic() {
256: return automatic.isSet(field_4_formatFlags);
257: }
258:
259: /**
260: * Sets the invert field value.
261: * swap foreground and background colours when data is negative
262: */
263: public void setInvert(boolean value) {
264: field_4_formatFlags = invert.setShortBoolean(
265: field_4_formatFlags, value);
266: }
267:
268: /**
269: * swap foreground and background colours when data is negative
270: * @return the invert field value.
271: */
272: public boolean isInvert() {
273: return invert.isSet(field_4_formatFlags);
274: }
275:
276: } // END OF CLASS
|