You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WSBoolRecord.java 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.record;
  16. import org.apache.poi.util.BitField;
  17. import org.apache.poi.util.BitFieldFactory;
  18. import org.apache.poi.util.LittleEndianOutput;
  19. /**
  20. * Title: WSBOOL (0x0081) (called SHEETPR in OOO doc)<p/>
  21. * Description: stores workbook settings (aka its a big "everything we didn't
  22. * put somewhere else")<P>
  23. * REFERENCE: PG 425 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  24. * @author Andrew C. Oliver (acoliver at apache dot org)
  25. * @author Glen Stampoultzis (gstamp@iprimus.com.au)
  26. * @author Jason Height (jheight at chariot dot net dot au)
  27. */
  28. public final class WSBoolRecord extends StandardRecord {
  29. public final static short sid = 0x0081;
  30. private byte field_1_wsbool; // crappy names are because this is really one big short field (2byte)
  31. private byte field_2_wsbool; // but the docs inconsistently use it as 2 separate bytes
  32. // I decided to be consistent in this way.
  33. private static final BitField autobreaks = BitFieldFactory.getInstance(0x01); // are automatic page breaks visible
  34. // bits 1 to 3 unused
  35. private static final BitField dialog = BitFieldFactory.getInstance(0x10); // is sheet dialog sheet
  36. private static final BitField applystyles = BitFieldFactory.getInstance(0x20); // whether to apply automatic styles to outlines
  37. private static final BitField rowsumsbelow = BitFieldFactory.getInstance(0x40); // whether summary rows will appear below detail in outlines
  38. private static final BitField rowsumsright = BitFieldFactory.getInstance(0x80); // whether summary rows will appear right of the detail in outlines
  39. private static final BitField fittopage = BitFieldFactory.getInstance(0x01); // whether to fit stuff to the page
  40. // bit 2 reserved
  41. private static final BitField displayguts = BitFieldFactory.getInstance(0x06); // whether to display outline symbols (in the gutters)
  42. // bits 4-5 reserved
  43. private static final BitField alternateexpression = BitFieldFactory.getInstance(0x40); // whether to use alternate expression eval
  44. private static final BitField alternateformula = BitFieldFactory.getInstance(0x80); // whether to use alternate formula entry
  45. public WSBoolRecord()
  46. {
  47. }
  48. public WSBoolRecord(RecordInputStream in)
  49. {
  50. byte data[] = in.readRemainder();
  51. field_1_wsbool =
  52. data[ 1 ]; // backwards because theoretically this is one short field
  53. field_2_wsbool =
  54. data[ 0 ]; // but it was easier to implement it this way to avoid confusion
  55. } // because the dev kit shows the masks for it as 2 byte fields
  56. // why? Why ask why? But don't drink bud dry as its a really
  57. // crappy beer, try the czech "Budvar" beer (which is the real
  58. // budweiser though its ironically good...its sold in the USs
  59. // as czechvar --- odd that they had the name first but can't
  60. // use it)...
  61. /**
  62. * set first byte (see bit setters)
  63. */
  64. public void setWSBool1(byte bool1)
  65. {
  66. field_1_wsbool = bool1;
  67. }
  68. // bool1 bitfields
  69. /**
  70. * show automatic page breaks or not
  71. * @param ab whether to show auto page breaks
  72. */
  73. public void setAutobreaks(boolean ab)
  74. {
  75. field_1_wsbool = autobreaks.setByteBoolean(field_1_wsbool, ab);
  76. }
  77. /**
  78. * set whether sheet is a dialog sheet or not
  79. * @param isDialog or not
  80. */
  81. public void setDialog(boolean isDialog)
  82. {
  83. field_1_wsbool = dialog.setByteBoolean(field_1_wsbool, isDialog);
  84. }
  85. /**
  86. * set if row summaries appear below detail in the outline
  87. * @param below or not
  88. */
  89. public void setRowSumsBelow(boolean below)
  90. {
  91. field_1_wsbool = rowsumsbelow.setByteBoolean(field_1_wsbool, below);
  92. }
  93. /**
  94. * set if col summaries appear right of the detail in the outline
  95. * @param right or not
  96. */
  97. public void setRowSumsRight(boolean right)
  98. {
  99. field_1_wsbool = rowsumsright.setByteBoolean(field_1_wsbool, right);
  100. }
  101. // end bitfields
  102. /**
  103. * set the second byte (see bit setters)
  104. */
  105. public void setWSBool2(byte bool2)
  106. {
  107. field_2_wsbool = bool2;
  108. }
  109. // bool2 bitfields
  110. /**
  111. * fit to page option is on
  112. * @param fit2page fit or not
  113. */
  114. public void setFitToPage(boolean fit2page)
  115. {
  116. field_2_wsbool = fittopage.setByteBoolean(field_2_wsbool, fit2page);
  117. }
  118. /**
  119. * set whether to display the guts or not
  120. *
  121. * @param guts or no guts (or glory)
  122. */
  123. public void setDisplayGuts(boolean guts)
  124. {
  125. field_2_wsbool = displayguts.setByteBoolean(field_2_wsbool, guts);
  126. }
  127. /**
  128. * whether alternate expression evaluation is on
  129. * @param altexp alternative expression evaluation or not
  130. */
  131. public void setAlternateExpression(boolean altexp)
  132. {
  133. field_2_wsbool = alternateexpression.setByteBoolean(field_2_wsbool,
  134. altexp);
  135. }
  136. /**
  137. * whether alternative formula entry is on
  138. * @param formula alternative formulas or not
  139. */
  140. public void setAlternateFormula(boolean formula)
  141. {
  142. field_2_wsbool = alternateformula.setByteBoolean(field_2_wsbool,
  143. formula);
  144. }
  145. // end bitfields
  146. /**
  147. * get first byte (see bit getters)
  148. */
  149. public byte getWSBool1()
  150. {
  151. return field_1_wsbool;
  152. }
  153. // bool1 bitfields
  154. /**
  155. * show automatic page breaks or not
  156. * @return whether to show auto page breaks
  157. */
  158. public boolean getAutobreaks()
  159. {
  160. return autobreaks.isSet(field_1_wsbool);
  161. }
  162. /**
  163. * get whether sheet is a dialog sheet or not
  164. * @return isDialog or not
  165. */
  166. public boolean getDialog()
  167. {
  168. return dialog.isSet(field_1_wsbool);
  169. }
  170. /**
  171. * get if row summaries appear below detail in the outline
  172. * @return below or not
  173. */
  174. public boolean getRowSumsBelow()
  175. {
  176. return rowsumsbelow.isSet(field_1_wsbool);
  177. }
  178. /**
  179. * get if col summaries appear right of the detail in the outline
  180. * @return right or not
  181. */
  182. public boolean getRowSumsRight()
  183. {
  184. return rowsumsright.isSet(field_1_wsbool);
  185. }
  186. // end bitfields
  187. /**
  188. * get the second byte (see bit getters)
  189. */
  190. public byte getWSBool2()
  191. {
  192. return field_2_wsbool;
  193. }
  194. // bool2 bitfields
  195. /**
  196. * fit to page option is on
  197. * @return fit or not
  198. */
  199. public boolean getFitToPage()
  200. {
  201. return fittopage.isSet(field_2_wsbool);
  202. }
  203. /**
  204. * get whether to display the guts or not
  205. *
  206. * @return guts or no guts (or glory)
  207. */
  208. public boolean getDisplayGuts()
  209. {
  210. return displayguts.isSet(field_2_wsbool);
  211. }
  212. /**
  213. * whether alternate expression evaluation is on
  214. * @return alternative expression evaluation or not
  215. */
  216. public boolean getAlternateExpression()
  217. {
  218. return alternateexpression.isSet(field_2_wsbool);
  219. }
  220. /**
  221. * whether alternative formula entry is on
  222. * @return alternative formulas or not
  223. */
  224. public boolean getAlternateFormula()
  225. {
  226. return alternateformula.isSet(field_2_wsbool);
  227. }
  228. // end bitfields
  229. public String toString()
  230. {
  231. StringBuffer buffer = new StringBuffer();
  232. buffer.append("[WSBOOL]\n");
  233. buffer.append(" .wsbool1 = ")
  234. .append(Integer.toHexString(getWSBool1())).append("\n");
  235. buffer.append(" .autobreaks = ").append(getAutobreaks())
  236. .append("\n");
  237. buffer.append(" .dialog = ").append(getDialog())
  238. .append("\n");
  239. buffer.append(" .rowsumsbelw= ").append(getRowSumsBelow())
  240. .append("\n");
  241. buffer.append(" .rowsumsrigt= ").append(getRowSumsRight())
  242. .append("\n");
  243. buffer.append(" .wsbool2 = ")
  244. .append(Integer.toHexString(getWSBool2())).append("\n");
  245. buffer.append(" .fittopage = ").append(getFitToPage())
  246. .append("\n");
  247. buffer.append(" .displayguts= ").append(getDisplayGuts())
  248. .append("\n");
  249. buffer.append(" .alternateex= ")
  250. .append(getAlternateExpression()).append("\n");
  251. buffer.append(" .alternatefo= ").append(getAlternateFormula())
  252. .append("\n");
  253. buffer.append("[/WSBOOL]\n");
  254. return buffer.toString();
  255. }
  256. public void serialize(LittleEndianOutput out) {
  257. out.writeByte(getWSBool2());
  258. out.writeByte(getWSBool1());
  259. }
  260. protected int getDataSize() {
  261. return 2;
  262. }
  263. public short getSid()
  264. {
  265. return sid;
  266. }
  267. public Object clone() {
  268. WSBoolRecord rec = new WSBoolRecord();
  269. rec.field_1_wsbool = field_1_wsbool;
  270. rec.field_2_wsbool = field_2_wsbool;
  271. return rec;
  272. }
  273. }