1 /*
2 * GeoVISTA Center (Penn State, Dept. of Geography)
3 * Copyright (c), 1999 - 2002, GeoVISTA Center
4 * All Rights Researved.
5 *
6 * Description:
7 * Node is basic unit for Formula processing.
8 * <p>
9 * It can be one of the following:
10 * <ol>
11 * <li>Relative Address (LETTERS+numbers: A1)</li>
12 * <li>Absolute Address ($LETTERS$numbers: $A$1)</li>
13 * <li>functions.Function (LETTERS)</li>
14 * <li>Left Parenthese</li>
15 * <li>Right Parenthese</li>
16 * <li>Number (a float number)</li>
17 * <li>Operator (+ - * / % ^)</li>
18 * <li>Comma (separating parameters)</li>
19 * <li>Colon (used in range addresses: A1:C6)</li>
20 * </ol>
21 *
22 * The code has some reference to code written by Hua Zhong from Columbia University
23 * Apr 2, 2003
24 * Time: 10:42:12 PM
25 * @author Jin Chen
26 */
27
28
29 package edu.psu.geovista.app.spreadsheet.formula;
30
31 import edu.psu.geovista.app.spreadsheet.table.SSTableModel;
32
33 import java.io.*;
34 import java.util.*;
35 import java.awt.*;
36
37
38 public class Node {
39 /*** Based on tool ***/
40 //public static int baseRow = 0;
41 //public static int baseCol = 1; //replace SharpTools.baseCol
42
43
44
45 public static final int DEFAULT = 0; // reserved
46 public static final int REL_ADDR = 1; // LETTERS+numbers: A1
47 public static final int ABS_ADDR = 2; // $LETTERS$numbers: $A$1
48 public static final int FUNCTION = 3; // LETTERS: SUM
49 public static final int LPAREN = 4; // (
50 public static final int RPAREN = 5; // )
51 public static final int NUMBER = 6; // all numbers and has .: 0.5
52 public static final int OPERATOR = 7; // + - * / ^
53 public static final int COMMA = 8; // ,
54 public static final int COLON = 9; // :
55 public static final int EXP = 10; // an expression. the exp field counts.
56 // for each function param, its type is EXP
57
58 private static final String[] desc = {
59 "Default", "Rel_Addr", "Abs_Addr", "edu.psu.geovista.app.spreadsheet.functions.Function",
60 "LBracket", "RBracket", "Number", "Operator",
61 "Comma", "Colon", "Param" };
62
63 private int type; // which type the node is (see above 10 types)
64 private String data; // the raw data. Jin: the expression
65 private float number; // the numeric value. Jin: the value
66 private int row;
67 private int col;
68
69 private LinkedList exp; // a LinkedList for a function's params
70
71 /*
72 * Used for edu.psu.geovista.app.spreadsheet.functions.Function address range parameter (ADDR1:ADDR2)
73 * An address range is ultimately represented as follows:
74 *
75 * node type: COLON
76 * node.nextRange points to the start address (a node of REL_ADDR or
77 * ABS_ADDR), the start address' nextRange points to the end address.
78 */
79 private Node nextRange;
80
81 private boolean pending; // used for processing functions, see edu.psu.geovista.app.spreadsheet.formula.Formula
82
83
84 //Jin
85 private Cell reference;//Only used by Relative or Absolute address node, store the cell the address refer to
86 private Point address;//Store absolute address
87
88 /***
89 * This is an empty node constructor
90 */
91 Node() {
92 }
93
94 /***
95 * edu.psu.geovista.app.spreadsheet.formula.Node constructor
96 *
97 * @param node
98 */
99 Node(Node node) {
100 type = node.type;
101 if (data != null)
102 data = new String(node.data);
103 number = node.number;
104 row = node.row;
105 col = node.col;
106 }
107 /***
108 * For relative address
109 */
110 public Cell getReference() {
111 return reference;//edu.psu.geovista.app.spreadsheet.formula.Cell object
112 }
113 public void setReference(Cell reference) {
114 this.reference = reference;
115 setType(Node.REL_ADDR);
116 this.address =null; //absolute address
117 }
118
119 /***
120 * For absolute address
121 */
122 public Point getAddress(){
123 return this.address ;
124 }
125
126 public void setAddress(Point address) {
127 this.address = address;
128 setType(Node.ABS_ADDR );
129 this.reference =null;
130 }
131 public void setAddress(int x, int y) {
132 this.setAddress(new Point(x,y));
133 }
134
135 /*** get/set edu.psu.geovista.app.spreadsheet.functions */
136 public int getType() { return type; }
137 public void setType(int type) {
138 this.type = type;
139 }
140 public boolean isType(int type) { return this.type == type; }
141
142 public float getNumber() { return number; }
143 public String getData() { return data; }
144
145 public LinkedList getParams() { return exp; }
146 public Node getNextRange() { return nextRange; }
147 //Return the parameters
148 public LinkedList getExp() { return exp; }
149
150 //public int getRow() { return row; }
151 //public int getCol() { return col; }
152
153
154 public void setNumber(float number) { this.number = number; }
155
156 public void setData(String data) { this.data = data; }
157 public void appendData(char data) { this.data += data; }
158 public void appendData(String data) { this.data += data; }
159
160 public void setParams(LinkedList list) { exp = list; }
161 public void addParam(Node node) {
162 if (node.getExp().size()>0)
163 exp.add(node);
164 }
165
166 public void setNextRange(Node node) { nextRange = node; }
167 public void setExp(LinkedList exp) { this.exp = exp; }
168
169 public void setPending(boolean pending) { this.pending = pending; }
170 public boolean isPending() { return pending; }
171
172
173
174
175 }
This page was automatically generated by Maven