PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 338 lines | 156 code | 52 blank | 130 comment | 2 complexity | 8e21c5d1d0d27d16f6fc60aa41f7c6b7 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. /*
  38. * ColumnInfoRecord.java
  39. *
  40. * Created on December 8, 2001, 8:44 AM
  41. */
  42. package loci.poi.hssf.record;
  43. import loci.poi.util.LittleEndian;
  44. import loci.poi.util.BitField;
  45. import loci.poi.util.BitFieldFactory;
  46. /**
  47. * Title: ColumnInfo Record<P>
  48. * Description: Defines with width and formatting for a range of columns<P>
  49. * REFERENCE: PG 293 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  50. * @author Andrew C. Oliver (acoliver at apache dot org)
  51. * @version 2.0-pre
  52. */
  53. public class ColumnInfoRecord
  54. extends Record
  55. {
  56. public static final short sid = 0x7d;
  57. private short field_1_first_col;
  58. private short field_2_last_col;
  59. private short field_3_col_width;
  60. private short field_4_xf_index;
  61. private short field_5_options;
  62. static final private BitField hidden = BitFieldFactory.getInstance(0x01);
  63. static final private BitField outlevel = BitFieldFactory.getInstance(0x0700);
  64. static final private BitField collapsed = BitFieldFactory.getInstance(0x1000);
  65. private short field_6_reserved;
  66. public ColumnInfoRecord()
  67. {
  68. }
  69. /**
  70. * Constructs a ColumnInfo record and sets its fields appropriately
  71. * @param in the RecordInputstream to read the record from
  72. */
  73. public ColumnInfoRecord(RecordInputStream in)
  74. {
  75. super(in);
  76. }
  77. protected void fillFields(RecordInputStream in)
  78. {
  79. field_1_first_col = in.readShort();
  80. field_2_last_col = in.readShort();
  81. field_3_col_width = in.readShort();
  82. field_4_xf_index = in.readShort();
  83. field_5_options = in.readShort();
  84. field_6_reserved = in.readShort();
  85. }
  86. protected void validateSid(short id)
  87. {
  88. if (id != sid)
  89. {
  90. throw new RecordFormatException("NOT A COLINFO RECORD!!");
  91. }
  92. }
  93. /**
  94. * set the first column this record defines formatting info for
  95. * @param fc - the first column index (0-based)
  96. */
  97. public void setFirstColumn(short fc)
  98. {
  99. field_1_first_col = fc;
  100. }
  101. /**
  102. * set the last column this record defines formatting info for
  103. * @param lc - the last column index (0-based)
  104. */
  105. public void setLastColumn(short lc)
  106. {
  107. field_2_last_col = lc;
  108. }
  109. /**
  110. * set the columns' width in 1/256 of a character width
  111. * @param cw - column width
  112. */
  113. public void setColumnWidth(short cw)
  114. {
  115. field_3_col_width = cw;
  116. }
  117. /**
  118. * set the columns' default format info
  119. * @param xfi - the extended format index
  120. * @see loci.poi.hssf.record.ExtendedFormatRecord
  121. */
  122. public void setXFIndex(short xfi)
  123. {
  124. field_4_xf_index = xfi;
  125. }
  126. /**
  127. * set the options bitfield - use the bitsetters instead
  128. * @param options - the bitfield raw value
  129. */
  130. public void setOptions(short options)
  131. {
  132. field_5_options = options;
  133. }
  134. // start options bitfield
  135. /**
  136. * set whether or not these cells are hidden
  137. * @param ishidden - whether the cells are hidden.
  138. * @see #setOptions(short)
  139. */
  140. public void setHidden(boolean ishidden)
  141. {
  142. field_5_options = hidden.setShortBoolean(field_5_options, ishidden);
  143. }
  144. /**
  145. * set the outline level for the cells
  146. * @see #setOptions(short)
  147. * @param olevel -outline level for the cells
  148. */
  149. public void setOutlineLevel(short olevel)
  150. {
  151. field_5_options = outlevel.setShortValue(field_5_options, olevel);
  152. }
  153. /**
  154. * set whether the cells are collapsed
  155. * @param iscollapsed - wether the cells are collapsed
  156. * @see #setOptions(short)
  157. */
  158. public void setCollapsed(boolean iscollapsed)
  159. {
  160. field_5_options = collapsed.setShortBoolean(field_5_options,
  161. iscollapsed);
  162. }
  163. // end options bitfield
  164. /**
  165. * get the first column this record defines formatting info for
  166. * @return the first column index (0-based)
  167. */
  168. public short getFirstColumn()
  169. {
  170. return field_1_first_col;
  171. }
  172. /**
  173. * get the last column this record defines formatting info for
  174. * @return the last column index (0-based)
  175. */
  176. public short getLastColumn()
  177. {
  178. return field_2_last_col;
  179. }
  180. /**
  181. * get the columns' width in 1/256 of a character width
  182. * @return column width
  183. */
  184. public short getColumnWidth()
  185. {
  186. return field_3_col_width;
  187. }
  188. /**
  189. * get the columns' default format info
  190. * @return the extended format index
  191. * @see loci.poi.hssf.record.ExtendedFormatRecord
  192. */
  193. public short getXFIndex()
  194. {
  195. return field_4_xf_index;
  196. }
  197. /**
  198. * get the options bitfield - use the bitsetters instead
  199. * @return the bitfield raw value
  200. */
  201. public short getOptions()
  202. {
  203. return field_5_options;
  204. }
  205. // start options bitfield
  206. /**
  207. * get whether or not these cells are hidden
  208. * @return whether the cells are hidden.
  209. * @see #setOptions(short)
  210. */
  211. public boolean getHidden()
  212. {
  213. return hidden.isSet(field_5_options);
  214. }
  215. /**
  216. * get the outline level for the cells
  217. * @see #setOptions(short)
  218. * @return outline level for the cells
  219. */
  220. public short getOutlineLevel()
  221. {
  222. return outlevel.getShortValue(field_5_options);
  223. }
  224. /**
  225. * get whether the cells are collapsed
  226. * @return wether the cells are collapsed
  227. * @see #setOptions(short)
  228. */
  229. public boolean getCollapsed()
  230. {
  231. return collapsed.isSet(field_5_options);
  232. }
  233. // end options bitfield
  234. public short getSid()
  235. {
  236. return sid;
  237. }
  238. public int serialize(int offset, byte [] data)
  239. {
  240. LittleEndian.putShort(data, 0 + offset, sid);
  241. LittleEndian.putShort(data, 2 + offset, ( short ) 12);
  242. LittleEndian.putShort(data, 4 + offset, getFirstColumn());
  243. LittleEndian.putShort(data, 6 + offset, getLastColumn());
  244. LittleEndian.putShort(data, 8 + offset, getColumnWidth());
  245. LittleEndian.putShort(data, 10 + offset, getXFIndex());
  246. LittleEndian.putShort(data, 12 + offset, getOptions());
  247. LittleEndian.putShort(data, 14 + offset, field_6_reserved);
  248. return getRecordSize();
  249. }
  250. public int getRecordSize()
  251. {
  252. return 16;
  253. }
  254. public String toString()
  255. {
  256. StringBuffer buffer = new StringBuffer();
  257. buffer.append("[COLINFO]\n");
  258. buffer.append("colfirst = ").append(getFirstColumn())
  259. .append("\n");
  260. buffer.append("collast = ").append(getLastColumn())
  261. .append("\n");
  262. buffer.append("colwidth = ").append(getColumnWidth())
  263. .append("\n");
  264. buffer.append("xfindex = ").append(getXFIndex()).append("\n");
  265. buffer.append("options = ").append(getOptions()).append("\n");
  266. buffer.append(" hidden = ").append(getHidden()).append("\n");
  267. buffer.append(" olevel = ").append(getOutlineLevel())
  268. .append("\n");
  269. buffer.append(" collapsed = ").append(getCollapsed())
  270. .append("\n");
  271. buffer.append("[/COLINFO]\n");
  272. return buffer.toString();
  273. }
  274. public Object clone() {
  275. ColumnInfoRecord rec = new ColumnInfoRecord();
  276. rec.field_1_first_col = field_1_first_col;
  277. rec.field_2_last_col = field_2_last_col;
  278. rec.field_3_col_width = field_3_col_width;
  279. rec.field_4_xf_index = field_4_xf_index;
  280. rec.field_5_options = field_5_options;
  281. rec.field_6_reserved = field_6_reserved;
  282. return rec;
  283. }
  284. }