KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > BarRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19
20 package org.apache.poi.hssf.record;
21
22
23
24 import org.apache.poi.util.*;
25
26 /**
27  * The bar record is used to define a bar chart.
28  * NOTE: This source is automatically generated please do not modify this file. Either subclass or
29  * remove the record in src/records/definitions.
30
31  * @author Glen Stampoultzis (glens at apache.org)
32  */

33 public class BarRecord
34     extends Record
35 {
36     public final static short sid = 0x1017;
37     private short field_1_barSpace;
38     private short field_2_categorySpace;
39     private short field_3_formatFlags;
40     private BitField horizontal = new BitField(0x1);
41     private BitField stacked = new BitField(0x2);
42     private BitField displayAsPercentage = new BitField(0x4);
43     private BitField shadow = new BitField(0x8);
44
45
46     public BarRecord()
47     {
48
49     }
50
51     /**
52      * Constructs a Bar record and sets its fields appropriately.
53      *
54      * @param id id must be 0x1017 or an exception
55      * will be throw upon validation
56      * @param size size the size of the data area of the record
57      * @param data data of the record (should not contain sid/len)
58      */

59
60     public BarRecord(short id, short size, byte [] data)
61     {
62         super(id, size, data);
63     
64     }
65
66     /**
67      * Constructs a Bar record and sets its fields appropriately.
68      *
69      * @param id id must be 0x1017 or an exception
70      * will be throw upon validation
71      * @param size size the size of the data area of the record
72      * @param data data of the record (should not contain sid/len)
73      * @param offset of the record's data
74      */

75
76     public BarRecord(short id, short size, byte [] data, int offset)
77     {
78         super(id, size, data, offset);
79     
80     }
81
82     /**
83      * Checks the sid matches the expected side for this record
84      *
85      * @param id the expected sid.
86      */

87     protected void validateSid(short id)
88     {
89         if (id != sid)
90         {
91             throw new RecordFormatException("Not a Bar record");
92         }
93     }
94
95     protected void fillFields(byte [] data, short size, int offset)
96     {
97
98         int pos = 0;
99         field_1_barSpace = LittleEndian.getShort(data, pos + 0x0 + offset);
100         field_2_categorySpace = LittleEndian.getShort(data, pos + 0x2 + offset);
101         field_3_formatFlags = LittleEndian.getShort(data, pos + 0x4 + offset);
102
103     }
104
105     public String JavaDoc toString()
106     {
107         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
108
109         buffer.append("[BAR]\n");
110         buffer.append(" .barSpace = ")
111             .append("0x").append(HexDump.toHex( getBarSpace ()))
112             .append(" (").append( getBarSpace() ).append(" )");
113         buffer.append(System.getProperty("line.separator"));
114         buffer.append(" .categorySpace = ")
115             .append("0x").append(HexDump.toHex( getCategorySpace ()))
116             .append(" (").append( getCategorySpace() ).append(" )");
117         buffer.append(System.getProperty("line.separator"));
118         buffer.append(" .formatFlags = ")
119             .append("0x").append(HexDump.toHex( getFormatFlags ()))
120             .append(" (").append( getFormatFlags() ).append(" )");
121         buffer.append(System.getProperty("line.separator"));
122         buffer.append(" .horizontal = ").append(isHorizontal()).append('\n');
123         buffer.append(" .stacked = ").append(isStacked()).append('\n');
124         buffer.append(" .displayAsPercentage = ").append(isDisplayAsPercentage()).append('\n');
125         buffer.append(" .shadow = ").append(isShadow()).append('\n');
126
127         buffer.append("[/BAR]\n");
128         return buffer.toString();
129     }
130
131     public int serialize(int offset, byte[] data)
132     {
133         int pos = 0;
134
135         LittleEndian.putShort(data, 0 + offset, sid);
136         LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
137
138         LittleEndian.putShort(data, 4 + offset + pos, field_1_barSpace);
139         LittleEndian.putShort(data, 6 + offset + pos, field_2_categorySpace);
140         LittleEndian.putShort(data, 8 + offset + pos, field_3_formatFlags);
141
142         return getRecordSize();
143     }
144
145     /**
146      * Size of record (exluding 4 byte header)
147      */

148     public int getRecordSize()
149     {
150         return 4 + 2 + 2 + 2;
151     }
152
153     public short getSid()
154     {
155         return this.sid;
156     }
157
158     public Object JavaDoc clone() {
159         BarRecord rec = new BarRecord();
160     
161         rec.field_1_barSpace = field_1_barSpace;
162         rec.field_2_categorySpace = field_2_categorySpace;
163         rec.field_3_formatFlags = field_3_formatFlags;
164         return rec;
165     }
166
167
168
169
170     /**
171      * Get the bar space field for the Bar record.
172      */

173     public short getBarSpace()
174     {
175         return field_1_barSpace;
176     }
177
178     /**
179      * Set the bar space field for the Bar record.
180      */

181     public void setBarSpace(short field_1_barSpace)
182     {
183         this.field_1_barSpace = field_1_barSpace;
184     }
185
186     /**
187      * Get the category space field for the Bar record.
188      */

189     public short getCategorySpace()
190     {
191         return field_2_categorySpace;
192     }
193
194     /**
195      * Set the category space field for the Bar record.
196      */

197     public void setCategorySpace(short field_2_categorySpace)
198     {
199         this.field_2_categorySpace = field_2_categorySpace;
200     }
201
202     /**
203      * Get the format flags field for the Bar record.
204      */

205     public short getFormatFlags()
206     {
207         return field_3_formatFlags;
208     }
209
210     /**
211      * Set the format flags field for the Bar record.
212      */

213     public void setFormatFlags(short field_3_formatFlags)
214     {
215         this.field_3_formatFlags = field_3_formatFlags;
216     }
217
218     /**
219      * Sets the horizontal field value.
220      * true to display horizontal bar charts, false for vertical
221      */

222     public void setHorizontal(boolean value)
223     {
224         field_3_formatFlags = horizontal.setShortBoolean(field_3_formatFlags, value);
225     }
226
227     /**
228      * true to display horizontal bar charts, false for vertical
229      * @return the horizontal field value.
230      */

231     public boolean isHorizontal()
232     {
233         return horizontal.isSet(field_3_formatFlags);
234     }
235
236     /**
237      * Sets the stacked field value.
238      * stack displayed values
239      */

240     public void setStacked(boolean value)
241     {
242         field_3_formatFlags = stacked.setShortBoolean(field_3_formatFlags, value);
243     }
244
245     /**
246      * stack displayed values
247      * @return the stacked field value.
248      */

249     public boolean isStacked()
250     {
251         return stacked.isSet(field_3_formatFlags);
252     }
253
254     /**
255      * Sets the display as percentage field value.
256      * display chart values as a percentage
257      */

258     public void setDisplayAsPercentage(boolean value)
259     {
260         field_3_formatFlags = displayAsPercentage.setShortBoolean(field_3_formatFlags, value);
261     }
262
263     /**
264      * display chart values as a percentage
265      * @return the display as percentage field value.
266      */

267     public boolean isDisplayAsPercentage()
268     {
269         return displayAsPercentage.isSet(field_3_formatFlags);
270     }
271
272     /**
273      * Sets the shadow field value.
274      * display a shadow for the chart
275      */

276     public void setShadow(boolean value)
277     {
278         field_3_formatFlags = shadow.setShortBoolean(field_3_formatFlags, value);
279     }
280
281     /**
282      * display a shadow for the chart
283      * @return the shadow field value.
284      */

285     public boolean isShadow()
286     {
287         return shadow.isSet(field_3_formatFlags);
288     }
289
290
291 } // END OF CLASS
292

293
294
295
296
Popular Tags