1 ////////////////////////////////////////////////////////////////////////////////
2 // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3 // Copyright (C) 2005 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;
22
23 import org.millscript.office.excel.RecordParser;
24 import org.millscript.office.excel.alerts.BIFFAlert;
25 import org.millscript.office.spreadsheet.cells.BooleanCell;
26 import org.millscript.office.spreadsheet.cells.ErrorCell;
27 import org.millscript.office.spreadsheet.formula.Error;
28
29 /**
30 *
31 */
32 public class BoolErr extends AbstractCellRecord {
33
34 /**
35 *
36 */
37 public enum BoolErrType {
38
39 BooleanValue, ErrorCode;
40
41 public static BoolErrType getBoolErrType( final byte type ) {
42 switch ( type ) {
43 case 0x00:
44 return BooleanValue;
45 case 0x01:
46 return ErrorCode;
47 default:
48 throw new BIFFAlert(
49 "Unknown type for BOOLERR record"
50 ).culprit( "type", type ).mishap();
51 }
52 }
53
54 }
55
56 private BoolErrType type;
57
58 private byte value;
59
60 /**
61 * @param row
62 * @param col
63 * @param xf
64 */
65 public BoolErr( final int row, final int col, final int xf ) {
66 super( row, col, xf );
67 }
68
69 /**
70 * @see org.millscript.office.excel.Record#handle(org.millscript.office.excel.RecordParser)
71 */
72 @Override
73 public void handle( final RecordParser recordParser ) {
74 switch ( this.type ) {
75 case BooleanValue:
76 // Set the cell contents, to be a boolean cell
77 recordParser.getCurrentWorksheet().insertCell(
78 this.getIndexToRow() + 1,
79 this.getIndexToColumn() + 1,
80 new BooleanCell(
81 this.value == 0 ? Boolean.FALSE
82 : Boolean.TRUE
83 )
84 );
85 break;
86 case ErrorCode:
87 // Set the cell contents, to be an error cell
88 recordParser.getCurrentWorksheet().insertCell(
89 this.getIndexToRow() + 1,
90 this.getIndexToColumn() + 1,
91 new ErrorCell(
92 Error.getError( this.value )
93 )
94 );
95 break;
96 default:
97 break;
98 }
99 }
100
101 /**
102 * @param t The type to set.
103 */
104 public void setType( final BoolErrType t ) {
105 this.type = t;
106 }
107
108 /**
109 * @param v The value to set.
110 */
111 public void setValue( final byte v ) {
112 this.value = v;
113 }
114
115 }