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 /** 38 * Represents a BIFF Record that describes worksheet window attributes 39 */ 40 public class Window2 implements BIFFRecord { 41 42 private final static int FROZEN = 0x08; 43 private final static int NOSPLIT = 0x01; 44 45 private byte[] rwTop = new byte[2]; 46 private byte colLeft; 47 private byte[] grbit = new byte[2]; 48 49 /** 50 * Constructor 51 */ Window2()52 public Window2() { 53 this.rwTop = EndianConverter.writeShort((short) 0); 54 this.colLeft = 0; 55 this.grbit = EndianConverter.writeShort((short) 0); 56 } 57 58 /** 59 * Constructs a Window2 Record from an <code>InputStream</code> 60 * 61 * @param is InputStream containing a Window2 Record 62 */ Window2(InputStream is)63 public Window2(InputStream is) throws IOException { 64 read(is); 65 } 66 67 /** 68 * Get the hex code for this particular <code>BIFFRecord</code> 69 * 70 * @return the hex code for <code>Window2</code> 71 */ getBiffType()72 public short getBiffType() { 73 return PocketExcelConstants.SHEET_WINDOW_INFO; 74 } 75 76 /** 77 * Sets the split type for this pane, the split type is the same for both 78 * x and y so we only test against one. 79 * 80 * @param splitType the split type based on types defined in 81 * <code>sheetSettings</code> 82 */ setSplitType(Point splitType)83 public void setSplitType(Point splitType) { 84 if(splitType.getX()==SheetSettings.SPLIT) { 85 grbit[0] &= ~FROZEN; 86 grbit[1] &= ~NOSPLIT; 87 } else { 88 grbit[0] |= FROZEN; 89 grbit[1] |= NOSPLIT; 90 } 91 } 92 93 /** 94 * This method tests if this object describes a freeze 95 * 96 * @return true if freeze otherwise false 97 */ isFrozen()98 public boolean isFrozen() { 99 if((grbit[0] & FROZEN) != FROZEN) 100 return false; 101 102 if((grbit[1] & NOSPLIT) != NOSPLIT) 103 return false; 104 105 return true; 106 } 107 108 /** 109 * This method tests if this object describes a split 110 * 111 * @return true if split otherwise false 112 */ isSplit()113 public boolean isSplit() { 114 if((grbit[0] & FROZEN) == FROZEN) 115 return false; 116 117 if((grbit[1] & NOSPLIT) == NOSPLIT) 118 return false; 119 120 return true; 121 } 122 123 /** 124 * Reads a Window2 Record from an <code>InputStream</code> 125 * 126 * @param input InputStream containing a Window2 Record 127 */ read(InputStream input)128 public int read(InputStream input) throws IOException { 129 130 int numOfBytesRead = input.read(rwTop); 131 colLeft = (byte) input.read(); 132 numOfBytesRead++; 133 numOfBytesRead += input.read(grbit); 134 135 Debug.log(Debug.TRACE,"\trwTop : "+ EndianConverter.readShort(rwTop) + 136 " colLeft : " + colLeft + 137 " grbit : " + EndianConverter.readShort(grbit)); 138 return numOfBytesRead; 139 } 140 write(OutputStream output)141 public void write(OutputStream output) throws IOException { 142 143 output.write(getBiffType()); 144 output.write(rwTop); 145 output.write(colLeft); 146 output.write(grbit); 147 148 Debug.log(Debug.TRACE,"Writing Window2 record"); 149 } 150 } 151