2 /* ====================================================================
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================== */
20 package org
.apache
.poi
.hssf
.record
;
22 import org
.apache
.poi
.util
.BitField
;
23 import org
.apache
.poi
.util
.BitFieldFactory
;
24 import org
.apache
.poi
.util
.LittleEndian
;
27 * Title: WSBool Record.<p>
28 * Description: stores workbook settings (aka its a big "everything we didn't
29 * put somewhere else")<P>
30 * REFERENCE: PG 425 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
31 * @author Andrew C. Oliver (acoliver at apache dot org)
32 * @author Glen Stampoultzis (gstamp@iprimus.com.au)
33 * @author Jason Height (jheight at chariot dot net dot au)
37 public class WSBoolRecord
40 public final static short sid
= 0x81;
41 private byte field_1_wsbool
; // crappy names are because this is really one big short field (2byte)
42 private byte field_2_wsbool
; // but the docs inconsistantly use it as 2 seperate bytes
44 // I decided to be consistant in this way.
45 static final private BitField autobreaks
=
46 BitFieldFactory
.getInstance(0x01); // are automatic page breaks visible
49 static final private BitField dialog
=
50 BitFieldFactory
.getInstance(0x10); // is sheet dialog sheet
51 static final private BitField applystyles
=
52 BitFieldFactory
.getInstance(0x20); // whether to apply automatic styles to outlines
53 static final private BitField rowsumsbelow
= BitFieldFactory
.getInstance(
54 0x40); // whether summary rows will appear below detail in outlines
55 static final private BitField rowsumsright
= BitFieldFactory
.getInstance(
56 0x80); // whether summary rows will appear right of the detail in outlines
57 static final private BitField fittopage
=
58 BitFieldFactory
.getInstance(0x01); // whether to fit stuff to the page
61 static final private BitField displayguts
= BitFieldFactory
.getInstance(
62 0x06); // whether to display outline symbols (in the gutters)
65 static final private BitField alternateexpression
= // whether to use alternate expression eval
66 BitFieldFactory
.getInstance(0x40);
67 static final private BitField alternateformula
= // whether to use alternate formula entry
68 BitFieldFactory
.getInstance(0x80);
75 * Constructs a WSBool record and sets its fields appropriately.
76 * @param in the RecordInputstream to read the record from
79 public WSBoolRecord(RecordInputStream in
)
84 protected void validateSid(short id
)
88 throw new RecordFormatException("NOT A WSBoolRECORD");
92 protected void fillFields(RecordInputStream in
)
94 byte data
[] = in
.readRemainder();
96 data
[ 1 ]; // backwards because theoretically this is one short field
98 data
[ 0 ]; // but it was easier to implement it this way to avoid confusion
99 } // because the dev kit shows the masks for it as 2 byte fields
101 // why? Why ask why? But don't drink bud dry as its a really
102 // crappy beer, try the czech "Budvar" beer (which is the real
103 // budweiser though its ironically good...its sold in the USs
104 // as czechvar --- odd that they had the name first but can't
108 * set first byte (see bit setters)
111 public void setWSBool1(byte bool1
)
113 field_1_wsbool
= bool1
;
119 * show automatic page breaks or not
120 * @param ab whether to show auto page breaks
123 public void setAutobreaks(boolean ab
)
125 field_1_wsbool
= autobreaks
.setByteBoolean(field_1_wsbool
, ab
);
129 * set whether sheet is a dialog sheet or not
130 * @param isDialog or not
133 public void setDialog(boolean isDialog
)
135 field_1_wsbool
= dialog
.setByteBoolean(field_1_wsbool
, isDialog
);
139 * set if row summaries appear below detail in the outline
140 * @param below or not
143 public void setRowSumsBelow(boolean below
)
145 field_1_wsbool
= rowsumsbelow
.setByteBoolean(field_1_wsbool
, below
);
149 * set if col summaries appear right of the detail in the outline
150 * @param right or not
153 public void setRowSumsRight(boolean right
)
155 field_1_wsbool
= rowsumsright
.setByteBoolean(field_1_wsbool
, right
);
161 * set the second byte (see bit setters)
164 public void setWSBool2(byte bool2
)
166 field_2_wsbool
= bool2
;
172 * fit to page option is on
173 * @param fit2page fit or not
176 public void setFitToPage(boolean fit2page
)
178 field_2_wsbool
= fittopage
.setByteBoolean(field_2_wsbool
, fit2page
);
182 * set whether to display the guts or not
184 * @param guts or no guts (or glory)
187 public void setDisplayGuts(boolean guts
)
189 field_2_wsbool
= displayguts
.setByteBoolean(field_2_wsbool
, guts
);
193 * whether alternate expression evaluation is on
194 * @param altexp alternative expression evaluation or not
197 public void setAlternateExpression(boolean altexp
)
199 field_2_wsbool
= alternateexpression
.setByteBoolean(field_2_wsbool
,
204 * whether alternative formula entry is on
205 * @param formula alternative formulas or not
208 public void setAlternateFormula(boolean formula
)
210 field_2_wsbool
= alternateformula
.setByteBoolean(field_2_wsbool
,
217 * get first byte (see bit getters)
220 public byte getWSBool1()
222 return field_1_wsbool
;
228 * show automatic page breaks or not
229 * @return whether to show auto page breaks
232 public boolean getAutobreaks()
234 return autobreaks
.isSet(field_1_wsbool
);
238 * get whether sheet is a dialog sheet or not
239 * @return isDialog or not
242 public boolean getDialog()
244 return dialog
.isSet(field_1_wsbool
);
248 * get if row summaries appear below detail in the outline
249 * @return below or not
252 public boolean getRowSumsBelow()
254 return rowsumsbelow
.isSet(field_1_wsbool
);
258 * get if col summaries appear right of the detail in the outline
259 * @return right or not
262 public boolean getRowSumsRight()
264 return rowsumsright
.isSet(field_1_wsbool
);
270 * get the second byte (see bit getters)
273 public byte getWSBool2()
275 return field_2_wsbool
;
281 * fit to page option is on
285 public boolean getFitToPage()
287 return fittopage
.isSet(field_2_wsbool
);
291 * get whether to display the guts or not
293 * @return guts or no guts (or glory)
296 public boolean getDisplayGuts()
298 return displayguts
.isSet(field_2_wsbool
);
302 * whether alternate expression evaluation is on
303 * @return alternative expression evaluation or not
306 public boolean getAlternateExpression()
308 return alternateexpression
.isSet(field_2_wsbool
);
312 * whether alternative formula entry is on
313 * @return alternative formulas or not
316 public boolean getAlternateFormula()
318 return alternateformula
.isSet(field_2_wsbool
);
322 public String
toString()
324 StringBuffer buffer
= new StringBuffer();
326 buffer
.append("[WSBOOL]\n");
327 buffer
.append(" .wsbool1 = ")
328 .append(Integer
.toHexString(getWSBool1())).append("\n");
329 buffer
.append(" .autobreaks = ").append(getAutobreaks())
331 buffer
.append(" .dialog = ").append(getDialog())
333 buffer
.append(" .rowsumsbelw= ").append(getRowSumsBelow())
335 buffer
.append(" .rowsumsrigt= ").append(getRowSumsRight())
337 buffer
.append(" .wsbool2 = ")
338 .append(Integer
.toHexString(getWSBool2())).append("\n");
339 buffer
.append(" .fittopage = ").append(getFitToPage())
341 buffer
.append(" .displayguts= ").append(getDisplayGuts())
343 buffer
.append(" .alternateex= ")
344 .append(getAlternateExpression()).append("\n");
345 buffer
.append(" .alternatefo= ").append(getAlternateFormula())
347 buffer
.append("[/WSBOOL]\n");
348 return buffer
.toString();
351 public int serialize(int offset
, byte [] data
)
353 LittleEndian
.putShort(data
, 0 + offset
, sid
);
354 LittleEndian
.putShort(data
, 2 + offset
, ( short ) 0x2);
355 data
[ 5 + offset
] = getWSBool1();
356 data
[ 4 + offset
] = getWSBool2();
357 return getRecordSize();
360 public int getRecordSize()
365 public short getSid()
370 public Object
clone() {
371 WSBoolRecord rec
= new WSBoolRecord();
372 rec
.field_1_wsbool
= field_1_wsbool
;
373 rec
.field_2_wsbool
= field_2_wsbool
;