KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Stack JavaDoc;
23
24 import jxl.Sheet;
25 import jxl.biff.IntegerHelper;
26
27 /**
28  * A cell reference in a formula
29  */

30 class Parenthesis extends Operator implements ParsedThing
31 {
32   /**
33    * Constructor
34    */

35   public Parenthesis()
36   {
37   }
38
39   /**
40    * Reads the ptg data from the array starting at the specified position
41    *
42    * @param data the RPN array
43    * @param pos the current position in the array, excluding the ptg identifier
44    * @return the number of bytes read
45    */

46   public int read(byte[] data, int pos)
47   {
48     return 0;
49   }
50
51   /**
52    * Gets the operands for this operator from the stack
53    */

54   public void getOperands(Stack JavaDoc s)
55   {
56     ParseItem pi = (ParseItem) s.pop();
57
58     add(pi);
59   }
60
61   public void getString(StringBuffer JavaDoc buf)
62   {
63     ParseItem[] operands = getOperands();
64     buf.append('(');
65     operands[0].getString(buf);
66     buf.append(')');
67   }
68
69   /**
70    * Adjusts all the relative cell references in this formula by the
71    * amount specified. Used when copying formulas
72    *
73    * @param colAdjust the amount to add on to each relative cell reference
74    * @param rowAdjust the amount to add on to each relative row reference
75    */

76   public void adjustRelativeCellReferences(int colAdjust, int rowAdjust)
77   {
78     ParseItem[] operands = getOperands();
79     operands[0].adjustRelativeCellReferences(colAdjust, rowAdjust);
80   }
81
82   /**
83    * Called when a column is inserted on the specified sheet. Tells
84    * the formula parser to update all of its cell references beyond this
85    * column
86    *
87    * @param sheetIndex the sheet on which the column was inserted
88    * @param col the column number which was inserted
89    * @param currentSheet TRUE if this formula is on the sheet in which the
90    * column was inserted, FALSE otherwise
91    */

92   void columnInserted(int sheetIndex, int col, boolean currentSheet)
93   {
94     ParseItem[] operands = getOperands();
95     operands[0].columnInserted(sheetIndex, col, currentSheet);
96   }
97
98   /**
99    * Called when a column is inserted on the specified sheet. Tells
100    * the formula parser to update all of its cell references beyond this
101    * column
102    *
103    * @param sheetIndex the sheet on which the column was removed
104    * @param col the column number which was removed
105    * @param currentSheet TRUE if this formula is on the sheet in which the
106    * column was inserted, FALSE otherwise
107    */

108   void columnRemoved(int sheetIndex, int col, boolean currentSheet)
109   {
110     ParseItem[] operands = getOperands();
111     operands[0].columnRemoved(sheetIndex, col, currentSheet);
112   }
113
114   /**
115    * Called when a column is inserted on the specified sheet. Tells
116    * the formula parser to update all of its cell references beyond this
117    * column
118    *
119    * @param sheetIndex the sheet on which the row was inserted
120    * @param row the row number which was inserted
121    * @param currentSheet TRUE if this formula is on the sheet in which the
122    * column was inserted, FALSE otherwise
123    */

124   void rowInserted(int sheetIndex, int row, boolean currentSheet)
125   {
126     ParseItem[] operands = getOperands();
127     operands[0].rowInserted(sheetIndex, row, currentSheet);
128   }
129
130   /**
131    * Called when a column is inserted on the specified sheet. Tells
132    * the formula parser to update all of its cell references beyond this
133    * column
134    *
135    * @param sheetIndex the sheet on which the row was removed
136    * @param row the row number which was removed
137    * @param currentSheet TRUE if this formula is on the sheet in which the
138    * column was inserted, FALSE otherwise
139    */

140   void rowRemoved(int sheetIndex, int row, boolean currentSheet)
141   {
142     ParseItem[] operands = getOperands();
143     operands[0].rowRemoved(sheetIndex, row, currentSheet);
144   }
145
146   /**
147    * Abstract method which gets the token for this operator
148    *
149    * @return the string symbol for this token
150    */

151   Token getToken()
152   {
153     return Token.PARENTHESIS;
154   }
155
156   /**
157    * Gets the token representation of this item in RPN
158    *
159    * @return the bytes applicable to this formula
160    */

161   byte[] getBytes()
162   {
163     // Get the data for the operands
164
ParseItem[] operands = getOperands();
165     byte[] data = operands[0].getBytes();
166
167     // Add on the operator byte
168
byte[] newdata = new byte[data.length + 1];
169     System.arraycopy(data, 0, newdata, 0, data.length);
170     newdata[data.length] = getToken().getCode();
171
172     return newdata;
173   }
174
175   /**
176    * Gets the precedence for this operator. Operator precedents run from
177    * 1 to 5, one being the highest, 5 being the lowest
178    *
179    * @return the operator precedence
180    */

181   int getPrecedence()
182   {
183     return 4;
184   }
185 }
186
Popular Tags