001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Title: Window Protect Record<P>
024: * Description: flags whether workbook windows are protected<P>
025: * REFERENCE: PG 424 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
026: * @author Andrew C. Oliver (acoliver at apache dot org)
027: * @version 2.0-pre
028: */
029:
030: public class WindowProtectRecord extends Record {
031: public final static short sid = 0x19;
032: private short field_1_protect;
033:
034: public WindowProtectRecord() {
035: }
036:
037: /**
038: * Constructs a WindowProtect record and sets its fields appropriately.
039: * @param in the RecordInputstream to read the record from
040: */
041:
042: public WindowProtectRecord(RecordInputStream in) {
043: super (in);
044: }
045:
046: protected void validateSid(short id) {
047: if (id != sid) {
048: throw new RecordFormatException(
049: "NOT A WINDOWPROTECT RECORD");
050: }
051: }
052:
053: protected void fillFields(RecordInputStream in) {
054: field_1_protect = in.readShort();
055: }
056:
057: /**
058: * set whether this window should be protected or not
059: * @param protect or not
060: */
061:
062: public void setProtect(boolean protect) {
063: if (protect == true) {
064: field_1_protect = 1;
065: } else {
066: field_1_protect = 0;
067: }
068: }
069:
070: /**
071: * is this window protected or not
072: *
073: * @return protected or not
074: */
075:
076: public boolean getProtect() {
077: return (field_1_protect == 1);
078: }
079:
080: public String toString() {
081: StringBuffer buffer = new StringBuffer();
082:
083: buffer.append("[WINDOWPROTECT]\n");
084: buffer.append(" .protect = ").append(getProtect())
085: .append("\n");
086: buffer.append("[/WINDOWPROTECT]\n");
087: return buffer.toString();
088: }
089:
090: public int serialize(int offset, byte[] data) {
091: LittleEndian.putShort(data, 0 + offset, sid);
092: LittleEndian.putShort(data, 2 + offset, ((short) 0x02)); // 2 bytes (6 total)
093: LittleEndian.putShort(data, 4 + offset, field_1_protect);
094: return getRecordSize();
095: }
096:
097: public int getRecordSize() {
098: return 6;
099: }
100:
101: public short getSid() {
102: return sid;
103: }
104: }
|