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: * Defines a legend for 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 Andrew C. Oliver (acoliver at apache.org)
028: */
029: public class LegendRecord extends Record {
030: public final static short sid = 0x1015;
031: private int field_1_xAxisUpperLeft;
032: private int field_2_yAxisUpperLeft;
033: private int field_3_xSize;
034: private int field_4_ySize;
035: private byte field_5_type;
036: public final static byte TYPE_BOTTOM = 0;
037: public final static byte TYPE_CORNER = 1;
038: public final static byte TYPE_TOP = 2;
039: public final static byte TYPE_RIGHT = 3;
040: public final static byte TYPE_LEFT = 4;
041: public final static byte TYPE_UNDOCKED = 7;
042: private byte field_6_spacing;
043: public final static byte SPACING_CLOSE = 0;
044: public final static byte SPACING_MEDIUM = 1;
045: public final static byte SPACING_OPEN = 2;
046: private short field_7_options;
047: private BitField autoPosition = BitFieldFactory.getInstance(0x1);
048: private BitField autoSeries = BitFieldFactory.getInstance(0x2);
049: private BitField autoXPositioning = BitFieldFactory
050: .getInstance(0x4);
051: private BitField autoYPositioning = BitFieldFactory
052: .getInstance(0x8);
053: private BitField vertical = BitFieldFactory.getInstance(0x10);
054: private BitField dataTable = BitFieldFactory.getInstance(0x20);
055:
056: public LegendRecord() {
057:
058: }
059:
060: /**
061: * Constructs a Legend record and sets its fields appropriately.
062: *
063: * @param in the RecordInputstream to read the record from
064: */
065:
066: public LegendRecord(RecordInputStream in) {
067: super (in);
068:
069: }
070:
071: /**
072: * Checks the sid matches the expected side for this record
073: *
074: * @param id the expected sid.
075: */
076: protected void validateSid(short id) {
077: if (id != sid) {
078: throw new RecordFormatException("Not a Legend record");
079: }
080: }
081:
082: protected void fillFields(RecordInputStream in) {
083: field_1_xAxisUpperLeft = in.readInt();
084: field_2_yAxisUpperLeft = in.readInt();
085: field_3_xSize = in.readInt();
086: field_4_ySize = in.readInt();
087: field_5_type = in.readByte();
088: field_6_spacing = in.readByte();
089: field_7_options = in.readShort();
090: }
091:
092: public String toString() {
093: StringBuffer buffer = new StringBuffer();
094:
095: buffer.append("[LEGEND]\n");
096: buffer.append(" .xAxisUpperLeft = ").append("0x")
097: .append(HexDump.toHex(getXAxisUpperLeft()))
098: .append(" (").append(getXAxisUpperLeft()).append(" )");
099: buffer.append(System.getProperty("line.separator"));
100: buffer.append(" .yAxisUpperLeft = ").append("0x")
101: .append(HexDump.toHex(getYAxisUpperLeft()))
102: .append(" (").append(getYAxisUpperLeft()).append(" )");
103: buffer.append(System.getProperty("line.separator"));
104: buffer.append(" .xSize = ").append("0x")
105: .append(HexDump.toHex(getXSize())).append(" (").append(
106: getXSize()).append(" )");
107: buffer.append(System.getProperty("line.separator"));
108: buffer.append(" .ySize = ").append("0x")
109: .append(HexDump.toHex(getYSize())).append(" (").append(
110: getYSize()).append(" )");
111: buffer.append(System.getProperty("line.separator"));
112: buffer.append(" .type = ").append("0x")
113: .append(HexDump.toHex(getType())).append(" (").append(
114: getType()).append(" )");
115: buffer.append(System.getProperty("line.separator"));
116: buffer.append(" .spacing = ").append("0x")
117: .append(HexDump.toHex(getSpacing())).append(" (")
118: .append(getSpacing()).append(" )");
119: buffer.append(System.getProperty("line.separator"));
120: buffer.append(" .options = ").append("0x")
121: .append(HexDump.toHex(getOptions())).append(" (")
122: .append(getOptions()).append(" )");
123: buffer.append(System.getProperty("line.separator"));
124: buffer.append(" .autoPosition = ").append(
125: isAutoPosition()).append('\n');
126: buffer.append(" .autoSeries = ").append(
127: isAutoSeries()).append('\n');
128: buffer.append(" .autoXPositioning = ").append(
129: isAutoXPositioning()).append('\n');
130: buffer.append(" .autoYPositioning = ").append(
131: isAutoYPositioning()).append('\n');
132: buffer.append(" .vertical = ").append(
133: isVertical()).append('\n');
134: buffer.append(" .dataTable = ").append(
135: isDataTable()).append('\n');
136:
137: buffer.append("[/LEGEND]\n");
138: return buffer.toString();
139: }
140:
141: public int serialize(int offset, byte[] data) {
142: int pos = 0;
143:
144: LittleEndian.putShort(data, 0 + offset, sid);
145: LittleEndian.putShort(data, 2 + offset,
146: (short) (getRecordSize() - 4));
147:
148: LittleEndian.putInt(data, 4 + offset + pos,
149: field_1_xAxisUpperLeft);
150: LittleEndian.putInt(data, 8 + offset + pos,
151: field_2_yAxisUpperLeft);
152: LittleEndian.putInt(data, 12 + offset + pos, field_3_xSize);
153: LittleEndian.putInt(data, 16 + offset + pos, field_4_ySize);
154: data[20 + offset + pos] = field_5_type;
155: data[21 + offset + pos] = field_6_spacing;
156: LittleEndian.putShort(data, 22 + offset + pos, field_7_options);
157:
158: return getRecordSize();
159: }
160:
161: /**
162: * Size of record (exluding 4 byte header)
163: */
164: public int getRecordSize() {
165: return 4 + 4 + 4 + 4 + 4 + 1 + 1 + 2;
166: }
167:
168: public short getSid() {
169: return sid;
170: }
171:
172: public Object clone() {
173: LegendRecord rec = new LegendRecord();
174:
175: rec.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
176: rec.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
177: rec.field_3_xSize = field_3_xSize;
178: rec.field_4_ySize = field_4_ySize;
179: rec.field_5_type = field_5_type;
180: rec.field_6_spacing = field_6_spacing;
181: rec.field_7_options = field_7_options;
182: return rec;
183: }
184:
185: /**
186: * Get the x axis upper left field for the Legend record.
187: */
188: public int getXAxisUpperLeft() {
189: return field_1_xAxisUpperLeft;
190: }
191:
192: /**
193: * Set the x axis upper left field for the Legend record.
194: */
195: public void setXAxisUpperLeft(int field_1_xAxisUpperLeft) {
196: this .field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
197: }
198:
199: /**
200: * Get the y axis upper left field for the Legend record.
201: */
202: public int getYAxisUpperLeft() {
203: return field_2_yAxisUpperLeft;
204: }
205:
206: /**
207: * Set the y axis upper left field for the Legend record.
208: */
209: public void setYAxisUpperLeft(int field_2_yAxisUpperLeft) {
210: this .field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
211: }
212:
213: /**
214: * Get the x size field for the Legend record.
215: */
216: public int getXSize() {
217: return field_3_xSize;
218: }
219:
220: /**
221: * Set the x size field for the Legend record.
222: */
223: public void setXSize(int field_3_xSize) {
224: this .field_3_xSize = field_3_xSize;
225: }
226:
227: /**
228: * Get the y size field for the Legend record.
229: */
230: public int getYSize() {
231: return field_4_ySize;
232: }
233:
234: /**
235: * Set the y size field for the Legend record.
236: */
237: public void setYSize(int field_4_ySize) {
238: this .field_4_ySize = field_4_ySize;
239: }
240:
241: /**
242: * Get the type field for the Legend record.
243: *
244: * @return One of
245: * TYPE_BOTTOM
246: * TYPE_CORNER
247: * TYPE_TOP
248: * TYPE_RIGHT
249: * TYPE_LEFT
250: * TYPE_UNDOCKED
251: */
252: public byte getType() {
253: return field_5_type;
254: }
255:
256: /**
257: * Set the type field for the Legend record.
258: *
259: * @param field_5_type
260: * One of
261: * TYPE_BOTTOM
262: * TYPE_CORNER
263: * TYPE_TOP
264: * TYPE_RIGHT
265: * TYPE_LEFT
266: * TYPE_UNDOCKED
267: */
268: public void setType(byte field_5_type) {
269: this .field_5_type = field_5_type;
270: }
271:
272: /**
273: * Get the spacing field for the Legend record.
274: *
275: * @return One of
276: * SPACING_CLOSE
277: * SPACING_MEDIUM
278: * SPACING_OPEN
279: */
280: public byte getSpacing() {
281: return field_6_spacing;
282: }
283:
284: /**
285: * Set the spacing field for the Legend record.
286: *
287: * @param field_6_spacing
288: * One of
289: * SPACING_CLOSE
290: * SPACING_MEDIUM
291: * SPACING_OPEN
292: */
293: public void setSpacing(byte field_6_spacing) {
294: this .field_6_spacing = field_6_spacing;
295: }
296:
297: /**
298: * Get the options field for the Legend record.
299: */
300: public short getOptions() {
301: return field_7_options;
302: }
303:
304: /**
305: * Set the options field for the Legend record.
306: */
307: public void setOptions(short field_7_options) {
308: this .field_7_options = field_7_options;
309: }
310:
311: /**
312: * Sets the auto position field value.
313: * automatic positioning (1=docked)
314: */
315: public void setAutoPosition(boolean value) {
316: field_7_options = autoPosition.setShortBoolean(field_7_options,
317: value);
318: }
319:
320: /**
321: * automatic positioning (1=docked)
322: * @return the auto position field value.
323: */
324: public boolean isAutoPosition() {
325: return autoPosition.isSet(field_7_options);
326: }
327:
328: /**
329: * Sets the auto series field value.
330: * excel 5 only (true)
331: */
332: public void setAutoSeries(boolean value) {
333: field_7_options = autoSeries.setShortBoolean(field_7_options,
334: value);
335: }
336:
337: /**
338: * excel 5 only (true)
339: * @return the auto series field value.
340: */
341: public boolean isAutoSeries() {
342: return autoSeries.isSet(field_7_options);
343: }
344:
345: /**
346: * Sets the auto x positioning field value.
347: * position of legend on the x axis is automatic
348: */
349: public void setAutoXPositioning(boolean value) {
350: field_7_options = autoXPositioning.setShortBoolean(
351: field_7_options, value);
352: }
353:
354: /**
355: * position of legend on the x axis is automatic
356: * @return the auto x positioning field value.
357: */
358: public boolean isAutoXPositioning() {
359: return autoXPositioning.isSet(field_7_options);
360: }
361:
362: /**
363: * Sets the auto y positioning field value.
364: * position of legend on the y axis is automatic
365: */
366: public void setAutoYPositioning(boolean value) {
367: field_7_options = autoYPositioning.setShortBoolean(
368: field_7_options, value);
369: }
370:
371: /**
372: * position of legend on the y axis is automatic
373: * @return the auto y positioning field value.
374: */
375: public boolean isAutoYPositioning() {
376: return autoYPositioning.isSet(field_7_options);
377: }
378:
379: /**
380: * Sets the vertical field value.
381: * vertical or horizontal legend (1 or 0 respectively). Always 0 if not automatic.
382: */
383: public void setVertical(boolean value) {
384: field_7_options = vertical.setShortBoolean(field_7_options,
385: value);
386: }
387:
388: /**
389: * vertical or horizontal legend (1 or 0 respectively). Always 0 if not automatic.
390: * @return the vertical field value.
391: */
392: public boolean isVertical() {
393: return vertical.isSet(field_7_options);
394: }
395:
396: /**
397: * Sets the data table field value.
398: * 1 if chart contains data table
399: */
400: public void setDataTable(boolean value) {
401: field_7_options = dataTable.setShortBoolean(field_7_options,
402: value);
403: }
404:
405: /**
406: * 1 if chart contains data table
407: * @return the data table field value.
408: */
409: public boolean isDataTable() {
410: return dataTable.isSet(field_7_options);
411: }
412:
413: } // END OF CLASS
|