PageRenderTime 145ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/WindowTwoRecord.java

http://github.com/openmicroscopy/bioformats
Java | 600 lines | 290 code | 100 blank | 210 comment | 4 complexity | 2f0b316a26e7d5bbbbe5284b2b9eb7ec MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.record;
  38. import loci.poi.util.BitField;
  39. import loci.poi.util.BitFieldFactory;
  40. import loci.poi.util.LittleEndian;
  41. /**
  42. * Title: Window Two Record<P>
  43. * Description: sheet window settings<P>
  44. * REFERENCE: PG 422 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  45. * @author Andrew C. Oliver (acoliver at apache dot org)
  46. * @author Jason Height (jheight at chariot dot net dot au)
  47. * @version 2.0-pre
  48. */
  49. public class WindowTwoRecord
  50. extends Record
  51. {
  52. public final static short sid = 0x23e;
  53. private short field_1_options;
  54. // bitfields
  55. private BitField displayFormulas = BitFieldFactory.getInstance(0x01);
  56. private BitField displayGridlines = BitFieldFactory.getInstance(0x02);
  57. private BitField displayRowColHeadings = BitFieldFactory.getInstance(0x04);
  58. private BitField freezePanes = BitFieldFactory.getInstance(0x08);
  59. private BitField displayZeros = BitFieldFactory.getInstance(0x10);
  60. private BitField defaultHeader =
  61. BitFieldFactory.getInstance(0x20); // if false use color in field 4
  62. // if true use default foreground
  63. // for headers
  64. private BitField arabic =
  65. BitFieldFactory.getInstance(0x40); // for our desert dwelling friends
  66. private BitField displayGuts = BitFieldFactory.getInstance(0x80);
  67. private BitField freezePanesNoSplit = BitFieldFactory.getInstance(0x100);
  68. private BitField selected = BitFieldFactory.getInstance(0x200);
  69. private BitField paged = BitFieldFactory.getInstance(0x400);
  70. private BitField savedInPageBreakPreview = BitFieldFactory.getInstance(0x800);
  71. // 4-7 reserved
  72. // end bitfields
  73. private short field_2_top_row;
  74. private short field_3_left_col;
  75. private int field_4_header_color;
  76. private short field_5_page_break_zoom;
  77. private short field_6_normal_zoom;
  78. private int field_7_reserved;
  79. public WindowTwoRecord()
  80. {
  81. }
  82. /**
  83. * Constructs a WindowTwo record and sets its fields appropriately.
  84. * @param in the RecordInputstream to read the record from
  85. */
  86. public WindowTwoRecord(RecordInputStream in)
  87. {
  88. super(in);
  89. }
  90. protected void validateSid(short id)
  91. {
  92. if (id != sid)
  93. {
  94. throw new RecordFormatException("NOT A valid WindowTwo RECORD");
  95. }
  96. }
  97. protected void fillFields(RecordInputStream in)
  98. {
  99. int size = in.remaining();
  100. field_1_options = in.readShort();
  101. field_2_top_row = in.readShort();
  102. field_3_left_col = in.readShort();
  103. field_4_header_color = in.readInt();
  104. if (size > 10)
  105. {
  106. field_5_page_break_zoom = in.readShort();
  107. field_6_normal_zoom = in.readShort();
  108. }
  109. if (size > 14)
  110. { // there is a special case of this record that has only 14 bytes...undocumented!
  111. field_7_reserved = in.readInt();
  112. }
  113. }
  114. /**
  115. * set the options bitmask or just use the bit setters.
  116. * @param options
  117. */
  118. public void setOptions(short options)
  119. {
  120. field_1_options = options;
  121. }
  122. // option bitfields
  123. /**
  124. * set whether the window should display formulas
  125. * @param formulas or not
  126. */
  127. public void setDisplayFormulas(boolean formulas)
  128. {
  129. field_1_options = displayFormulas.setShortBoolean(field_1_options, formulas);
  130. }
  131. /**
  132. * set whether the window should display gridlines
  133. * @param gridlines or not
  134. */
  135. public void setDisplayGridlines(boolean gridlines)
  136. {
  137. field_1_options = displayGridlines.setShortBoolean(field_1_options, gridlines);
  138. }
  139. /**
  140. * set whether the window should display row and column headings
  141. * @param headings or not
  142. */
  143. public void setDisplayRowColHeadings(boolean headings)
  144. {
  145. field_1_options = displayRowColHeadings.setShortBoolean(field_1_options, headings);
  146. }
  147. /**
  148. * set whether the window should freeze panes
  149. * @param freezepanes freeze panes or not
  150. */
  151. public void setFreezePanes(boolean freezepanes)
  152. {
  153. field_1_options = freezePanes.setShortBoolean(field_1_options, freezepanes);
  154. }
  155. /**
  156. * set whether the window should display zero values
  157. * @param zeros or not
  158. */
  159. public void setDisplayZeros(boolean zeros)
  160. {
  161. field_1_options = displayZeros.setShortBoolean(field_1_options, zeros);
  162. }
  163. /**
  164. * set whether the window should display a default header
  165. * @param header or not
  166. */
  167. public void setDefaultHeader(boolean header)
  168. {
  169. field_1_options = defaultHeader.setShortBoolean(field_1_options, header);
  170. }
  171. /**
  172. * is this arabic?
  173. * @param isarabic arabic or not
  174. */
  175. public void setArabic(boolean isarabic)
  176. {
  177. field_1_options = arabic.setShortBoolean(field_1_options, isarabic);
  178. }
  179. /**
  180. * set whether the outline symbols are displaed
  181. * @param guts symbols or not
  182. */
  183. public void setDisplayGuts(boolean guts)
  184. {
  185. field_1_options = displayGuts.setShortBoolean(field_1_options, guts);
  186. }
  187. /**
  188. * freeze unsplit panes or not
  189. * @param freeze or not
  190. */
  191. public void setFreezePanesNoSplit(boolean freeze)
  192. {
  193. field_1_options = freezePanesNoSplit.setShortBoolean(field_1_options, freeze);
  194. }
  195. /**
  196. * sheet tab is selected
  197. * @param sel selected or not
  198. */
  199. public void setSelected(boolean sel)
  200. {
  201. field_1_options = selected.setShortBoolean(field_1_options, sel);
  202. }
  203. /**
  204. * is the sheet currently displayed in the window
  205. * @param p displayed or not
  206. */
  207. public void setPaged(boolean p)
  208. {
  209. field_1_options = paged.setShortBoolean(field_1_options, p);
  210. }
  211. /**
  212. * was the sheet saved in page break view
  213. * @param p pagebreaksaved or not
  214. */
  215. public void setSavedInPageBreakPreview(boolean p)
  216. {
  217. field_1_options = savedInPageBreakPreview.setShortBoolean(field_1_options, p);
  218. }
  219. // end of bitfields.
  220. /**
  221. * set the top row visible in the window
  222. * @param topRow top row visible
  223. */
  224. public void setTopRow(short topRow)
  225. {
  226. field_2_top_row = topRow;
  227. }
  228. /**
  229. * set the leftmost column displayed in the window
  230. * @param leftCol leftmost column
  231. */
  232. public void setLeftCol(short leftCol)
  233. {
  234. field_3_left_col = leftCol;
  235. }
  236. /**
  237. * set the palette index for the header color
  238. * @param color
  239. */
  240. public void setHeaderColor(int color)
  241. {
  242. field_4_header_color = color;
  243. }
  244. /**
  245. * zoom magification in page break view
  246. * @param zoom
  247. */
  248. public void setPageBreakZoom(short zoom)
  249. {
  250. field_5_page_break_zoom = zoom;
  251. }
  252. /**
  253. * set the zoom magnification in normal view
  254. * @param zoom
  255. */
  256. public void setNormalZoom(short zoom)
  257. {
  258. field_6_normal_zoom = zoom;
  259. }
  260. /**
  261. * set the reserved (don't do this) value
  262. */
  263. public void setReserved(int reserved)
  264. {
  265. field_7_reserved = reserved;
  266. }
  267. /**
  268. * get the options bitmask or just use the bit setters.
  269. * @return options
  270. */
  271. public short getOptions()
  272. {
  273. return field_1_options;
  274. }
  275. // option bitfields
  276. /**
  277. * get whether the window should display formulas
  278. * @return formulas or not
  279. */
  280. public boolean getDisplayFormulas()
  281. {
  282. return displayFormulas.isSet(field_1_options);
  283. }
  284. /**
  285. * get whether the window should display gridlines
  286. * @return gridlines or not
  287. */
  288. public boolean getDisplayGridlines()
  289. {
  290. return displayGridlines.isSet(field_1_options);
  291. }
  292. /**
  293. * get whether the window should display row and column headings
  294. * @return headings or not
  295. */
  296. public boolean getDisplayRowColHeadings()
  297. {
  298. return displayRowColHeadings.isSet(field_1_options);
  299. }
  300. /**
  301. * get whether the window should freeze panes
  302. * @return freeze panes or not
  303. */
  304. public boolean getFreezePanes()
  305. {
  306. return freezePanes.isSet(field_1_options);
  307. }
  308. /**
  309. * get whether the window should display zero values
  310. * @return zeros or not
  311. */
  312. public boolean getDisplayZeros()
  313. {
  314. return displayZeros.isSet(field_1_options);
  315. }
  316. /**
  317. * get whether the window should display a default header
  318. * @return header or not
  319. */
  320. public boolean getDefaultHeader()
  321. {
  322. return defaultHeader.isSet(field_1_options);
  323. }
  324. /**
  325. * is this arabic?
  326. * @return arabic or not
  327. */
  328. public boolean getArabic()
  329. {
  330. return arabic.isSet(field_1_options);
  331. }
  332. /**
  333. * get whether the outline symbols are displaed
  334. * @return symbols or not
  335. */
  336. public boolean getDisplayGuts()
  337. {
  338. return displayGuts.isSet(field_1_options);
  339. }
  340. /**
  341. * freeze unsplit panes or not
  342. * @return freeze or not
  343. */
  344. public boolean getFreezePanesNoSplit()
  345. {
  346. return freezePanesNoSplit.isSet(field_1_options);
  347. }
  348. /**
  349. * sheet tab is selected
  350. * @return selected or not
  351. */
  352. public boolean getSelected()
  353. {
  354. return selected.isSet(field_1_options);
  355. }
  356. /**
  357. * is the sheet currently displayed in the window
  358. * @return displayed or not
  359. */
  360. public boolean getPaged()
  361. {
  362. return paged.isSet(field_1_options);
  363. }
  364. /**
  365. * was the sheet saved in page break view
  366. * @return pagebreaksaved or not
  367. */
  368. public boolean getSavedInPageBreakPreview()
  369. {
  370. return savedInPageBreakPreview.isSet(field_1_options);
  371. }
  372. // end of bitfields.
  373. /**
  374. * get the top row visible in the window
  375. * @return toprow
  376. */
  377. public short getTopRow()
  378. {
  379. return field_2_top_row;
  380. }
  381. /**
  382. * get the leftmost column displayed in the window
  383. * @return leftmost
  384. */
  385. public short getLeftCol()
  386. {
  387. return field_3_left_col;
  388. }
  389. /**
  390. * get the palette index for the header color
  391. * @return color
  392. */
  393. public int getHeaderColor()
  394. {
  395. return field_4_header_color;
  396. }
  397. /**
  398. * zoom magification in page break view
  399. * @return zoom
  400. */
  401. public short getPageBreakZoom()
  402. {
  403. return field_5_page_break_zoom;
  404. }
  405. /**
  406. * get the zoom magnification in normal view
  407. * @return zoom
  408. */
  409. public short getNormalZoom()
  410. {
  411. return field_6_normal_zoom;
  412. }
  413. /**
  414. * get the reserved bits - why would you do this?
  415. * @return reserved stuff -probably garbage
  416. */
  417. public int getReserved()
  418. {
  419. return field_7_reserved;
  420. }
  421. public String toString()
  422. {
  423. StringBuffer buffer = new StringBuffer();
  424. buffer.append("[WINDOW2]\n");
  425. buffer.append(" .options = ")
  426. .append(Integer.toHexString(getOptions())).append("\n");
  427. buffer.append(" .dispformulas= ").append(getDisplayFormulas())
  428. .append("\n");
  429. buffer.append(" .dispgridlins= ").append(getDisplayGridlines())
  430. .append("\n");
  431. buffer.append(" .disprcheadin= ")
  432. .append(getDisplayRowColHeadings()).append("\n");
  433. buffer.append(" .freezepanes = ").append(getFreezePanes())
  434. .append("\n");
  435. buffer.append(" .displayzeros= ").append(getDisplayZeros())
  436. .append("\n");
  437. buffer.append(" .defaultheadr= ").append(getDefaultHeader())
  438. .append("\n");
  439. buffer.append(" .arabic = ").append(getArabic())
  440. .append("\n");
  441. buffer.append(" .displayguts = ").append(getDisplayGuts())
  442. .append("\n");
  443. buffer.append(" .frzpnsnosplt= ")
  444. .append(getFreezePanesNoSplit()).append("\n");
  445. buffer.append(" .selected = ").append(getSelected())
  446. .append("\n");
  447. buffer.append(" .paged = ").append(getPaged())
  448. .append("\n");
  449. buffer.append(" .svdinpgbrkpv= ")
  450. .append(getSavedInPageBreakPreview()).append("\n");
  451. buffer.append(" .toprow = ")
  452. .append(Integer.toHexString(getTopRow())).append("\n");
  453. buffer.append(" .leftcol = ")
  454. .append(Integer.toHexString(getLeftCol())).append("\n");
  455. buffer.append(" .headercolor = ")
  456. .append(Integer.toHexString(getHeaderColor())).append("\n");
  457. buffer.append(" .pagebreakzoom = ")
  458. .append(Integer.toHexString(getPageBreakZoom())).append("\n");
  459. buffer.append(" .normalzoom = ")
  460. .append(Integer.toHexString(getNormalZoom())).append("\n");
  461. buffer.append(" .reserved = ")
  462. .append(Integer.toHexString(getReserved())).append("\n");
  463. buffer.append("[/WINDOW2]\n");
  464. return buffer.toString();
  465. }
  466. public int serialize(int offset, byte [] data)
  467. {
  468. LittleEndian.putShort(data, 0 + offset, sid);
  469. LittleEndian.putShort(data, 2 + offset, ( short ) 18);
  470. LittleEndian.putShort(data, 4 + offset, getOptions());
  471. LittleEndian.putShort(data, 6 + offset, getTopRow());
  472. LittleEndian.putShort(data, 8 + offset, getLeftCol());
  473. LittleEndian.putInt(data, 10 + offset, getHeaderColor());
  474. LittleEndian.putShort(data, 14 + offset, getPageBreakZoom());
  475. LittleEndian.putShort(data, 16 + offset, getNormalZoom());
  476. LittleEndian.putInt(data, 18 + offset, getReserved());
  477. return getRecordSize();
  478. }
  479. public int getRecordSize()
  480. {
  481. return 22;
  482. }
  483. public short getSid()
  484. {
  485. return sid;
  486. }
  487. public Object clone() {
  488. WindowTwoRecord rec = new WindowTwoRecord();
  489. rec.field_1_options = field_1_options;
  490. rec.field_2_top_row = field_2_top_row;
  491. rec.field_3_left_col = field_3_left_col;
  492. rec.field_4_header_color = field_4_header_color;
  493. rec.field_5_page_break_zoom = field_5_page_break_zoom;
  494. rec.field_6_normal_zoom = field_6_normal_zoom;
  495. rec.field_7_reserved = field_7_reserved;
  496. return rec;
  497. }
  498. }