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: import org.apache.poi.util.BitField;
022: import org.apache.poi.util.BitFieldFactory;
023:
024: /**
025: * Class ChartFormatRecord
026: *
027: *
028: * @author Glen Stampoultzis (glens at apache.org)
029: * @version %I%, %G%
030: */
031:
032: public class ChartFormatRecord extends Record {
033: public static final short sid = 0x1014;
034:
035: // ignored?
036: private int field1_x_position; // lower left
037: private int field2_y_position; // lower left
038: private int field3_width;
039: private int field4_height;
040: private short field5_grbit;
041: private BitField varyDisplayPattern = BitFieldFactory
042: .getInstance(0x01);
043:
044: public ChartFormatRecord() {
045: }
046:
047: /**
048: * Constructs a ChartFormatRecord record and sets its fields appropriately.
049: * @param in the RecordInputstream to read the record from
050: */
051:
052: public ChartFormatRecord(RecordInputStream in) {
053: super (in);
054: }
055:
056: protected void validateSid(short id) {
057: if (id != sid) {
058: throw new RecordFormatException("NOT A CHARTFORMAT RECORD");
059: }
060: }
061:
062: protected void fillFields(RecordInputStream in) {
063: field1_x_position = in.readInt();
064: field2_y_position = in.readInt();
065: field3_width = in.readInt();
066: field4_height = in.readInt();
067: field5_grbit = in.readShort();
068: }
069:
070: public String toString() {
071: StringBuffer buffer = new StringBuffer();
072:
073: buffer.append("[CHARTFORMAT]\n");
074: buffer.append(" .xPosition = ").append(getXPosition())
075: .append("\n");
076: buffer.append(" .yPosition = ").append(getYPosition())
077: .append("\n");
078: buffer.append(" .width = ").append(getWidth())
079: .append("\n");
080: buffer.append(" .height = ").append(getHeight())
081: .append("\n");
082: buffer.append(" .grBit = ").append(
083: Integer.toHexString(field5_grbit)).append("\n");
084: buffer.append("[/CHARTFORMAT]\n");
085: return buffer.toString();
086: }
087:
088: public int serialize(int offset, byte[] data) {
089: LittleEndian.putShort(data, 0 + offset, sid);
090: LittleEndian.putShort(data, 2 + offset, ((short) 22)); // 22 byte length
091: LittleEndian.putInt(data, 4 + offset, getXPosition());
092: LittleEndian.putInt(data, 8 + offset, getYPosition());
093: LittleEndian.putInt(data, 12 + offset, getWidth());
094: LittleEndian.putInt(data, 16 + offset, getHeight());
095: LittleEndian.putShort(data, 20 + offset, field5_grbit);
096: return getRecordSize();
097: }
098:
099: public int getRecordSize() {
100: return 22;
101: }
102:
103: public short getSid() {
104: return sid;
105: }
106:
107: public int getXPosition() {
108: return field1_x_position;
109: }
110:
111: public void setXPosition(int xPosition) {
112: this .field1_x_position = xPosition;
113: }
114:
115: public int getYPosition() {
116: return field2_y_position;
117: }
118:
119: public void setYPosition(int yPosition) {
120: this .field2_y_position = yPosition;
121: }
122:
123: public int getWidth() {
124: return field3_width;
125: }
126:
127: public void setWidth(int width) {
128: this .field3_width = width;
129: }
130:
131: public int getHeight() {
132: return field4_height;
133: }
134:
135: public void setHeight(int height) {
136: this .field4_height = height;
137: }
138:
139: public boolean getVaryDisplayPattern() {
140: return varyDisplayPattern.isSet(field5_grbit);
141: }
142:
143: public void setVaryDisplayPattern(boolean value) {
144: field5_grbit = varyDisplayPattern.setShortBoolean(field5_grbit,
145: value);
146: }
147: }
|