PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 298 lines | 154 code | 45 blank | 99 comment | 3 complexity | cee3153b17c1e6d33e9b2bc3676749c5 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 java.util.*;
  39. import loci.poi.util.LittleEndian;
  40. /**
  41. * Title: Selection Record<P>
  42. * Description: shows the user's selection on the sheet
  43. * for write set num refs to 0<P>
  44. *
  45. * TODO : Fully implement reference subrecords.
  46. * REFERENCE: PG 291 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  47. * @author Andrew C. Oliver (acoliver at apache dot org)
  48. * @author Jason Height (jheight at chariot dot net dot au)
  49. * @author Glen Stampoultzis (glens at apache.org)
  50. */
  51. public class SelectionRecord
  52. extends Record
  53. {
  54. public final static short sid = 0x1d;
  55. private byte field_1_pane;
  56. //private short field_2_row_active_cell;
  57. private int field_2_row_active_cell;
  58. private short field_3_col_active_cell;
  59. private short field_4_ref_active_cell;
  60. private short field_5_num_refs;
  61. private ArrayList field_6_refs; // not used yet
  62. public class Reference {
  63. private short field_1_first_row;
  64. private short field_2_last_row;
  65. private byte field_3_first_column;
  66. private byte field_4_last_column;
  67. Reference(RecordInputStream in) {
  68. field_1_first_row = in.readShort();
  69. field_2_last_row = in.readShort();
  70. field_3_first_column = in.readByte();
  71. field_4_last_column = in.readByte();
  72. }
  73. public short getFirstRow() {
  74. return field_1_first_row;
  75. }
  76. public short getLastRow() {
  77. return field_2_last_row;
  78. }
  79. public byte getFirstColumn() {
  80. return field_3_first_column;
  81. }
  82. public byte getLastColumn() {
  83. return field_4_last_column;
  84. }
  85. }
  86. public SelectionRecord()
  87. {
  88. }
  89. /**
  90. * Constructs a Selection record and sets its fields appropriately.
  91. * @param in the RecordInputstream to read the record from
  92. */
  93. public SelectionRecord(RecordInputStream in)
  94. {
  95. super(in);
  96. }
  97. protected void validateSid(short id)
  98. {
  99. if (id != sid)
  100. {
  101. throw new RecordFormatException("NOT A valid Selection RECORD");
  102. }
  103. }
  104. protected void fillFields(RecordInputStream in)
  105. {
  106. field_1_pane = in.readByte();
  107. //field_2_row_active_cell = LittleEndian.getShort(data, 1 + offset);
  108. field_2_row_active_cell = in.readUShort();
  109. field_3_col_active_cell = in.readShort();
  110. field_4_ref_active_cell = in.readShort();
  111. field_5_num_refs = in.readShort();
  112. field_6_refs = new ArrayList(field_5_num_refs);
  113. for (int i=0; i<field_5_num_refs; i++) {
  114. field_6_refs.add(new Reference(in));
  115. }
  116. }
  117. /**
  118. * set which window pane this is for
  119. * @param pane
  120. */
  121. public void setPane(byte pane)
  122. {
  123. field_1_pane = pane;
  124. }
  125. /**
  126. * set the active cell's row
  127. * @param row number of active cell
  128. */
  129. //public void setActiveCellRow(short row)
  130. public void setActiveCellRow(int row)
  131. {
  132. field_2_row_active_cell = row;
  133. }
  134. /**
  135. * set the active cell's col
  136. * @param col number of active cell
  137. */
  138. public void setActiveCellCol(short col)
  139. {
  140. field_3_col_active_cell = col;
  141. }
  142. /**
  143. * set the active cell's reference number
  144. * @param ref number of active cell
  145. */
  146. public void setActiveCellRef(short ref)
  147. {
  148. field_4_ref_active_cell = ref;
  149. }
  150. /**
  151. * set the number of cell refs (we don't support selection so set to 0
  152. * @param refs - number of references
  153. */
  154. public void setNumRefs(short refs)
  155. {
  156. field_5_num_refs = refs;
  157. }
  158. /**
  159. * get which window pane this is for
  160. * @return pane
  161. */
  162. public byte getPane()
  163. {
  164. return field_1_pane;
  165. }
  166. /**
  167. * get the active cell's row
  168. * @return row number of active cell
  169. */
  170. //public short getActiveCellRow()
  171. public int getActiveCellRow()
  172. {
  173. return field_2_row_active_cell;
  174. }
  175. /**
  176. * get the active cell's col
  177. * @return col number of active cell
  178. */
  179. public short getActiveCellCol()
  180. {
  181. return field_3_col_active_cell;
  182. }
  183. /**
  184. * get the active cell's reference number
  185. * @return ref number of active cell
  186. */
  187. public short getActiveCellRef()
  188. {
  189. return field_4_ref_active_cell;
  190. }
  191. /**
  192. * get the number of cell refs (we don't support selection so set to 0
  193. * @return refs - number of references
  194. */
  195. public short getNumRefs()
  196. {
  197. return field_5_num_refs;
  198. }
  199. public String toString()
  200. {
  201. StringBuffer buffer = new StringBuffer();
  202. buffer.append("[SELECTION]\n");
  203. buffer.append(" .pane = ")
  204. .append(Integer.toHexString(getPane())).append("\n");
  205. buffer.append(" .activecellrow = ")
  206. .append(Integer.toHexString(getActiveCellRow())).append("\n");
  207. buffer.append(" .activecellcol = ")
  208. .append(Integer.toHexString(getActiveCellCol())).append("\n");
  209. buffer.append(" .activecellref = ")
  210. .append(Integer.toHexString(getActiveCellRef())).append("\n");
  211. buffer.append(" .numrefs = ")
  212. .append(Integer.toHexString(getNumRefs())).append("\n");
  213. buffer.append("[/SELECTION]\n");
  214. return buffer.toString();
  215. }
  216. //hacked to provide one cell reference to 0,0 - 0,0
  217. public int serialize(int offset, byte [] data)
  218. {
  219. LittleEndian.putShort(data, 0 + offset, sid);
  220. LittleEndian.putShort(data, 2 + offset, ( short ) 15);
  221. data[ 4 + offset ] = getPane();
  222. //LittleEndian.putShort(data, 5 + offset, getActiveCellRow());
  223. LittleEndian.putShort(data, 5 + offset, ( short ) getActiveCellRow());
  224. LittleEndian.putShort(data, 7 + offset, getActiveCellCol());
  225. LittleEndian.putShort(data, 9 + offset, getActiveCellRef());
  226. LittleEndian.putShort(data, 11 + offset, ( short ) 1);
  227. LittleEndian.putShort(data, 13 + offset, ( short ) getActiveCellRow());
  228. LittleEndian.putShort(data, 15 + offset, ( short ) getActiveCellRow());
  229. data[ 17 + offset ] = (byte)getActiveCellCol();
  230. data[ 18 + offset ] = (byte)getActiveCellCol();
  231. return getRecordSize();
  232. }
  233. public int getRecordSize()
  234. {
  235. return 19;
  236. }
  237. public short getSid()
  238. {
  239. return sid;
  240. }
  241. public Object clone() {
  242. SelectionRecord rec = new SelectionRecord();
  243. rec.field_1_pane = field_1_pane;
  244. rec.field_2_row_active_cell = field_2_row_active_cell;
  245. rec.field_3_col_active_cell = field_3_col_active_cell;
  246. rec.field_4_ref_active_cell = field_4_ref_active_cell;
  247. rec.field_5_num_refs = field_5_num_refs;
  248. rec.field_6_refs = field_6_refs;
  249. return rec;
  250. }
  251. }