PageRenderTime 46ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/formula/Ref3DPtg.java

http://github.com/openmicroscopy/bioformats
Java | 210 lines | 123 code | 33 blank | 54 comment | 5 complexity | dc1a340f0e038706fba89d2517c6800d 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.formula;
  38. import loci.poi.util.LittleEndian;
  39. import loci.poi.hssf.util.RangeAddress;
  40. import loci.poi.hssf.util.CellReference;
  41. import loci.poi.hssf.util.SheetReferences;
  42. import loci.poi.hssf.model.Workbook;
  43. import loci.poi.util.BitField;
  44. import loci.poi.util.BitFieldFactory;
  45. import loci.poi.hssf.model.Workbook;
  46. import loci.poi.hssf.record.RecordInputStream;
  47. /**
  48. * Title: Reference 3D Ptg <P>
  49. * Description: Defined a cell in extern sheet. <P>
  50. * REFERENCE: <P>
  51. * @author Libin Roman (Vista Portal LDT. Developer)
  52. * @author Jason Height (jheight at chariot dot net dot au)
  53. * @version 1.0-pre
  54. */
  55. public class Ref3DPtg extends Ptg {
  56. public final static byte sid = 0x3a;
  57. private final static int SIZE = 7; // 6 + 1 for Ptg
  58. private short field_1_index_extern_sheet;
  59. private short field_2_row;
  60. private short field_3_column;
  61. private BitField rowRelative = BitFieldFactory.getInstance(0x8000);
  62. private BitField colRelative = BitFieldFactory.getInstance(0x4000);
  63. /** Creates new AreaPtg */
  64. public Ref3DPtg() {}
  65. public Ref3DPtg(RecordInputStream in) {
  66. field_1_index_extern_sheet = in.readShort();
  67. field_2_row = in.readShort();
  68. field_3_column = in.readShort();
  69. }
  70. public Ref3DPtg(String cellref, short externIdx ) {
  71. CellReference c= new CellReference(cellref);
  72. setRow((short) c.getRow());
  73. setColumn((short) c.getCol());
  74. setColRelative(!c.isColAbsolute());
  75. setRowRelative(!c.isRowAbsolute());
  76. setExternSheetIndex(externIdx);
  77. }
  78. public String toString() {
  79. StringBuffer buffer = new StringBuffer();
  80. buffer.append("Ref3dPtg\n");
  81. buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n");
  82. buffer.append("Row = " + getRow()).append("\n");
  83. buffer.append("Col = " + getColumn()).append("\n");
  84. buffer.append("ColRowRel= "
  85. + isRowRelative()).append("\n");
  86. buffer.append("ColRel = " + isColRelative()).append("\n");
  87. return buffer.toString();
  88. }
  89. public void writeBytes(byte [] array, int offset) {
  90. array[ 0 + offset ] = (byte) (sid + ptgClass);
  91. LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
  92. LittleEndian.putShort(array, 3 + offset , getRow());
  93. LittleEndian.putShort(array, 5 + offset , getColumnRaw());
  94. }
  95. public int getSize() {
  96. return SIZE;
  97. }
  98. public short getExternSheetIndex(){
  99. return field_1_index_extern_sheet;
  100. }
  101. public void setExternSheetIndex(short index){
  102. field_1_index_extern_sheet = index;
  103. }
  104. public short getRow() {
  105. return field_2_row;
  106. }
  107. public void setRow(short row) {
  108. field_2_row = row;
  109. }
  110. public short getColumn() {
  111. return ( short ) (field_3_column & 0xFF);
  112. }
  113. public short getColumnRaw() {
  114. return field_3_column;
  115. }
  116. public boolean isRowRelative()
  117. {
  118. return rowRelative.isSet(field_3_column);
  119. }
  120. public void setRowRelative(boolean rel) {
  121. field_3_column=rowRelative.setShortBoolean(field_3_column,rel);
  122. }
  123. public boolean isColRelative()
  124. {
  125. return colRelative.isSet(field_3_column);
  126. }
  127. public void setColRelative(boolean rel) {
  128. field_3_column=colRelative.setShortBoolean(field_3_column,rel);
  129. }
  130. public void setColumn(short column) {
  131. field_3_column &= 0xFF00;
  132. field_3_column |= column & 0xFF;
  133. }
  134. public void setColumnRaw(short column) {
  135. field_3_column = column;
  136. }
  137. /* public String getArea(){
  138. RangeAddress ra = new RangeAddress("");
  139. String result = (ra.numTo26Sys(getColumn()) + (getRow() + 1));
  140. return result;
  141. }*/
  142. public void setArea(String ref){
  143. RangeAddress ra = new RangeAddress(ref);
  144. String from = ra.getFromCell();
  145. setColumn((short) (ra.getXPosition(from) -1));
  146. setRow((short) (ra.getYPosition(from) -1));
  147. }
  148. public String toFormulaString(Workbook book) {
  149. StringBuffer retval = new StringBuffer();
  150. SheetReferences refs = book == null ? null : book.getSheetReferences();
  151. if (refs != null) {
  152. String sheetName =refs.getSheetName((int)this.field_1_index_extern_sheet);
  153. boolean appendQuotes = sheetName.indexOf(" ") >= 0;
  154. if (appendQuotes)
  155. retval.append("'");
  156. retval.append(sheetName);
  157. if (appendQuotes)
  158. retval.append("'");
  159. retval.append('!');
  160. }
  161. retval.append((new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString());
  162. return retval.toString();
  163. }
  164. public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
  165. public Object clone() {
  166. Ref3DPtg ptg = new Ref3DPtg();
  167. ptg.field_1_index_extern_sheet = field_1_index_extern_sheet;
  168. ptg.field_2_row = field_2_row;
  169. ptg.field_3_column = field_3_column;
  170. ptg.setClass(ptgClass);
  171. return ptg;
  172. }
  173. }