PageRenderTime 85ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 414 lines | 302 code | 56 blank | 56 comment | 2 complexity | 574ca7a66887d4de68c5ecf1a43a7c4a 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.LittleEndian;
  39. import loci.poi.util.BitField;
  40. import loci.poi.util.BitFieldFactory;
  41. /**
  42. * Title: Print Setup Record<P>
  43. * Description: Stores print setup options -- bogus for HSSF (and marked as such)<P>
  44. * REFERENCE: PG 385 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 PrintSetupRecord
  50. extends Record
  51. {
  52. public final static short sid = 0xa1;
  53. private short field_1_paper_size;
  54. private short field_2_scale;
  55. private short field_3_page_start;
  56. private short field_4_fit_width;
  57. private short field_5_fit_height;
  58. private short field_6_options;
  59. static final private BitField lefttoright =
  60. BitFieldFactory.getInstance(0x01); // print over then down
  61. static final private BitField landscape =
  62. BitFieldFactory.getInstance(0x02); // landscape mode
  63. static final private BitField validsettings = BitFieldFactory.getInstance(
  64. 0x04); // if papersize, scale, resolution, copies, landscape
  65. // weren't obtained from the print consider them
  66. // mere bunk
  67. static final private BitField nocolor =
  68. BitFieldFactory.getInstance(0x08); // print mono/b&w, colorless
  69. static final private BitField draft =
  70. BitFieldFactory.getInstance(0x10); // print draft quality
  71. static final private BitField notes =
  72. BitFieldFactory.getInstance(0x20); // print the notes
  73. static final private BitField noOrientation =
  74. BitFieldFactory.getInstance(0x40); // the orientation is not set
  75. static final private BitField usepage =
  76. BitFieldFactory.getInstance(0x80); // use a user set page no, instead of auto
  77. private short field_7_hresolution;
  78. private short field_8_vresolution;
  79. private double field_9_headermargin;
  80. private double field_10_footermargin;
  81. private short field_11_copies;
  82. public PrintSetupRecord()
  83. {
  84. }
  85. /**
  86. * Constructs a PrintSetup (SETUP) record and sets its fields appropriately.
  87. * @param in the RecordInputstream to read the record from
  88. */
  89. public PrintSetupRecord(RecordInputStream in)
  90. {
  91. super(in);
  92. }
  93. protected void validateSid(short id)
  94. {
  95. if (id != sid)
  96. {
  97. throw new RecordFormatException(
  98. "NOT A valid PrintSetup record RECORD");
  99. }
  100. }
  101. protected void fillFields(RecordInputStream in)
  102. {
  103. field_1_paper_size = in.readShort();
  104. field_2_scale = in.readShort();
  105. field_3_page_start = in.readShort();
  106. field_4_fit_width = in.readShort();
  107. field_5_fit_height = in.readShort();
  108. field_6_options = in.readShort();
  109. field_7_hresolution = in.readShort();
  110. field_8_vresolution = in.readShort();
  111. field_9_headermargin = in.readDouble();
  112. field_10_footermargin = in.readDouble();
  113. field_11_copies = in.readShort();
  114. }
  115. public void setPaperSize(short size)
  116. {
  117. field_1_paper_size = size;
  118. }
  119. public void setScale(short scale)
  120. {
  121. field_2_scale = scale;
  122. }
  123. public void setPageStart(short start)
  124. {
  125. field_3_page_start = start;
  126. }
  127. public void setFitWidth(short width)
  128. {
  129. field_4_fit_width = width;
  130. }
  131. public void setFitHeight(short height)
  132. {
  133. field_5_fit_height = height;
  134. }
  135. public void setOptions(short options)
  136. {
  137. field_6_options = options;
  138. }
  139. // option bitfields
  140. public void setLeftToRight(boolean ltor)
  141. {
  142. field_6_options = lefttoright.setShortBoolean(field_6_options, ltor);
  143. }
  144. public void setLandscape(boolean ls)
  145. {
  146. field_6_options = landscape.setShortBoolean(field_6_options, ls);
  147. }
  148. public void setValidSettings(boolean valid)
  149. {
  150. field_6_options = validsettings.setShortBoolean(field_6_options, valid);
  151. }
  152. public void setNoColor(boolean mono)
  153. {
  154. field_6_options = nocolor.setShortBoolean(field_6_options, mono);
  155. }
  156. public void setDraft(boolean d)
  157. {
  158. field_6_options = draft.setShortBoolean(field_6_options, d);
  159. }
  160. public void setNotes(boolean printnotes)
  161. {
  162. field_6_options = notes.setShortBoolean(field_6_options, printnotes);
  163. }
  164. public void setNoOrientation(boolean orientation)
  165. {
  166. field_6_options = noOrientation.setShortBoolean(field_6_options, orientation);
  167. }
  168. public void setUsePage(boolean page)
  169. {
  170. field_6_options = usepage.setShortBoolean(field_6_options, page);
  171. }
  172. // end option bitfields
  173. public void setHResolution(short resolution)
  174. {
  175. field_7_hresolution = resolution;
  176. }
  177. public void setVResolution(short resolution)
  178. {
  179. field_8_vresolution = resolution;
  180. }
  181. public void setHeaderMargin(double headermargin)
  182. {
  183. field_9_headermargin = headermargin;
  184. }
  185. public void setFooterMargin(double footermargin)
  186. {
  187. field_10_footermargin = footermargin;
  188. }
  189. public void setCopies(short copies)
  190. {
  191. field_11_copies = copies;
  192. }
  193. public short getPaperSize()
  194. {
  195. return field_1_paper_size;
  196. }
  197. public short getScale()
  198. {
  199. return field_2_scale;
  200. }
  201. public short getPageStart()
  202. {
  203. return field_3_page_start;
  204. }
  205. public short getFitWidth()
  206. {
  207. return field_4_fit_width;
  208. }
  209. public short getFitHeight()
  210. {
  211. return field_5_fit_height;
  212. }
  213. public short getOptions()
  214. {
  215. return field_6_options;
  216. }
  217. // option bitfields
  218. public boolean getLeftToRight()
  219. {
  220. return lefttoright.isSet(field_6_options);
  221. }
  222. public boolean getLandscape()
  223. {
  224. return landscape.isSet(field_6_options);
  225. }
  226. public boolean getValidSettings()
  227. {
  228. return validsettings.isSet(field_6_options);
  229. }
  230. public boolean getNoColor()
  231. {
  232. return nocolor.isSet(field_6_options);
  233. }
  234. public boolean getDraft()
  235. {
  236. return draft.isSet(field_6_options);
  237. }
  238. public boolean getNotes()
  239. {
  240. return notes.isSet(field_6_options);
  241. }
  242. public boolean getNoOrientation()
  243. {
  244. return noOrientation.isSet(field_6_options);
  245. }
  246. public boolean getUsePage()
  247. {
  248. return usepage.isSet(field_6_options);
  249. }
  250. // end option bitfields
  251. public short getHResolution()
  252. {
  253. return field_7_hresolution;
  254. }
  255. public short getVResolution()
  256. {
  257. return field_8_vresolution;
  258. }
  259. public double getHeaderMargin()
  260. {
  261. return field_9_headermargin;
  262. }
  263. public double getFooterMargin()
  264. {
  265. return field_10_footermargin;
  266. }
  267. public short getCopies()
  268. {
  269. return field_11_copies;
  270. }
  271. public String toString()
  272. {
  273. StringBuffer buffer = new StringBuffer();
  274. buffer.append("[PRINTSETUP]\n");
  275. buffer.append(" .papersize = ").append(getPaperSize())
  276. .append("\n");
  277. buffer.append(" .scale = ").append(getScale())
  278. .append("\n");
  279. buffer.append(" .pagestart = ").append(getPageStart())
  280. .append("\n");
  281. buffer.append(" .fitwidth = ").append(getFitWidth())
  282. .append("\n");
  283. buffer.append(" .fitheight = ").append(getFitHeight())
  284. .append("\n");
  285. buffer.append(" .options = ").append(getOptions())
  286. .append("\n");
  287. buffer.append(" .ltor = ").append(getLeftToRight())
  288. .append("\n");
  289. buffer.append(" .landscape = ").append(getLandscape())
  290. .append("\n");
  291. buffer.append(" .valid = ").append(getValidSettings())
  292. .append("\n");
  293. buffer.append(" .mono = ").append(getNoColor())
  294. .append("\n");
  295. buffer.append(" .draft = ").append(getDraft())
  296. .append("\n");
  297. buffer.append(" .notes = ").append(getNotes())
  298. .append("\n");
  299. buffer.append(" .noOrientat = ").append(getNoOrientation())
  300. .append("\n");
  301. buffer.append(" .usepage = ").append(getUsePage())
  302. .append("\n");
  303. buffer.append(" .hresolution = ").append(getHResolution())
  304. .append("\n");
  305. buffer.append(" .vresolution = ").append(getVResolution())
  306. .append("\n");
  307. buffer.append(" .headermargin = ").append(getHeaderMargin())
  308. .append("\n");
  309. buffer.append(" .footermargin = ").append(getFooterMargin())
  310. .append("\n");
  311. buffer.append(" .copies = ").append(getCopies())
  312. .append("\n");
  313. buffer.append("[/PRINTSETUP]\n");
  314. return buffer.toString();
  315. }
  316. public int serialize(int offset, byte [] data)
  317. {
  318. LittleEndian.putShort(data, 0 + offset, sid);
  319. LittleEndian.putShort(data, 2 + offset, ( short ) 34);
  320. LittleEndian.putShort(data, 4 + offset, getPaperSize());
  321. LittleEndian.putShort(data, 6 + offset, getScale());
  322. LittleEndian.putShort(data, 8 + offset, getPageStart());
  323. LittleEndian.putShort(data, 10 + offset, getFitWidth());
  324. LittleEndian.putShort(data, 12 + offset, getFitHeight());
  325. LittleEndian.putShort(data, 14 + offset, getOptions());
  326. LittleEndian.putShort(data, 16 + offset, getHResolution());
  327. LittleEndian.putShort(data, 18 + offset, getVResolution());
  328. LittleEndian.putDouble(data, 20 + offset, getHeaderMargin());
  329. LittleEndian.putDouble(data, 28 + offset, getFooterMargin());
  330. LittleEndian.putShort(data, 36 + offset, getCopies());
  331. return getRecordSize();
  332. }
  333. public int getRecordSize()
  334. {
  335. return 38;
  336. }
  337. public short getSid()
  338. {
  339. return sid;
  340. }
  341. public Object clone() {
  342. PrintSetupRecord rec = new PrintSetupRecord();
  343. rec.field_1_paper_size = field_1_paper_size;
  344. rec.field_2_scale = field_2_scale;
  345. rec.field_3_page_start = field_3_page_start;
  346. rec.field_4_fit_width = field_4_fit_width;
  347. rec.field_5_fit_height = field_5_fit_height;
  348. rec.field_6_options = field_6_options;
  349. rec.field_7_hresolution = field_7_hresolution;
  350. rec.field_8_vresolution = field_8_vresolution;
  351. rec.field_9_headermargin = field_9_headermargin;
  352. rec.field_10_footermargin = field_10_footermargin;
  353. rec.field_11_copies = field_11_copies;
  354. return rec;
  355. }
  356. }