KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > formula > ParseItem


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff.formula;
21
22 import jxl.Sheet;
23
24 /**
25  * Abstract base class for an item in a formula parse tree
26  */

27 abstract class ParseItem
28 {
29   /**
30    * The parent of this parse item
31    */

32   private ParseItem parent;
33
34   /**
35    * Volatile flag
36    */

37   private boolean volatileFunction;
38
39   /**
40    * Indicates that the alternative token code should be used
41    */

42   private boolean alternateCode;
43
44   /**
45    * Constructor
46    */

47   public ParseItem()
48   {
49     volatileFunction = false;
50     alternateCode = false;
51   }
52
53   /**
54    * Called by this class to initialize the parent
55    */

56   protected void setParent(ParseItem p)
57   {
58     parent = p;
59   }
60
61   /**
62    * Sets the volatile flag and ripples all the way up the parse tree
63    */

64   protected void setVolatile()
65   {
66     volatileFunction = true;
67     if (parent != null && !parent.isVolatile())
68     {
69       parent.setVolatile();
70     }
71   }
72
73   /**
74    * Accessor for the volatile function
75    *
76    * @return TRUE if the formula is volatile, FALSE otherwise
77    */

78   final boolean isVolatile()
79   {
80     return volatileFunction;
81   }
82
83   /**
84    * Gets the string representation of this item
85    * @param ws the workbook settings
86    */

87   abstract void getString(StringBuffer JavaDoc buf);
88
89   /**
90    * Gets the token representation of this item in RPN
91    *
92    * @return the bytes applicable to this formula
93    */

94   abstract byte[] getBytes();
95
96   /**
97    * Adjusts all the relative cell references in this formula by the
98    * amount specified. Used when copying formulas
99    *
100    * @param colAdjust the amount to add on to each relative cell reference
101    * @param rowAdjust the amount to add on to each relative row reference
102    */

103   abstract void adjustRelativeCellReferences(int colAdjust, int rowAdjust);
104
105   /**
106    * Called when a column is inserted on the specified sheet. Tells
107    * the formula parser to update all of its cell references beyond this
108    * column
109    *
110    * @param sheetIndex the sheet on which the column was inserted
111    * @param col the column number which was inserted
112    * @param currentSheet TRUE if this formula is on the sheet in which the
113    * column was inserted, FALSE otherwise
114    */

115   abstract void columnInserted(int sheetIndex, int col, boolean currentSheet);
116
117   /**
118    * Called when a column is inserted on the specified sheet. Tells
119    * the formula parser to update all of its cell references beyond this
120    * column
121    *
122    * @param sheetIndex the sheet on which the column was removed
123    * @param col the column number which was removed
124    * @param currentSheet TRUE if this formula is on the sheet in which the
125    * column was inserted, FALSE otherwise
126    */

127   abstract void columnRemoved(int sheetIndex, int col, boolean currentSheet);
128
129   /**
130    * Called when a column is inserted on the specified sheet. Tells
131    * the formula parser to update all of its cell references beyond this
132    * column
133    *
134    * @param sheetIndex the sheet on which the row was inserted
135    * @param row the row number which was inserted
136    * @param currentSheet TRUE if this formula is on the sheet in which the
137    * column was inserted, FALSE otherwise
138    */

139   abstract void rowInserted(int sheetIndex, int row, boolean currentSheet);
140
141   /**
142    * Called when a column is inserted on the specified sheet. Tells
143    * the formula parser to update all of its cell references beyond this
144    * column
145    *
146    * @param sheetIndex the sheet on which the row was removed
147    * @param row the row number which was removed
148    * @param currentSheet TRUE if this formula is on the sheet in which the
149    * column was inserted, FALSE otherwise
150    */

151   abstract void rowRemoved(int sheetIndex, int row, boolean currentSheet);
152
153   /**
154    * Tells the operands to use the alternate code
155    */

156   protected void setAlternateCode()
157   {
158     alternateCode = true;
159   }
160
161   /**
162    * Accessor for the alternate code flag
163    *
164    * @return TRUE to use the alternate code, FALSE otherwise
165    */

166   protected final boolean useAlternateCode()
167   {
168     return alternateCode;
169   }
170 }
171
172
173
174
Popular Tags