KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 /**
24  * Title: Gridset Record.<P>
25  * Description: flag denoting whether the user specified that gridlines are used when
26  * printing.<P>
27  * REFERENCE: PG 320 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
28  *
29  * @author Andrew C. Oliver (acoliver at apache dot org)
30  * @author Glen Stampoultzis (glens at apache.org)
31  * @author Jason Height (jheight at chariot dot net dot au)
32  *
33  * @version 2.0-pre
34  */

35
36 public class GridsetRecord
37     extends Record
38 {
39     public final static short sid = 0x82;
40     public short field_1_gridset_flag;
41
42     public GridsetRecord()
43     {
44     }
45
46     /**
47      * Constructs a GridSet record and sets its fields appropriately.
48      *
49      * @param id id must be 0x82 or an exception will be throw upon validation
50      * @param size the size of the data area of the record
51      * @param data data of the record (should not contain sid/len)
52      */

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

67
68     public GridsetRecord(short id, short size, byte [] data, int offset)
69     {
70         super(id, size, data, offset);
71     }
72
73     protected void validateSid(short id)
74     {
75         if (id != sid)
76         {
77             throw new RecordFormatException("NOT A Gridset RECORD");
78         }
79     }
80
81     protected void fillFields(byte [] data, short size, int offset)
82     {
83         field_1_gridset_flag = LittleEndian.getShort(data, 0 + offset);
84     }
85
86     /**
87      * set whether gridlines are visible when printing
88      *
89      * @param gridset - <b>true</b> if no gridlines are print, <b>false</b> if gridlines are not print.
90      */

91
92     public void setGridset(boolean gridset)
93     {
94         if (gridset == true)
95         {
96             field_1_gridset_flag = 1;
97         }
98         else
99         {
100             field_1_gridset_flag = 0;
101         }
102     }
103
104     /**
105      * get whether the gridlines are shown during printing.
106      *
107      * @return gridset - true if gridlines are NOT printed, false if they are.
108      */

109
110     public boolean getGridset()
111     {
112         return (field_1_gridset_flag == 1);
113     }
114
115     public String JavaDoc toString()
116     {
117         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
118
119         buffer.append("[GRIDSET]\n");
120         buffer.append(" .gridset = ").append(getGridset())
121             .append("\n");
122         buffer.append("[/GRIDSET]\n");
123         return buffer.toString();
124     }
125
126     public int serialize(int offset, byte [] data)
127     {
128         LittleEndian.putShort(data, 0 + offset, sid);
129         LittleEndian.putShort(data, 2 + offset, ( short ) 0x2);
130         LittleEndian.putShort(data, 4 + offset, field_1_gridset_flag);
131         return getRecordSize();
132     }
133
134     public int getRecordSize()
135     {
136         return 6;
137     }
138
139     public short getSid()
140     {
141         return this.sid;
142     }
143
144     public Object JavaDoc clone() {
145       GridsetRecord rec = new GridsetRecord();
146       rec.field_1_gridset_flag = field_1_gridset_flag;
147       return rec;
148     }
149 }
150
Popular Tags