KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22 import org.apache.poi.util.BitField;
23
24 /**
25  * Class ChartFormatRecord
26  *
27  *
28  * @author Glen Stampoultzis (glens at apache.org)
29  * @version %I%, %G%
30  */

31
32 public class ChartFormatRecord
33     extends Record
34 {
35     public static final short sid = 0x1014;
36
37     // ignored?
38
private int field1_x_position; // lower left
39
private int field2_y_position; // lower left
40
private int field3_width;
41     private int field4_height;
42     private short field5_grbit;
43     private BitField varyDisplayPattern = new BitField(0x01);
44
45     public ChartFormatRecord()
46     {
47     }
48
49     /**
50      * Constructs a ChartFormatRecord record and sets its fields appropriately.
51      *
52      * @param id id must equal the sid or an exception will be throw upon validation
53      * @param 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 ChartFormatRecord(short id, short size, byte [] data)
58     {
59         super(id, size, data);
60     }
61
62     /**
63      * Constructs a ChartFormatRecord record and sets its fields appropriately.
64      *
65      * @param id id must equal the sid or an exception will be throw upon validation
66      * @param size the size of the data area of the record
67      * @param data data of the record (should not contain sid/len)
68      * @param offset of the record's data
69      */

70
71     public ChartFormatRecord(short id, short size, byte [] data, int offset)
72     {
73         super(id, size, data, offset);
74     }
75
76     protected void validateSid(short id)
77     {
78         if (id != sid)
79         {
80             throw new RecordFormatException("NOT A CHARTFORMAT RECORD");
81         }
82     }
83
84     protected void fillFields(byte [] data, short size, int offset)
85     {
86         field1_x_position = LittleEndian.getInt(data, 0 + offset);
87         field2_y_position = LittleEndian.getInt(data, 4 + offset);
88         field3_width = LittleEndian.getInt(data, 8 + offset);
89         field4_height = LittleEndian.getInt(data, 12 + offset);
90         field5_grbit = LittleEndian.getShort(data, 16 + offset);
91     }
92
93     public String JavaDoc toString()
94     {
95         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
96
97         buffer.append("[CHARTFORMAT]\n");
98         buffer.append(" .xPosition = ").append(getXPosition())
99             .append("\n");
100         buffer.append(" .yPosition = ").append(getYPosition())
101             .append("\n");
102         buffer.append(" .width = ").append(getWidth())
103             .append("\n");
104         buffer.append(" .height = ").append(getHeight())
105             .append("\n");
106         buffer.append(" .grBit = ")
107             .append(Integer.toHexString(field5_grbit)).append("\n");
108         buffer.append("[/CHARTFORMAT]\n");
109         return buffer.toString();
110     }
111
112     public int serialize(int offset, byte [] data)
113     {
114         LittleEndian.putShort(data, 0 + offset, sid);
115         LittleEndian.putShort(data, 2 + offset,
116                               (( short ) 22)); // 22 byte length
117
LittleEndian.putInt(data, 4 + offset, getXPosition());
118         LittleEndian.putInt(data, 8 + offset, getYPosition());
119         LittleEndian.putInt(data, 12 + offset, getWidth());
120         LittleEndian.putInt(data, 16 + offset, getHeight());
121         LittleEndian.putShort(data, 20 + offset, field5_grbit);
122         return getRecordSize();
123     }
124
125     public int getRecordSize()
126     {
127         return 22;
128     }
129
130     public short getSid()
131     {
132         return this.sid;
133     }
134
135     public int getXPosition()
136     {
137         return field1_x_position;
138     }
139
140     public void setXPosition(int xPosition)
141     {
142         this.field1_x_position = xPosition;
143     }
144
145     public int getYPosition()
146     {
147         return field2_y_position;
148     }
149
150     public void setYPosition(int yPosition)
151     {
152         this.field2_y_position = yPosition;
153     }
154
155     public int getWidth()
156     {
157         return field3_width;
158     }
159
160     public void setWidth(int width)
161     {
162         this.field3_width = width;
163     }
164
165     public int getHeight()
166     {
167         return field4_height;
168     }
169
170     public void setHeight(int height)
171     {
172         this.field4_height = height;
173     }
174
175     public boolean getVaryDisplayPattern()
176     {
177         return varyDisplayPattern.isSet(field5_grbit);
178     }
179
180     public void setVaryDisplayPattern(boolean value)
181     {
182         field5_grbit = varyDisplayPattern.setShortBoolean(field5_grbit,
183                 value);
184     }
185 }
186
Popular Tags