View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-Excel is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-Excel; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.office.excel.records.substructures;
22  
23  import org.millscript.office.excel.RecordTokenizer;
24  
25  /**
26   * 
27   */
28  public class CellAttributes {
29  
30      private boolean cellIsLocked;
31  
32      private boolean formulaIsHidden;
33  
34      private boolean hasLeftBlackBorder;
35  
36      private boolean hasRightBlackBorder;
37  
38      private boolean hasTopBlackBorder;
39  
40      private boolean hasBottomBlackBorder;
41  
42      private boolean hasShadedBlackBorder;
43  
44      private XF_HOR_ALIGN horizontalAlignment;
45  
46      private byte indexToFontRecord;
47  
48      private byte indexToFormatRecord;
49  
50      /**
51       * The index to the XF record for this cell. If this is <code>-1</code> it
52       * means that an <code>IXFE</code> record is required.
53       */
54      private byte indexToXFRecord;
55  
56      /**
57       * @param tokenizer
58       */
59      public CellAttributes( final RecordTokenizer tokenizer ) {
60          // Decode the cell protection and XF index
61          final byte cellProtectionAndXFIndex = tokenizer.readByte();
62          this.indexToXFRecord = (byte) ( cellProtectionAndXFIndex & 0x3F );
63          // Check if the index to the XF record is 0x3F(63) as this indicates it
64          // is "out of bounds" as the Cell Attributes can only contain indicies
65          // in the range 0-62.
66          if ( this.indexToXFRecord == 0x3F ) {
67              this.indexToXFRecord = -1;
68          }
69          this.cellIsLocked = ( 1 == ( cellProtectionAndXFIndex & 0x40 ) );
70          this.formulaIsHidden = ( 1 == ( cellProtectionAndXFIndex & 0x80 ) );
71          // Decord the FORMAT and FONT indicies
72          final byte formatAndFontIndicies = tokenizer.readByte();
73          this.indexToFormatRecord = (byte) ( formatAndFontIndicies & 0x3F );
74          this.indexToFontRecord = (byte) ( formatAndFontIndicies & 0xC0 );
75          // Decode the cell style
76          final byte cellStyle = tokenizer.readByte();
77          this.horizontalAlignment = XF_HOR_ALIGN.getXFHorAlign( cellStyle & 0x07 );
78          this.hasLeftBlackBorder = ( 1 == ( cellStyle & 0x08 ) );
79          this.hasRightBlackBorder = ( 1 == ( cellStyle & 0x10 ) );
80          this.hasTopBlackBorder = ( 1 == ( cellStyle & 0x20 ) );
81          this.hasBottomBlackBorder = ( 1 == ( cellStyle & 0x40 ) );
82          this.hasShadedBlackBorder = ( 1 == ( cellStyle & 0x80 ) );
83      }
84  
85      /**
86       * @return Returns the indexToXFRecord.
87       */
88      public byte getIndexToXFRecord() {
89          return indexToXFRecord;
90      }
91  
92  }