您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WindowTwoRecord.java 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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 java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.util.BitField;
  19. import org.apache.poi.util.BitFieldFactory;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. import org.apache.poi.util.LittleEndianOutput;
  22. /**
  23. * Sheet window settings
  24. *
  25. * @version 2.0-pre
  26. */
  27. public final class WindowTwoRecord extends StandardRecord {
  28. public static final 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. public WindowTwoRecord(WindowTwoRecord other) {
  54. super(other);
  55. field_1_options = other.field_1_options;
  56. field_2_top_row = other.field_2_top_row;
  57. field_3_left_col = other.field_3_left_col;
  58. field_4_header_color = other.field_4_header_color;
  59. field_5_page_break_zoom = other.field_5_page_break_zoom;
  60. field_6_normal_zoom = other.field_6_normal_zoom;
  61. field_7_reserved = other.field_7_reserved;
  62. }
  63. public WindowTwoRecord(RecordInputStream in) {
  64. int size = in.remaining();
  65. field_1_options = in.readShort();
  66. field_2_top_row = in.readShort();
  67. field_3_left_col = in.readShort();
  68. field_4_header_color = in.readInt();
  69. if (size > 10)
  70. {
  71. field_5_page_break_zoom = in.readShort();
  72. field_6_normal_zoom = in.readShort();
  73. }
  74. if (size > 14)
  75. { // there is a special case of this record that has only 14 bytes...undocumented!
  76. field_7_reserved = in.readInt();
  77. }
  78. }
  79. /**
  80. * set the options bitmask or just use the bit setters.
  81. *
  82. * @param options Which options to set for this record
  83. */
  84. public void setOptions(short options)
  85. {
  86. field_1_options = options;
  87. }
  88. // option bitfields
  89. /**
  90. * set whether the window should display formulas
  91. * @param formulas or not
  92. */
  93. public void setDisplayFormulas(boolean formulas)
  94. {
  95. field_1_options = displayFormulas.setShortBoolean(field_1_options, formulas);
  96. }
  97. /**
  98. * set whether the window should display gridlines
  99. * @param gridlines or not
  100. */
  101. public void setDisplayGridlines(boolean gridlines)
  102. {
  103. field_1_options = displayGridlines.setShortBoolean(field_1_options, gridlines);
  104. }
  105. /**
  106. * set whether the window should display row and column headings
  107. * @param headings or not
  108. */
  109. public void setDisplayRowColHeadings(boolean headings)
  110. {
  111. field_1_options = displayRowColHeadings.setShortBoolean(field_1_options, headings);
  112. }
  113. /**
  114. * set whether the window should freeze panes
  115. * @param freezepanes freeze panes or not
  116. */
  117. public void setFreezePanes(boolean freezepanes)
  118. {
  119. field_1_options = freezePanes.setShortBoolean(field_1_options, freezepanes);
  120. }
  121. /**
  122. * set whether the window should display zero values
  123. * @param zeros or not
  124. */
  125. public void setDisplayZeros(boolean zeros)
  126. {
  127. field_1_options = displayZeros.setShortBoolean(field_1_options, zeros);
  128. }
  129. /**
  130. * set whether the window should display a default header
  131. * @param header or not
  132. */
  133. public void setDefaultHeader(boolean header)
  134. {
  135. field_1_options = defaultHeader.setShortBoolean(field_1_options, header);
  136. }
  137. /**
  138. * is this arabic?
  139. * @param isarabic arabic or not
  140. */
  141. public void setArabic(boolean isarabic)
  142. {
  143. field_1_options = arabic.setShortBoolean(field_1_options, isarabic);
  144. }
  145. /**
  146. * set whether the outline symbols are displaed
  147. * @param guts symbols or not
  148. */
  149. public void setDisplayGuts(boolean guts)
  150. {
  151. field_1_options = displayGuts.setShortBoolean(field_1_options, guts);
  152. }
  153. /**
  154. * freeze unsplit panes or not
  155. * @param freeze or not
  156. */
  157. public void setFreezePanesNoSplit(boolean freeze)
  158. {
  159. field_1_options = freezePanesNoSplit.setShortBoolean(field_1_options, freeze);
  160. }
  161. /**
  162. * sheet tab is selected
  163. * @param sel selected or not
  164. */
  165. public void setSelected(boolean sel)
  166. {
  167. field_1_options = selected.setShortBoolean(field_1_options, sel);
  168. }
  169. /**
  170. * is the sheet currently displayed in the window
  171. * @param p displayed or not
  172. */
  173. public void setActive(boolean p) {
  174. field_1_options = active.setShortBoolean(field_1_options, p);
  175. }
  176. /**
  177. * was the sheet saved in page break view
  178. * @param p pagebreaksaved or not
  179. */
  180. public void setSavedInPageBreakPreview(boolean p)
  181. {
  182. field_1_options = savedInPageBreakPreview.setShortBoolean(field_1_options, p);
  183. }
  184. // end of bitfields.
  185. /**
  186. * set the top row visible in the window
  187. * @param topRow top row visible
  188. */
  189. public void setTopRow(short topRow)
  190. {
  191. field_2_top_row = topRow;
  192. }
  193. /**
  194. * set the leftmost column displayed in the window
  195. * @param leftCol leftmost column
  196. */
  197. public void setLeftCol(short leftCol)
  198. {
  199. field_3_left_col = leftCol;
  200. }
  201. /**
  202. * set the palette index for the header color
  203. *
  204. * @param color Which color to use for the header, see the specification for details
  205. */
  206. public void setHeaderColor(int color)
  207. {
  208. field_4_header_color = color;
  209. }
  210. /**
  211. * zoom magnification in page break view
  212. *
  213. * @param zoom The zoom-level to use for the page-break view
  214. */
  215. public void setPageBreakZoom(short zoom)
  216. {
  217. field_5_page_break_zoom = zoom;
  218. }
  219. /**
  220. * set the zoom magnification in normal view
  221. *
  222. * @param zoom The zoom-level to use for the normal view
  223. */
  224. public void setNormalZoom(short zoom)
  225. {
  226. field_6_normal_zoom = zoom;
  227. }
  228. /**
  229. * set the reserved (don't do this) value
  230. *
  231. * @param reserved reserved value usually does not need to be set
  232. */
  233. public void setReserved(int reserved)
  234. {
  235. field_7_reserved = reserved;
  236. }
  237. /**
  238. * get the options bitmask or just use the bit setters.
  239. * @return options
  240. */
  241. public short getOptions()
  242. {
  243. return field_1_options;
  244. }
  245. // option bitfields
  246. /**
  247. * get whether the window should display formulas
  248. * @return formulas or not
  249. */
  250. public boolean getDisplayFormulas()
  251. {
  252. return displayFormulas.isSet(field_1_options);
  253. }
  254. /**
  255. * get whether the window should display gridlines
  256. * @return gridlines or not
  257. */
  258. public boolean getDisplayGridlines()
  259. {
  260. return displayGridlines.isSet(field_1_options);
  261. }
  262. /**
  263. * get whether the window should display row and column headings
  264. * @return headings or not
  265. */
  266. public boolean getDisplayRowColHeadings()
  267. {
  268. return displayRowColHeadings.isSet(field_1_options);
  269. }
  270. /**
  271. * get whether the window should freeze panes
  272. * @return freeze panes or not
  273. */
  274. public boolean getFreezePanes()
  275. {
  276. return freezePanes.isSet(field_1_options);
  277. }
  278. /**
  279. * get whether the window should display zero values
  280. * @return zeros or not
  281. */
  282. public boolean getDisplayZeros()
  283. {
  284. return displayZeros.isSet(field_1_options);
  285. }
  286. /**
  287. * get whether the window should display a default header
  288. * @return header or not
  289. */
  290. public boolean getDefaultHeader()
  291. {
  292. return defaultHeader.isSet(field_1_options);
  293. }
  294. /**
  295. * is this arabic?
  296. * @return arabic or not
  297. */
  298. public boolean getArabic()
  299. {
  300. return arabic.isSet(field_1_options);
  301. }
  302. /**
  303. * get whether the outline symbols are displaed
  304. * @return symbols or not
  305. */
  306. public boolean getDisplayGuts()
  307. {
  308. return displayGuts.isSet(field_1_options);
  309. }
  310. /**
  311. * freeze unsplit panes or not
  312. * @return freeze or not
  313. */
  314. public boolean getFreezePanesNoSplit()
  315. {
  316. return freezePanesNoSplit.isSet(field_1_options);
  317. }
  318. /**
  319. * sheet tab is selected
  320. * @return selected or not
  321. */
  322. public boolean getSelected()
  323. {
  324. return selected.isSet(field_1_options);
  325. }
  326. /**
  327. * is the sheet currently displayed in the window
  328. * @return displayed or not
  329. */
  330. public boolean isActive() {
  331. return active.isSet(field_1_options);
  332. }
  333. /**
  334. * was the sheet saved in page break view
  335. * @return pagebreaksaved or not
  336. */
  337. public boolean getSavedInPageBreakPreview()
  338. {
  339. return savedInPageBreakPreview.isSet(field_1_options);
  340. }
  341. // end of bitfields.
  342. /**
  343. * get the top row visible in the window
  344. * @return toprow
  345. */
  346. public short getTopRow()
  347. {
  348. return field_2_top_row;
  349. }
  350. /**
  351. * get the leftmost column displayed in the window
  352. * @return leftmost
  353. */
  354. public short getLeftCol()
  355. {
  356. return field_3_left_col;
  357. }
  358. /**
  359. * get the palette index for the header color
  360. * @return color
  361. */
  362. public int getHeaderColor()
  363. {
  364. return field_4_header_color;
  365. }
  366. /**
  367. * zoom magification in page break view
  368. * @return zoom
  369. */
  370. public short getPageBreakZoom()
  371. {
  372. return field_5_page_break_zoom;
  373. }
  374. /**
  375. * get the zoom magnification in normal view
  376. * @return zoom
  377. */
  378. public short getNormalZoom()
  379. {
  380. return field_6_normal_zoom;
  381. }
  382. /**
  383. * get the reserved bits - why would you do this?
  384. * @return reserved stuff -probably garbage
  385. */
  386. public int getReserved()
  387. {
  388. return field_7_reserved;
  389. }
  390. public void serialize(LittleEndianOutput out) {
  391. out.writeShort(getOptions());
  392. out.writeShort(getTopRow());
  393. out.writeShort(getLeftCol());
  394. out.writeInt(getHeaderColor());
  395. out.writeShort(getPageBreakZoom());
  396. out.writeShort(getNormalZoom());
  397. out.writeInt(getReserved());
  398. }
  399. protected int getDataSize() {
  400. return 18;
  401. }
  402. public short getSid()
  403. {
  404. return sid;
  405. }
  406. @Override
  407. public WindowTwoRecord copy() {
  408. return new WindowTwoRecord(this);
  409. }
  410. @Override
  411. public HSSFRecordTypes getGenericRecordType() {
  412. return HSSFRecordTypes.WINDOW_TWO;
  413. }
  414. @Override
  415. public Map<String, Supplier<?>> getGenericProperties() {
  416. return GenericRecordUtil.getGenericProperties(
  417. "options", GenericRecordUtil.getBitsAsString(this::getOptions,
  418. new BitField[]{displayFormulas, displayGridlines, displayRowColHeadings, freezePanes, displayZeros, defaultHeader, arabic, displayGuts, freezePanesNoSplit, selected, active, savedInPageBreakPreview},
  419. new String[]{"DISPLAY_FORMULAS", "DISPLAY_GRIDLINES", "DISPLAY_ROW_COL_HEADINGS", "FREEZE_PANES", "DISPLAY_ZEROS", "DEFAULT_HEADER", "ARABIC", "DISPLAY_GUTS", "FREEZE_PANES_NO_SPLIT", "SELECTED", "ACTIVE", "SAVED_IN_PAGE_BREAK_PREVIEW"}),
  420. "topRow", this::getTopRow,
  421. "leftCol", this::getLeftCol,
  422. "headerColor", this::getHeaderColor,
  423. "pageBreakZoom", this::getPageBreakZoom,
  424. "normalZoom", this::getNormalZoom,
  425. "reserved", this::getReserved
  426. );
  427. }
  428. }