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 bar record is used to define a bar 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 BarRecord extends Record {
030: public final static short sid = 0x1017;
031: private short field_1_barSpace;
032: private short field_2_categorySpace;
033: private short field_3_formatFlags;
034: private BitField horizontal = BitFieldFactory.getInstance(0x1);
035: private BitField stacked = BitFieldFactory.getInstance(0x2);
036: private BitField displayAsPercentage = BitFieldFactory
037: .getInstance(0x4);
038: private BitField shadow = BitFieldFactory.getInstance(0x8);
039:
040: public BarRecord() {
041:
042: }
043:
044: /**
045: * Constructs a Bar record and sets its fields appropriately.
046: *
047: * @param in the RecordInputstream to read the record from
048: */
049:
050: public BarRecord(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 Bar record");
063: }
064: }
065:
066: protected void fillFields(RecordInputStream in) {
067: field_1_barSpace = in.readShort();
068: field_2_categorySpace = in.readShort();
069: field_3_formatFlags = in.readShort();
070: }
071:
072: public String toString() {
073: StringBuffer buffer = new StringBuffer();
074:
075: buffer.append("[BAR]\n");
076: buffer.append(" .barSpace = ").append("0x")
077: .append(HexDump.toHex(getBarSpace())).append(" (")
078: .append(getBarSpace()).append(" )");
079: buffer.append(System.getProperty("line.separator"));
080: buffer.append(" .categorySpace = ").append("0x")
081: .append(HexDump.toHex(getCategorySpace())).append(" (")
082: .append(getCategorySpace()).append(" )");
083: buffer.append(System.getProperty("line.separator"));
084: buffer.append(" .formatFlags = ").append("0x")
085: .append(HexDump.toHex(getFormatFlags())).append(" (")
086: .append(getFormatFlags()).append(" )");
087: buffer.append(System.getProperty("line.separator"));
088: buffer.append(" .horizontal = ").append(
089: isHorizontal()).append('\n');
090: buffer.append(" .stacked = ").append(
091: isStacked()).append('\n');
092: buffer.append(" .displayAsPercentage = ").append(
093: isDisplayAsPercentage()).append('\n');
094: buffer.append(" .shadow = ").append(
095: isShadow()).append('\n');
096:
097: buffer.append("[/BAR]\n");
098: return buffer.toString();
099: }
100:
101: public int serialize(int offset, byte[] data) {
102: int pos = 0;
103:
104: LittleEndian.putShort(data, 0 + offset, sid);
105: LittleEndian.putShort(data, 2 + offset,
106: (short) (getRecordSize() - 4));
107:
108: LittleEndian.putShort(data, 4 + offset + pos, field_1_barSpace);
109: LittleEndian.putShort(data, 6 + offset + pos,
110: field_2_categorySpace);
111: LittleEndian.putShort(data, 8 + offset + pos,
112: field_3_formatFlags);
113:
114: return getRecordSize();
115: }
116:
117: /**
118: * Size of record (exluding 4 byte header)
119: */
120: public int getRecordSize() {
121: return 4 + 2 + 2 + 2;
122: }
123:
124: public short getSid() {
125: return sid;
126: }
127:
128: public Object clone() {
129: BarRecord rec = new BarRecord();
130:
131: rec.field_1_barSpace = field_1_barSpace;
132: rec.field_2_categorySpace = field_2_categorySpace;
133: rec.field_3_formatFlags = field_3_formatFlags;
134: return rec;
135: }
136:
137: /**
138: * Get the bar space field for the Bar record.
139: */
140: public short getBarSpace() {
141: return field_1_barSpace;
142: }
143:
144: /**
145: * Set the bar space field for the Bar record.
146: */
147: public void setBarSpace(short field_1_barSpace) {
148: this .field_1_barSpace = field_1_barSpace;
149: }
150:
151: /**
152: * Get the category space field for the Bar record.
153: */
154: public short getCategorySpace() {
155: return field_2_categorySpace;
156: }
157:
158: /**
159: * Set the category space field for the Bar record.
160: */
161: public void setCategorySpace(short field_2_categorySpace) {
162: this .field_2_categorySpace = field_2_categorySpace;
163: }
164:
165: /**
166: * Get the format flags field for the Bar record.
167: */
168: public short getFormatFlags() {
169: return field_3_formatFlags;
170: }
171:
172: /**
173: * Set the format flags field for the Bar record.
174: */
175: public void setFormatFlags(short field_3_formatFlags) {
176: this .field_3_formatFlags = field_3_formatFlags;
177: }
178:
179: /**
180: * Sets the horizontal field value.
181: * true to display horizontal bar charts, false for vertical
182: */
183: public void setHorizontal(boolean value) {
184: field_3_formatFlags = horizontal.setShortBoolean(
185: field_3_formatFlags, value);
186: }
187:
188: /**
189: * true to display horizontal bar charts, false for vertical
190: * @return the horizontal field value.
191: */
192: public boolean isHorizontal() {
193: return horizontal.isSet(field_3_formatFlags);
194: }
195:
196: /**
197: * Sets the stacked field value.
198: * stack displayed values
199: */
200: public void setStacked(boolean value) {
201: field_3_formatFlags = stacked.setShortBoolean(
202: field_3_formatFlags, value);
203: }
204:
205: /**
206: * stack displayed values
207: * @return the stacked field value.
208: */
209: public boolean isStacked() {
210: return stacked.isSet(field_3_formatFlags);
211: }
212:
213: /**
214: * Sets the display as percentage field value.
215: * display chart values as a percentage
216: */
217: public void setDisplayAsPercentage(boolean value) {
218: field_3_formatFlags = displayAsPercentage.setShortBoolean(
219: field_3_formatFlags, value);
220: }
221:
222: /**
223: * display chart values as a percentage
224: * @return the display as percentage field value.
225: */
226: public boolean isDisplayAsPercentage() {
227: return displayAsPercentage.isSet(field_3_formatFlags);
228: }
229:
230: /**
231: * Sets the shadow field value.
232: * display a shadow for the chart
233: */
234: public void setShadow(boolean value) {
235: field_3_formatFlags = shadow.setShortBoolean(
236: field_3_formatFlags, value);
237: }
238:
239: /**
240: * display a shadow for the chart
241: * @return the shadow field value.
242: */
243: public boolean isShadow() {
244: return shadow.isSet(field_3_formatFlags);
245: }
246:
247: } // END OF CLASS
|