KickJava   Java API By Example, From Geeks To Geeks.

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


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.BitField;
22 import org.apache.poi.util.LittleEndian;
23
24 /**
25  * Title: WSBool Record.<p>
26  * Description: stores workbook settings (aka its a big "everything we didn't
27  * put somewhere else")<P>
28  * REFERENCE: PG 425 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
29  * @author Andrew C. Oliver (acoliver at apache dot org)
30  * @author Glen Stampoultzis (gstamp@iprimus.com.au)
31  * @author Jason Height (jheight at chariot dot net dot au)
32  * @version 2.0-pre
33  */

34
35 public class WSBoolRecord
36     extends Record
37 {
38     public final static short sid = 0x81;
39     private byte field_1_wsbool; // crappy names are because this is really one big short field (2byte)
40
private byte field_2_wsbool; // but the docs inconsistantly use it as 2 seperate bytes
41

42     // I decided to be consistant in this way.
43
static final private BitField autobreaks =
44         new BitField(0x01); // are automatic page breaks visible
45

46     // bits 1 to 3 unused
47
static final private BitField dialog =
48         new BitField(0x10); // is sheet dialog sheet
49
static final private BitField applystyles =
50         new BitField(0x20); // whether to apply automatic styles to outlines
51
static final private BitField rowsumsbelow = new BitField(
52         0x40); // whether summary rows will appear below detail in outlines
53
static final private BitField rowsumsright = new BitField(
54         0x80); // whether summary rows will appear right of the detail in outlines
55
static final private BitField fittopage =
56         new BitField(0x01); // whether to fit stuff to the page
57

58     // bit 2 reserved
59
static final private BitField displayguts = new BitField(
60         0x06); // whether to display outline symbols (in the gutters)
61

62     // bits 4-5 reserved
63
static final private BitField alternateexpression = // whether to use alternate expression eval
64
new BitField(0x40);
65     static final private BitField alternateformula = // whether to use alternate formula entry
66
new BitField(0x80);
67
68     public WSBoolRecord()
69     {
70     }
71
72     /**
73      * Constructs a WSBool record and sets its fields appropriately.
74      *
75      * @param id id must be 0x81 or an exception will be throw upon validation
76      * @param size the size of the data area of the record
77      * @param data data of the record (should not contain sid/len)
78      */

79
80     public WSBoolRecord(short id, short size, byte [] data)
81     {
82         super(id, size, data);
83     }
84
85     /**
86      * Constructs a WSBool record and sets its fields appropriately.
87      *
88      * @param id id must be 0x81 or an exception will be throw upon validation
89      * @param size the size of the data area of the record
90      * @param data data of the record (should not contain sid/len)
91      */

92
93     public WSBoolRecord(short id, short size, byte [] data, int offset)
94     {
95         super(id, size, data, offset);
96     }
97
98     protected void validateSid(short id)
99     {
100         if (id != sid)
101         {
102             throw new RecordFormatException("NOT A WSBoolRECORD");
103         }
104     }
105
106     protected void fillFields(byte [] data, short size, int offset)
107     {
108         field_1_wsbool =
109             data[ 1 + offset ]; // backwards because theoretically this is one short field
110
field_2_wsbool =
111             data[ 0 + offset ]; // but it was easier to implement it this way to avoid confusion
112
} // because the dev kit shows the masks for it as 2 byte fields
113

114     // why? Why ask why? But don't drink bud dry as its a really
115
// crappy beer, try the czech "Budvar" beer (which is the real
116
// budweiser though its ironically good...its sold in the USs
117
// as czechvar --- odd that they had the name first but can't
118
// use it)...
119

120     /**
121      * set first byte (see bit setters)
122      */

123
124     public void setWSBool1(byte bool1)
125     {
126         field_1_wsbool = bool1;
127     }
128
129     // bool1 bitfields
130

131     /**
132      * show automatic page breaks or not
133      * @param ab whether to show auto page breaks
134      */

135
136     public void setAutobreaks(boolean ab)
137     {
138         field_1_wsbool = autobreaks.setByteBoolean(field_1_wsbool, ab);
139     }
140
141     /**
142      * set whether sheet is a dialog sheet or not
143      * @param isDialog or not
144      */

145
146     public void setDialog(boolean isDialog)
147     {
148         field_1_wsbool = dialog.setByteBoolean(field_1_wsbool, isDialog);
149     }
150
151     /**
152      * set if row summaries appear below detail in the outline
153      * @param below or not
154      */

155
156     public void setRowSumsBelow(boolean below)
157     {
158         field_1_wsbool = rowsumsbelow.setByteBoolean(field_1_wsbool, below);
159     }
160
161     /**
162      * set if col summaries appear right of the detail in the outline
163      * @param right or not
164      */

165
166     public void setRowSumsRight(boolean right)
167     {
168         field_1_wsbool = rowsumsright.setByteBoolean(field_1_wsbool, right);
169     }
170
171     // end bitfields
172

173     /**
174      * set the second byte (see bit setters)
175      */

176
177     public void setWSBool2(byte bool2)
178     {
179         field_2_wsbool = field_2_wsbool = bool2;
180     }
181
182     // bool2 bitfields
183

184     /**
185      * fit to page option is on
186      * @param fit2page fit or not
187      */

188
189     public void setFitToPage(boolean fit2page)
190     {
191         field_2_wsbool = fittopage.setByteBoolean(field_2_wsbool, fit2page);
192     }
193
194     /**
195      * set whether to display the guts or not
196      *
197      * @param guts or no guts (or glory)
198      */

199
200     public void setDisplayGuts(boolean guts)
201     {
202         field_2_wsbool = displayguts.setByteBoolean(field_2_wsbool, guts);
203     }
204
205     /**
206      * whether alternate expression evaluation is on
207      * @param altexp alternative expression evaluation or not
208      */

209
210     public void setAlternateExpression(boolean altexp)
211     {
212         field_2_wsbool = alternateexpression.setByteBoolean(field_2_wsbool,
213                 altexp);
214     }
215
216     /**
217      * whether alternative formula entry is on
218      * @param formula alternative formulas or not
219      */

220
221     public void setAlternateFormula(boolean formula)
222     {
223         field_2_wsbool = alternateformula.setByteBoolean(field_2_wsbool,
224                 formula);
225     }
226
227     // end bitfields
228

229     /**
230      * get first byte (see bit getters)
231      */

232
233     public byte getWSBool1()
234     {
235         return field_1_wsbool;
236     }
237
238     // bool1 bitfields
239

240     /**
241      * show automatic page breaks or not
242      * @return whether to show auto page breaks
243      */

244
245     public boolean getAutobreaks()
246     {
247         return autobreaks.isSet(field_1_wsbool);
248     }
249
250     /**
251      * get whether sheet is a dialog sheet or not
252      * @return isDialog or not
253      */

254
255     public boolean getDialog()
256     {
257         return dialog.isSet(field_1_wsbool);
258     }
259
260     /**
261      * get if row summaries appear below detail in the outline
262      * @return below or not
263      */

264
265     public boolean getRowSumsBelow()
266     {
267         return rowsumsbelow.isSet(field_1_wsbool);
268     }
269
270     /**
271      * get if col summaries appear right of the detail in the outline
272      * @return right or not
273      */

274
275     public boolean getRowSumsRight()
276     {
277         return rowsumsright.isSet(field_1_wsbool);
278     }
279
280     // end bitfields
281

282     /**
283      * get the second byte (see bit getters)
284      */

285
286     public byte getWSBool2()
287     {
288         return field_2_wsbool;
289     }
290
291     // bool2 bitfields
292

293     /**
294      * fit to page option is on
295      * @return fit or not
296      */

297
298     public boolean getFitToPage()
299     {
300         return fittopage.isSet(field_2_wsbool);
301     }
302
303     /**
304      * get whether to display the guts or not
305      *
306      * @return guts or no guts (or glory)
307      */

308
309     public boolean getDisplayGuts()
310     {
311         return displayguts.isSet(field_2_wsbool);
312     }
313
314     /**
315      * whether alternate expression evaluation is on
316      * @return alternative expression evaluation or not
317      */

318
319     public boolean getAlternateExpression()
320     {
321         return alternateexpression.isSet(field_2_wsbool);
322     }
323
324     /**
325      * whether alternative formula entry is on
326      * @return alternative formulas or not
327      */

328
329     public boolean getAlternateFormula()
330     {
331         return alternateformula.isSet(field_2_wsbool);
332     }
333
334     // end bitfields
335
public String JavaDoc toString()
336     {
337         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
338
339         buffer.append("[WSBOOL]\n");
340         buffer.append(" .wsbool1 = ")
341             .append(Integer.toHexString(getWSBool1())).append("\n");
342         buffer.append(" .autobreaks = ").append(getAutobreaks())
343             .append("\n");
344         buffer.append(" .dialog = ").append(getDialog())
345             .append("\n");
346         buffer.append(" .rowsumsbelw= ").append(getRowSumsBelow())
347             .append("\n");
348         buffer.append(" .rowsumsrigt= ").append(getRowSumsRight())
349             .append("\n");
350         buffer.append(" .wsbool2 = ")
351             .append(Integer.toHexString(getWSBool2())).append("\n");
352         buffer.append(" .fittopage = ").append(getFitToPage())
353             .append("\n");
354         buffer.append(" .displayguts= ").append(getDisplayGuts())
355             .append("\n");
356         buffer.append(" .alternateex= ")
357             .append(getAlternateExpression()).append("\n");
358         buffer.append(" .alternatefo= ").append(getAlternateFormula())
359             .append("\n");
360         buffer.append("[/WSBOOL]\n");
361         return buffer.toString();
362     }
363
364     public int serialize(int offset, byte [] data)
365     {
366         LittleEndian.putShort(data, 0 + offset, sid);
367         LittleEndian.putShort(data, 2 + offset, ( short ) 0x2);
368         data[ 5 + offset ] = getWSBool1();
369         data[ 4 + offset ] = getWSBool2();
370         return getRecordSize();
371     }
372
373     public int getRecordSize()
374     {
375         return 6;
376     }
377
378     public short getSid()
379     {
380         return this.sid;
381     }
382
383     public Object JavaDoc clone() {
384       WSBoolRecord rec = new WSBoolRecord();
385       rec.field_1_wsbool = field_1_wsbool;
386       rec.field_2_wsbool = field_2_wsbool;
387       return rec;
388     }
389 }
390
Popular Tags