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 chart record is used to define the location and size of a chart.
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 ChartRecord extends Record {
030: public final static short sid = 0x1002;
031: private int field_1_x;
032: private int field_2_y;
033: private int field_3_width;
034: private int field_4_height;
035:
036: public ChartRecord() {
037:
038: }
039:
040: /**
041: * Constructs a Chart record and sets its fields appropriately.
042: *
043: * @param in the RecordInputstream to read the record from
044: */
045:
046: public ChartRecord(RecordInputStream in) {
047: super (in);
048:
049: }
050:
051: /**
052: * Checks the sid matches the expected side for this record
053: *
054: * @param id the expected sid.
055: */
056: protected void validateSid(short id) {
057: if (id != sid) {
058: throw new RecordFormatException("Not a Chart record");
059: }
060: }
061:
062: protected void fillFields(RecordInputStream in) {
063: field_1_x = in.readInt();
064: field_2_y = in.readInt();
065: field_3_width = in.readInt();
066: field_4_height = in.readInt();
067: }
068:
069: public String toString() {
070: StringBuffer buffer = new StringBuffer();
071:
072: buffer.append("[CHART]\n");
073: buffer.append(" .x = ").append("0x")
074: .append(HexDump.toHex(getX())).append(" (").append(
075: getX()).append(" )");
076: buffer.append(System.getProperty("line.separator"));
077: buffer.append(" .y = ").append("0x")
078: .append(HexDump.toHex(getY())).append(" (").append(
079: getY()).append(" )");
080: buffer.append(System.getProperty("line.separator"));
081: buffer.append(" .width = ").append("0x")
082: .append(HexDump.toHex(getWidth())).append(" (").append(
083: getWidth()).append(" )");
084: buffer.append(System.getProperty("line.separator"));
085: buffer.append(" .height = ").append("0x")
086: .append(HexDump.toHex(getHeight())).append(" (")
087: .append(getHeight()).append(" )");
088: buffer.append(System.getProperty("line.separator"));
089:
090: buffer.append("[/CHART]\n");
091: return buffer.toString();
092: }
093:
094: public int serialize(int offset, byte[] data) {
095: int pos = 0;
096:
097: LittleEndian.putShort(data, 0 + offset, sid);
098: LittleEndian.putShort(data, 2 + offset,
099: (short) (getRecordSize() - 4));
100:
101: LittleEndian.putInt(data, 4 + offset + pos, field_1_x);
102: LittleEndian.putInt(data, 8 + offset + pos, field_2_y);
103: LittleEndian.putInt(data, 12 + offset + pos, field_3_width);
104: LittleEndian.putInt(data, 16 + offset + pos, field_4_height);
105:
106: return getRecordSize();
107: }
108:
109: /**
110: * Size of record (exluding 4 byte header)
111: */
112: public int getRecordSize() {
113: return 4 + 4 + 4 + 4 + 4;
114: }
115:
116: public short getSid() {
117: return sid;
118: }
119:
120: public Object clone() {
121: ChartRecord rec = new ChartRecord();
122:
123: rec.field_1_x = field_1_x;
124: rec.field_2_y = field_2_y;
125: rec.field_3_width = field_3_width;
126: rec.field_4_height = field_4_height;
127: return rec;
128: }
129:
130: /**
131: * Get the x field for the Chart record.
132: */
133: public int getX() {
134: return field_1_x;
135: }
136:
137: /**
138: * Set the x field for the Chart record.
139: */
140: public void setX(int field_1_x) {
141: this .field_1_x = field_1_x;
142: }
143:
144: /**
145: * Get the y field for the Chart record.
146: */
147: public int getY() {
148: return field_2_y;
149: }
150:
151: /**
152: * Set the y field for the Chart record.
153: */
154: public void setY(int field_2_y) {
155: this .field_2_y = field_2_y;
156: }
157:
158: /**
159: * Get the width field for the Chart record.
160: */
161: public int getWidth() {
162: return field_3_width;
163: }
164:
165: /**
166: * Set the width field for the Chart record.
167: */
168: public void setWidth(int field_3_width) {
169: this .field_3_width = field_3_width;
170: }
171:
172: /**
173: * Get the height field for the Chart record.
174: */
175: public int getHeight() {
176: return field_4_height;
177: }
178:
179: /**
180: * Set the height field for the Chart record.
181: */
182: public void setHeight(int field_4_height) {
183: this .field_4_height = field_4_height;
184: }
185:
186: } // END OF CLASS
|