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.

WindowTwoRecord.java 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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: Window Two Record<P>
  21. * Description: sheet window settings<P>
  22. * REFERENCE: PG 422 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  23. * @author Andrew C. Oliver (acoliver at apache dot org)
  24. * @author Jason Height (jheight at chariot dot net dot au)
  25. * @version 2.0-pre
  26. */
  27. public final class WindowTwoRecord extends StandardRecord {
  28. public final static short sid = 0x023E;
  29. // bitfields
  30. private static final BitField displayFormulas = BitFieldFactory.getInstance(0x01);
  31. private static final BitField displayGridlines = BitFieldFactory.getInstance(0x02);
  32. private static final BitField displayRowColHeadings = BitFieldFactory.getInstance(0x04);
  33. private static final BitField freezePanes = BitFieldFactory.getInstance(0x08);
  34. private static final BitField displayZeros = BitFieldFactory.getInstance(0x10);
  35. /** if false use color in field 4 if true use default foreground for headers */
  36. private static final BitField defaultHeader = BitFieldFactory.getInstance(0x20);
  37. private static final BitField arabic = BitFieldFactory.getInstance(0x040);
  38. private static final BitField displayGuts = BitFieldFactory.getInstance(0x080);
  39. private static final BitField freezePanesNoSplit = BitFieldFactory.getInstance(0x100);
  40. private static final BitField selected = BitFieldFactory.getInstance(0x200);
  41. private static final BitField active = BitFieldFactory.getInstance(0x400);
  42. private static final BitField savedInPageBreakPreview = BitFieldFactory.getInstance(0x800);
  43. // 4-7 reserved
  44. // end bitfields
  45. private short field_1_options;
  46. private short field_2_top_row;
  47. private short field_3_left_col;
  48. private int field_4_header_color;
  49. private short field_5_page_break_zoom;
  50. private short field_6_normal_zoom;
  51. private int field_7_reserved;
  52. public WindowTwoRecord()
  53. {
  54. }
  55. public WindowTwoRecord(RecordInputStream in)
  56. {
  57. int size = in.remaining();
  58. field_1_options = in.readShort();
  59. field_2_top_row = in.readShort();
  60. field_3_left_col = in.readShort();
  61. field_4_header_color = in.readInt();
  62. if (size > 10)
  63. {
  64. field_5_page_break_zoom = in.readShort();
  65. field_6_normal_zoom = in.readShort();
  66. }
  67. if (size > 14)
  68. { // there is a special case of this record that has only 14 bytes...undocumented!
  69. field_7_reserved = in.readInt();
  70. }
  71. }
  72. /**
  73. * set the options bitmask or just use the bit setters.
  74. * @param options
  75. */
  76. public void setOptions(short options)
  77. {
  78. field_1_options = options;
  79. }
  80. // option bitfields
  81. /**
  82. * set whether the window should display formulas
  83. * @param formulas or not
  84. */
  85. public void setDisplayFormulas(boolean formulas)
  86. {
  87. field_1_options = displayFormulas.setShortBoolean(field_1_options, formulas);
  88. }
  89. /**
  90. * set whether the window should display gridlines
  91. * @param gridlines or not
  92. */
  93. public void setDisplayGridlines(boolean gridlines)
  94. {
  95. field_1_options = displayGridlines.setShortBoolean(field_1_options, gridlines);
  96. }
  97. /**
  98. * set whether the window should display row and column headings
  99. * @param headings or not
  100. */
  101. public void setDisplayRowColHeadings(boolean headings)
  102. {
  103. field_1_options = displayRowColHeadings.setShortBoolean(field_1_options, headings);
  104. }
  105. /**
  106. * set whether the window should freeze panes
  107. * @param freezepanes freeze panes or not
  108. */
  109. public void setFreezePanes(boolean freezepanes)
  110. {
  111. field_1_options = freezePanes.setShortBoolean(field_1_options, freezepanes);
  112. }
  113. /**
  114. * set whether the window should display zero values
  115. * @param zeros or not
  116. */
  117. public void setDisplayZeros(boolean zeros)
  118. {
  119. field_1_options = displayZeros.setShortBoolean(field_1_options, zeros);
  120. }
  121. /**
  122. * set whether the window should display a default header
  123. * @param header or not
  124. */
  125. public void setDefaultHeader(boolean header)
  126. {
  127. field_1_options = defaultHeader.setShortBoolean(field_1_options, header);
  128. }
  129. /**
  130. * is this arabic?
  131. * @param isarabic arabic or not
  132. */
  133. public void setArabic(boolean isarabic)
  134. {
  135. field_1_options = arabic.setShortBoolean(field_1_options, isarabic);
  136. }
  137. /**
  138. * set whether the outline symbols are displaed
  139. * @param guts symbols or not
  140. */
  141. public void setDisplayGuts(boolean guts)
  142. {
  143. field_1_options = displayGuts.setShortBoolean(field_1_options, guts);
  144. }
  145. /**
  146. * freeze unsplit panes or not
  147. * @param freeze or not
  148. */
  149. public void setFreezePanesNoSplit(boolean freeze)
  150. {
  151. field_1_options = freezePanesNoSplit.setShortBoolean(field_1_options, freeze);
  152. }
  153. /**
  154. * sheet tab is selected
  155. * @param sel selected or not
  156. */
  157. public void setSelected(boolean sel)
  158. {
  159. field_1_options = selected.setShortBoolean(field_1_options, sel);
  160. }
  161. /**
  162. * is the sheet currently displayed in the window
  163. * @param p displayed or not
  164. */
  165. public void setActive(boolean p) {
  166. field_1_options = active.setShortBoolean(field_1_options, p);
  167. }
  168. /**
  169. * deprecated May 2008
  170. * @deprecated use setActive()
  171. */
  172. public void setPaged(boolean p) {
  173. setActive(p);
  174. }
  175. /**
  176. * was the sheet saved in page break view
  177. * @param p pagebreaksaved or not
  178. */
  179. public void setSavedInPageBreakPreview(boolean p)
  180. {
  181. field_1_options = savedInPageBreakPreview.setShortBoolean(field_1_options, p);
  182. }
  183. // end of bitfields.
  184. /**
  185. * set the top row visible in the window
  186. * @param topRow top row visible
  187. */
  188. public void setTopRow(short topRow)
  189. {
  190. field_2_top_row = topRow;
  191. }
  192. /**
  193. * set the leftmost column displayed in the window
  194. * @param leftCol leftmost column
  195. */
  196. public void setLeftCol(short leftCol)
  197. {
  198. field_3_left_col = leftCol;
  199. }
  200. /**
  201. * set the palette index for the header color
  202. * @param color
  203. */
  204. public void setHeaderColor(int color)
  205. {
  206. field_4_header_color = color;
  207. }
  208. /**
  209. * zoom magification in page break view
  210. * @param zoom
  211. */
  212. public void setPageBreakZoom(short zoom)
  213. {
  214. field_5_page_break_zoom = zoom;
  215. }
  216. /**
  217. * set the zoom magnification in normal view
  218. * @param zoom
  219. */
  220. public void setNormalZoom(short zoom)
  221. {
  222. field_6_normal_zoom = zoom;
  223. }
  224. /**
  225. * set the reserved (don't do this) value
  226. */
  227. public void setReserved(int reserved)
  228. {
  229. field_7_reserved = reserved;
  230. }
  231. /**
  232. * get the options bitmask or just use the bit setters.
  233. * @return options
  234. */
  235. public short getOptions()
  236. {
  237. return field_1_options;
  238. }
  239. // option bitfields
  240. /**
  241. * get whether the window should display formulas
  242. * @return formulas or not
  243. */
  244. public boolean getDisplayFormulas()
  245. {
  246. return displayFormulas.isSet(field_1_options);
  247. }
  248. /**
  249. * get whether the window should display gridlines
  250. * @return gridlines or not
  251. */
  252. public boolean getDisplayGridlines()
  253. {
  254. return displayGridlines.isSet(field_1_options);
  255. }
  256. /**
  257. * get whether the window should display row and column headings
  258. * @return headings or not
  259. */
  260. public boolean getDisplayRowColHeadings()
  261. {
  262. return displayRowColHeadings.isSet(field_1_options);
  263. }
  264. /**
  265. * get whether the window should freeze panes
  266. * @return freeze panes or not
  267. */
  268. public boolean getFreezePanes()
  269. {
  270. return freezePanes.isSet(field_1_options);
  271. }
  272. /**
  273. * get whether the window should display zero values
  274. * @return zeros or not
  275. */
  276. public boolean getDisplayZeros()
  277. {
  278. return displayZeros.isSet(field_1_options);
  279. }
  280. /**
  281. * get whether the window should display a default header
  282. * @return header or not
  283. */
  284. public boolean getDefaultHeader()
  285. {
  286. return defaultHeader.isSet(field_1_options);
  287. }
  288. /**
  289. * is this arabic?
  290. * @return arabic or not
  291. */
  292. public boolean getArabic()
  293. {
  294. return arabic.isSet(field_1_options);
  295. }
  296. /**
  297. * get whether the outline symbols are displaed
  298. * @return symbols or not
  299. */
  300. public boolean getDisplayGuts()
  301. {
  302. return displayGuts.isSet(field_1_options);
  303. }
  304. /**
  305. * freeze unsplit panes or not
  306. * @return freeze or not
  307. */
  308. public boolean getFreezePanesNoSplit()
  309. {
  310. return freezePanesNoSplit.isSet(field_1_options);
  311. }
  312. /**
  313. * sheet tab is selected
  314. * @return selected or not
  315. */
  316. public boolean getSelected()
  317. {
  318. return selected.isSet(field_1_options);
  319. }
  320. /**
  321. * is the sheet currently displayed in the window
  322. * @return displayed or not
  323. */
  324. public boolean isActive() {
  325. return active.isSet(field_1_options);
  326. }
  327. /**
  328. * deprecated May 2008
  329. * @deprecated use isActive()
  330. */
  331. public boolean getPaged() {
  332. return isActive();
  333. }
  334. /**
  335. * was the sheet saved in page break view
  336. * @return pagebreaksaved or not
  337. */
  338. public boolean getSavedInPageBreakPreview()
  339. {
  340. return savedInPageBreakPreview.isSet(field_1_options);
  341. }
  342. // end of bitfields.
  343. /**
  344. * get the top row visible in the window
  345. * @return toprow
  346. */
  347. public short getTopRow()
  348. {
  349. return field_2_top_row;
  350. }
  351. /**
  352. * get the leftmost column displayed in the window
  353. * @return leftmost
  354. */
  355. public short getLeftCol()
  356. {
  357. return field_3_left_col;
  358. }
  359. /**
  360. * get the palette index for the header color
  361. * @return color
  362. */
  363. public int getHeaderColor()
  364. {
  365. return field_4_header_color;
  366. }
  367. /**
  368. * zoom magification in page break view
  369. * @return zoom
  370. */
  371. public short getPageBreakZoom()
  372. {
  373. return field_5_page_break_zoom;
  374. }
  375. /**
  376. * get the zoom magnification in normal view
  377. * @return zoom
  378. */
  379. public short getNormalZoom()
  380. {
  381. return field_6_normal_zoom;
  382. }
  383. /**
  384. * get the reserved bits - why would you do this?
  385. * @return reserved stuff -probably garbage
  386. */
  387. public int getReserved()
  388. {
  389. return field_7_reserved;
  390. }
  391. public String toString()
  392. {
  393. StringBuffer buffer = new StringBuffer();
  394. buffer.append("[WINDOW2]\n");
  395. buffer.append(" .options = ")
  396. .append(Integer.toHexString(getOptions())).append("\n");
  397. buffer.append(" .dispformulas= ").append(getDisplayFormulas())
  398. .append("\n");
  399. buffer.append(" .dispgridlins= ").append(getDisplayGridlines())
  400. .append("\n");
  401. buffer.append(" .disprcheadin= ")
  402. .append(getDisplayRowColHeadings()).append("\n");
  403. buffer.append(" .freezepanes = ").append(getFreezePanes())
  404. .append("\n");
  405. buffer.append(" .displayzeros= ").append(getDisplayZeros())
  406. .append("\n");
  407. buffer.append(" .defaultheadr= ").append(getDefaultHeader())
  408. .append("\n");
  409. buffer.append(" .arabic = ").append(getArabic())
  410. .append("\n");
  411. buffer.append(" .displayguts = ").append(getDisplayGuts())
  412. .append("\n");
  413. buffer.append(" .frzpnsnosplt= ")
  414. .append(getFreezePanesNoSplit()).append("\n");
  415. buffer.append(" .selected = ").append(getSelected())
  416. .append("\n");
  417. buffer.append(" .active = ").append(isActive())
  418. .append("\n");
  419. buffer.append(" .svdinpgbrkpv= ")
  420. .append(getSavedInPageBreakPreview()).append("\n");
  421. buffer.append(" .toprow = ")
  422. .append(Integer.toHexString(getTopRow())).append("\n");
  423. buffer.append(" .leftcol = ")
  424. .append(Integer.toHexString(getLeftCol())).append("\n");
  425. buffer.append(" .headercolor = ")
  426. .append(Integer.toHexString(getHeaderColor())).append("\n");
  427. buffer.append(" .pagebreakzoom = ")
  428. .append(Integer.toHexString(getPageBreakZoom())).append("\n");
  429. buffer.append(" .normalzoom = ")
  430. .append(Integer.toHexString(getNormalZoom())).append("\n");
  431. buffer.append(" .reserved = ")
  432. .append(Integer.toHexString(getReserved())).append("\n");
  433. buffer.append("[/WINDOW2]\n");
  434. return buffer.toString();
  435. }
  436. public void serialize(LittleEndianOutput out) {
  437. out.writeShort(getOptions());
  438. out.writeShort(getTopRow());
  439. out.writeShort(getLeftCol());
  440. out.writeInt(getHeaderColor());
  441. out.writeShort(getPageBreakZoom());
  442. out.writeShort(getNormalZoom());
  443. out.writeInt(getReserved());
  444. }
  445. protected int getDataSize() {
  446. return 18;
  447. }
  448. public short getSid()
  449. {
  450. return sid;
  451. }
  452. public Object clone() {
  453. WindowTwoRecord rec = new WindowTwoRecord();
  454. rec.field_1_options = field_1_options;
  455. rec.field_2_top_row = field_2_top_row;
  456. rec.field_3_left_col = field_3_left_col;
  457. rec.field_4_header_color = field_4_header_color;
  458. rec.field_5_page_break_zoom = field_5_page_break_zoom;
  459. rec.field_6_normal_zoom = field_6_normal_zoom;
  460. rec.field_7_reserved = field_7_reserved;
  461. return rec;
  462. }
  463. }