PageRenderTime 34ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 228 lines | 105 code | 33 blank | 90 comment | 2 complexity | 03d5ffaac8745d62ce62bc726770fc05 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. /**
  40. * Title: Guts Record <P>
  41. * Description: Row/column gutter sizes <P>
  42. * REFERENCE: PG 320 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  43. * @author Andrew C. Oliver (acoliver at apache dot org)
  44. * @author Jason Height (jheight at chariot dot net dot au)
  45. * @version 2.0-pre
  46. */
  47. public class GutsRecord
  48. extends Record
  49. {
  50. public final static short sid = 0x80;
  51. private short field_1_left_row_gutter; // size of the row gutter to the left of the rows
  52. private short field_2_top_col_gutter; // size of the column gutter above the columns
  53. private short field_3_row_level_max; // maximum outline level for row gutters
  54. private short field_4_col_level_max; // maximum outline level for column gutters
  55. public GutsRecord()
  56. {
  57. }
  58. /**
  59. * Constructs a Guts record and sets its fields appropriately.
  60. * @param in the RecordInputstream to read the record from
  61. */
  62. public GutsRecord(RecordInputStream in)
  63. {
  64. super(in);
  65. }
  66. protected void validateSid(short id)
  67. {
  68. if (id != sid)
  69. {
  70. throw new RecordFormatException("NOT A Guts RECORD");
  71. }
  72. }
  73. protected void fillFields(RecordInputStream in)
  74. {
  75. field_1_left_row_gutter = in.readShort();
  76. field_2_top_col_gutter = in.readShort();
  77. field_3_row_level_max = in.readShort();
  78. field_4_col_level_max = in.readShort();
  79. }
  80. /**
  81. * set the size of the gutter that appears at the left of the rows
  82. *
  83. * @param gut gutter size in screen units
  84. */
  85. public void setLeftRowGutter(short gut)
  86. {
  87. field_1_left_row_gutter = gut;
  88. }
  89. /**
  90. * set the size of the gutter that appears at the above the columns
  91. *
  92. * @param gut gutter size in screen units
  93. */
  94. public void setTopColGutter(short gut)
  95. {
  96. field_2_top_col_gutter = gut;
  97. }
  98. /**
  99. * set the maximum outline level for the row gutter.
  100. *
  101. * @param max maximum outline level
  102. */
  103. public void setRowLevelMax(short max)
  104. {
  105. field_3_row_level_max = max;
  106. }
  107. /**
  108. * set the maximum outline level for the col gutter.
  109. *
  110. * @param max maximum outline level
  111. */
  112. public void setColLevelMax(short max)
  113. {
  114. field_4_col_level_max = max;
  115. }
  116. /**
  117. * get the size of the gutter that appears at the left of the rows
  118. *
  119. * @return gutter size in screen units
  120. */
  121. public short getLeftRowGutter()
  122. {
  123. return field_1_left_row_gutter;
  124. }
  125. /**
  126. * get the size of the gutter that appears at the above the columns
  127. *
  128. * @return gutter size in screen units
  129. */
  130. public short getTopColGutter()
  131. {
  132. return field_2_top_col_gutter;
  133. }
  134. /**
  135. * get the maximum outline level for the row gutter.
  136. *
  137. * @return maximum outline level
  138. */
  139. public short getRowLevelMax()
  140. {
  141. return field_3_row_level_max;
  142. }
  143. /**
  144. * get the maximum outline level for the col gutter.
  145. *
  146. * @return maximum outline level
  147. */
  148. public short getColLevelMax()
  149. {
  150. return field_4_col_level_max;
  151. }
  152. public String toString()
  153. {
  154. StringBuffer buffer = new StringBuffer();
  155. buffer.append("[GUTS]\n");
  156. buffer.append(" .leftgutter = ")
  157. .append(Integer.toHexString(getLeftRowGutter())).append("\n");
  158. buffer.append(" .topgutter = ")
  159. .append(Integer.toHexString(getTopColGutter())).append("\n");
  160. buffer.append(" .rowlevelmax = ")
  161. .append(Integer.toHexString(getRowLevelMax())).append("\n");
  162. buffer.append(" .collevelmax = ")
  163. .append(Integer.toHexString(getColLevelMax())).append("\n");
  164. buffer.append("[/GUTS]\n");
  165. return buffer.toString();
  166. }
  167. public int serialize(int offset, byte [] data)
  168. {
  169. LittleEndian.putShort(data, 0 + offset, sid);
  170. LittleEndian.putShort(data, 2 + offset, ( short ) 0x8);
  171. LittleEndian.putShort(data, 4 + offset, getLeftRowGutter());
  172. LittleEndian.putShort(data, 6 + offset, getTopColGutter());
  173. LittleEndian.putShort(data, 8 + offset, getRowLevelMax());
  174. LittleEndian.putShort(data, 10 + offset, getColLevelMax());
  175. return getRecordSize();
  176. }
  177. public int getRecordSize()
  178. {
  179. return 12;
  180. }
  181. public short getSid()
  182. {
  183. return sid;
  184. }
  185. public Object clone() {
  186. GutsRecord rec = new GutsRecord();
  187. rec.field_1_left_row_gutter = field_1_left_row_gutter;
  188. rec.field_2_top_col_gutter = field_2_top_col_gutter;
  189. rec.field_3_row_level_max = field_3_row_level_max;
  190. rec.field_4_col_level_max = field_4_col_level_max;
  191. return rec;
  192. }
  193. }