1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.xmerge.converter.xml.sxc.pexcel.records; 25 26 import java.io.OutputStream; 27 import java.io.InputStream; 28 import java.io.IOException; 29 import java.awt.Point; 30 31 import org.openoffice.xmerge.util.Debug; 32 import org.openoffice.xmerge.util.EndianConverter; 33 import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants; 34 import org.openoffice.xmerge.converter.xml.sxc.SheetSettings; 35 36 /** 37 * Represents a BIFF Record that describes the number and position of unfrozen 38 * panes. 39 */ 40 public class Pane implements BIFFRecord { 41 42 private byte[] x = new byte[2]; 43 private byte[] y = new byte[2]; 44 private byte[] rwTop = new byte[2]; 45 private byte[] colLeft = new byte[2]; 46 private byte pnnAcct; 47 48 /** 49 * Default Constructor 50 */ Pane()51 public Pane() { 52 pnnAcct = (byte) 0x02; // Default setting 53 } 54 55 /** 56 * Constructs a Pane Record from the <code>InputStream</code> 57 * 58 * @param is InputStream containing a Pane record 59 */ Pane(InputStream is)60 public Pane(InputStream is) throws IOException { 61 read(is); 62 } 63 64 /** 65 * Get the hex code for this particular <code>BIFFRecord</code> 66 * 67 * @return the hex code for <code>Pane</code> 68 */ getBiffType()69 public short getBiffType() { 70 return PocketExcelConstants.PANE_INFO; 71 } 72 73 /** 74 * Gets the split point for this pane, in the case of splits this will be 75 * in twips. 76 * 77 * @return the split point 78 */ getSplitPoint()79 public Point getSplitPoint() { 80 81 int xTwips = EndianConverter.readShort(x)/11; 82 int yTwips = EndianConverter.readShort(y)/15; 83 return (new Point(xTwips, yTwips)); 84 } 85 86 /** 87 * Gets the freeze point for this pane, in the case of freezes this will 88 * be a zero-based index to either the column or row. 89 * 90 * @return the freeze point 91 */ getFreezePoint()92 public Point getFreezePoint() { 93 94 return (new Point(EndianConverter.readShort(x), 95 EndianConverter.readShort(y))); 96 } 97 98 /** 99 * Sets the split point for this pane, coordinates are in column row units 100 * if the split type is freeze or twips if split type is split. 101 * 102 * @param splitType contains the X and Y split types (freeze or split) 103 * @param p the split point 104 */ setSplitPoint(Point splitType, Point p)105 public void setSplitPoint(Point splitType, Point p) { 106 107 if(splitType.getX()==SheetSettings.SPLIT 108 || splitType.getY()==SheetSettings.SPLIT) { 109 int yTwips = (int) p.getY(); 110 short yPxl = (short) (yTwips * 15); 111 y = EndianConverter.writeShort(yPxl); 112 int xTwips = (int) p.getX(); 113 short xPxl = (short) (xTwips * 11); 114 x = EndianConverter.writeShort(xPxl); 115 } else { 116 y = EndianConverter.writeShort((short) p.getY()); 117 x = EndianConverter.writeShort((short) p.getX()); 118 } 119 120 } 121 122 /** 123 * Set the pane number of the active pane 124 * 0 - bottom right, 1 - top right 125 * 2 - bottom left, 3 - top left 126 * 127 * @param paneNumber the pane number of the active pane 128 */ setPaneNumber(int paneNumber)129 public void setPaneNumber(int paneNumber) { 130 pnnAcct = (byte) paneNumber; 131 } 132 133 /** 134 * Get the pane number of the active pane 135 * 0 - bottom right, 1 - top right 136 * 2 - bottom left, 3 - top left 137 * 138 * @return the hex code for <code>Pane</code> 139 */ getPaneNumber()140 public int getPaneNumber() { 141 return pnnAcct; 142 } 143 144 /** 145 * Set the top row visible in the lower pane 146 * 147 * @param top 0-based inex of the top row 148 */ setTop(int top)149 public void setTop(int top) { 150 rwTop = EndianConverter.writeShort((short)top); 151 } 152 153 /** 154 * Set leftmost column visible in the right pane 155 * 156 * @param left 0-based index of the leftmost column 157 */ setLeft(int left)158 public void setLeft(int left) { 159 colLeft = EndianConverter.writeShort((short)left); 160 } 161 162 /** 163 * Get the top row visible in the lower pane 164 * 165 * @return the hex code for <code>Pane</code> 166 */ getTop()167 public int getTop() { 168 return EndianConverter.readShort(rwTop); 169 } 170 171 /** 172 * Get leftmost column visible in the right pane 173 * 174 * @return 0-based index of the column 175 */ getLeft()176 public int getLeft() { 177 return EndianConverter.readShort(colLeft); 178 } 179 180 181 /** 182 * Reads a <code>Pane</code> record from the <code>InputStream</code> 183 * 184 * @param input <code>InputStream</code> to read from 185 * @return the total number of bytes read 186 */ read(InputStream input)187 public int read(InputStream input) throws IOException { 188 189 int numOfBytesRead = input.read(x); 190 numOfBytesRead += input.read(y); 191 numOfBytesRead += input.read(rwTop); 192 numOfBytesRead += input.read(colLeft); 193 pnnAcct = (byte) input.read(); 194 numOfBytesRead++; 195 196 Debug.log(Debug.TRACE, "\tx : "+ EndianConverter.readShort(x) + 197 " y : " + EndianConverter.readShort(y) + 198 " rwTop : " + EndianConverter.readShort(rwTop) + 199 " colLeft : " + EndianConverter.readShort(colLeft) + 200 " pnnAcct : " + pnnAcct); 201 202 return numOfBytesRead; 203 } 204 write(OutputStream output)205 public void write(OutputStream output) throws IOException { 206 207 output.write(getBiffType()); 208 output.write(x); 209 output.write(y); 210 output.write(rwTop); 211 output.write(colLeft); 212 output.write(pnnAcct); 213 214 Debug.log(Debug.TRACE,"Writing Pane record"); 215 } 216 } 217