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 
30 import org.openoffice.xmerge.util.Debug;
31 import org.openoffice.xmerge.util.EndianConverter;
32 import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants;
33 
34 
35 /**
36  * Represents a BIFF REcord that describes workbook window attributes
37  */
38 public class Window1 implements BIFFRecord {
39 
40     private byte[] grbit 	= new byte[2];
41     private byte[] itabCur	= new byte[2];		// index of selected worksheet
42 
43 	/**
44  	 * Constructor
45  	 */
Window1()46     public Window1() {
47 		grbit	= EndianConverter.writeShort((short) 0);
48 		itabCur	= EndianConverter.writeShort((short) 0);
49     }
50 
51    	/**
52  	 * Constructs a Window1 Record from an <code>InputStream</code>
53  	 *
54  	 * @param	is InputStream containing a Window1 Record
55  	 */
Window1(InputStream is)56     public Window1(InputStream is) throws IOException{
57 		read(is);
58     }
59 
60     /**
61 	 * Set the number of the active sheet
62 	 *
63 	 * @param activeSheet number of the active sheet
64 	 */
setActiveSheet(int activeSheet)65     public void setActiveSheet(int activeSheet) {
66         itabCur = EndianConverter.writeShort((short) activeSheet);
67     }
68 
69     /**
70 	 * Get the number of the active sheet
71 	 *
72 	 * @return 	 number of the active sheet
73 	 */
getActiveSheet()74     public int getActiveSheet() {
75         return EndianConverter.readShort(itabCur);
76     }
77 
78     /**
79 	 * Get the hex code for this particular <code>BIFFRecord</code>
80 	 *
81 	 * @return the hex code for <code>Window1</code>
82 	 */
getBiffType()83     public short getBiffType() {
84         return PocketExcelConstants.WINDOW_INFO;
85     }
86 
87    	/**
88  	 * Reads a Window1 Record from an <code>InputStream</code>
89  	 *
90  	 * @param	input InputStream containing a Window1 Record
91  	 */
read(InputStream input)92     public int read(InputStream input) throws IOException {
93 
94         int numOfBytesRead	= input.read(grbit);
95         numOfBytesRead		+= input.read(itabCur);
96 
97         Debug.log(Debug.TRACE,"\tgrbit : "+ EndianConverter.readShort(grbit) +
98                             " itabCur : " + EndianConverter.readShort(itabCur));
99 
100         return numOfBytesRead;
101     }
102 
write(OutputStream output)103     public void write(OutputStream output) throws IOException {
104 
105 		output.write(getBiffType());
106 		output.write(grbit);
107 		output.write(itabCur);
108 
109 		Debug.log(Debug.TRACE,"Writing Window1 record");
110     }
111 }
112