KickJava   Java API By Example, From Geeks To Geeks.

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


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 chart record is used to define the location and size of a 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 ChartRecord
34     extends Record
35 {
36     public final static short sid = 0x1002;
37     private int field_1_x;
38     private int field_2_y;
39     private int field_3_width;
40     private int field_4_height;
41
42
43     public ChartRecord()
44     {
45
46     }
47
48     /**
49      * Constructs a Chart record and sets its fields appropriately.
50      *
51      * @param id id must be 0x1002 or an exception
52      * will be throw upon validation
53      * @param size size the size of the data area of the record
54      * @param data data of the record (should not contain sid/len)
55      */

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

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

84     protected void validateSid(short id)
85     {
86         if (id != sid)
87         {
88             throw new RecordFormatException("Not a Chart record");
89         }
90     }
91
92     protected void fillFields(byte [] data, short size, int offset)
93     {
94
95         int pos = 0;
96         field_1_x = LittleEndian.getInt(data, pos + 0x0 + offset);
97         field_2_y = LittleEndian.getInt(data, pos + 0x4 + offset);
98         field_3_width = LittleEndian.getInt(data, pos + 0x8 + offset);
99         field_4_height = LittleEndian.getInt(data, pos + 0xc + offset);
100
101     }
102
103     public String JavaDoc toString()
104     {
105         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
106
107         buffer.append("[CHART]\n");
108         buffer.append(" .x = ")
109             .append("0x").append(HexDump.toHex( getX ()))
110             .append(" (").append( getX() ).append(" )");
111         buffer.append(System.getProperty("line.separator"));
112         buffer.append(" .y = ")
113             .append("0x").append(HexDump.toHex( getY ()))
114             .append(" (").append( getY() ).append(" )");
115         buffer.append(System.getProperty("line.separator"));
116         buffer.append(" .width = ")
117             .append("0x").append(HexDump.toHex( getWidth ()))
118             .append(" (").append( getWidth() ).append(" )");
119         buffer.append(System.getProperty("line.separator"));
120         buffer.append(" .height = ")
121             .append("0x").append(HexDump.toHex( getHeight ()))
122             .append(" (").append( getHeight() ).append(" )");
123         buffer.append(System.getProperty("line.separator"));
124
125         buffer.append("[/CHART]\n");
126         return buffer.toString();
127     }
128
129     public int serialize(int offset, byte[] data)
130     {
131         int pos = 0;
132
133         LittleEndian.putShort(data, 0 + offset, sid);
134         LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
135
136         LittleEndian.putInt(data, 4 + offset + pos, field_1_x);
137         LittleEndian.putInt(data, 8 + offset + pos, field_2_y);
138         LittleEndian.putInt(data, 12 + offset + pos, field_3_width);
139         LittleEndian.putInt(data, 16 + offset + pos, field_4_height);
140
141         return getRecordSize();
142     }
143
144     /**
145      * Size of record (exluding 4 byte header)
146      */

147     public int getRecordSize()
148     {
149         return 4 + 4 + 4 + 4 + 4;
150     }
151
152     public short getSid()
153     {
154         return this.sid;
155     }
156
157     public Object JavaDoc clone() {
158         ChartRecord rec = new ChartRecord();
159     
160         rec.field_1_x = field_1_x;
161         rec.field_2_y = field_2_y;
162         rec.field_3_width = field_3_width;
163         rec.field_4_height = field_4_height;
164         return rec;
165     }
166
167
168
169
170     /**
171      * Get the x field for the Chart record.
172      */

173     public int getX()
174     {
175         return field_1_x;
176     }
177
178     /**
179      * Set the x field for the Chart record.
180      */

181     public void setX(int field_1_x)
182     {
183         this.field_1_x = field_1_x;
184     }
185
186     /**
187      * Get the y field for the Chart record.
188      */

189     public int getY()
190     {
191         return field_2_y;
192     }
193
194     /**
195      * Set the y field for the Chart record.
196      */

197     public void setY(int field_2_y)
198     {
199         this.field_2_y = field_2_y;
200     }
201
202     /**
203      * Get the width field for the Chart record.
204      */

205     public int getWidth()
206     {
207         return field_3_width;
208     }
209
210     /**
211      * Set the width field for the Chart record.
212      */

213     public void setWidth(int field_3_width)
214     {
215         this.field_3_width = field_3_width;
216     }
217
218     /**
219      * Get the height field for the Chart record.
220      */

221     public int getHeight()
222     {
223         return field_4_height;
224     }
225
226     /**
227      * Set the height field for the Chart record.
228      */

229     public void setHeight(int field_4_height)
230     {
231         this.field_4_height = field_4_height;
232     }
233
234
235 } // END OF CLASS
236

237
238
239
240
Popular Tags