home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Graphics;
-
- class Cell {
- public static final int VALUE = 0;
- public static final int LABEL = 1;
- public static final int URL = 2;
- public static final int FORMULA = 3;
- Node parseRoot;
- boolean needRedisplay;
- boolean selected = false;
- boolean transientValue = false;
- public int type;
- String valueString = "";
- String printString = "v";
- float value;
- Color bgColor;
- Color fgColor;
- Color highlightColor;
- int width;
- int height;
- SpreadSheet app;
- CellUpdater updaterThread;
- boolean paused = false;
-
- public Cell(SpreadSheet var1, Color var2, Color var3, Color var4, int var5, int var6) {
- this.app = var1;
- this.bgColor = var2;
- this.fgColor = var3;
- this.highlightColor = var4;
- this.width = var5;
- this.height = var6;
- this.needRedisplay = true;
- }
-
- public void setRawValue(float var1) {
- this.valueString = Float.toString(var1);
- this.value = var1;
- }
-
- public void setValue(float var1) {
- this.setRawValue(var1);
- this.printString = "v" + this.valueString;
- this.type = 0;
- this.paused = false;
- this.app.recalculate();
- this.needRedisplay = true;
- }
-
- public void setTransientValue(float var1) {
- this.transientValue = true;
- this.value = var1;
- this.needRedisplay = true;
- this.app.recalculate();
- }
-
- public void setUnparsedValue(String var1) {
- switch (var1.charAt(0)) {
- case 'f':
- this.setValue(3, var1.substring(1));
- return;
- case 'l':
- this.setValue(1, var1.substring(1));
- return;
- case 'u':
- this.setValue(2, var1.substring(1));
- return;
- case 'v':
- this.setValue(0, var1.substring(1));
- return;
- default:
- }
- }
-
- public String parseFormula(String var1, Node var2) {
- var1.length();
- if (var1 == null) {
- return null;
- } else {
- String var3 = this.parseValue(var1, var2);
- if (var3 != null && var3.length() != 0) {
- if (var3 == var1) {
- return var1;
- } else {
- char var7;
- switch (var7 = var3.charAt(0)) {
- case '\u0000':
- return null;
- case ')':
- return var3;
- case '*':
- case '+':
- case '-':
- case '/':
- String var4 = var3.substring(1);
- Node var6;
- var3 = this.parseValue(var4, var6 = new Node());
- if (var3 != var4) {
- Node var5 = new Node(var2);
- var2.left = var5;
- var2.right = var6;
- var2.op = var7;
- var2.type = 0;
- return var3;
- }
-
- return var1;
- default:
- return var1;
- }
- }
- } else {
- return null;
- }
- }
- }
-
- public String parseValue(String var1, Node var2) {
- char var3 = var1.charAt(0);
- String var5 = var1;
- if (var3 == '(') {
- var5 = var1.substring(1);
- String var4 = this.parseFormula(var5, var2);
- if (var4 == null || var4.length() == var5.length()) {
- return var1;
- }
-
- if (var4.charAt(0) != ')') {
- return var1;
- }
-
- var5 = var4;
- } else {
- if (var3 >= '0' && var3 <= '9') {
- int var16;
- for(var16 = 0; var16 < var1.length(); ++var16) {
- var3 = var1.charAt(var16);
- if ((var3 < '0' || var3 > '9') && var3 != '.') {
- break;
- }
- }
-
- float var6;
- try {
- var6 = Float.valueOf(var1.substring(0, var16));
- } catch (NumberFormatException var10) {
- return var1;
- }
-
- var2.type = 1;
- var2.value = var6;
- var5 = var1.substring(var16);
- return var5;
- }
-
- if (var3 >= 'A' && var3 <= 'Z') {
- int var8 = var3 - 65;
- var5 = var1.substring(1);
-
- int var9;
- for(var9 = 0; var9 < var5.length(); ++var9) {
- var3 = var5.charAt(var9);
- if (var3 < '0' || var3 > '9') {
- break;
- }
- }
-
- int var7 = Float.valueOf(var5.substring(0, var9)).intValue();
- var2.row = var7 - 1;
- var2.column = var8;
- var2.type = 2;
- if (var9 == var5.length()) {
- var5 = null;
- } else {
- var5 = var5.substring(var9);
- if (var5.charAt(0) == 0) {
- return null;
- }
- }
- }
- }
-
- return var5;
- }
-
- public void setValue(int var1, String var2) {
- this.paused = false;
- if (this.type == 2) {
- this.updaterThread.stop();
- this.updaterThread = null;
- }
-
- this.valueString = new String(var2);
- this.type = var1;
- this.needRedisplay = true;
- switch (var1) {
- case 0:
- this.setValue(Float.valueOf(var2));
- break;
- case 1:
- this.printString = "l" + this.valueString;
- break;
- case 2:
- this.printString = "u" + this.valueString;
- this.updaterThread = new CellUpdater(this);
- this.updaterThread.start();
- break;
- case 3:
- this.parseFormula(this.valueString, this.parseRoot = new Node());
- this.printString = "f" + this.valueString;
- }
-
- this.app.recalculate();
- }
-
- public String getValueString() {
- return this.valueString;
- }
-
- public String getPrintString() {
- return this.printString;
- }
-
- public void select() {
- this.selected = true;
- this.paused = true;
- }
-
- public void deselect() {
- this.selected = false;
- this.paused = false;
- this.needRedisplay = true;
- this.app.repaint();
- }
-
- public void paint(Graphics var1, int var2, int var3) {
- if (this.selected) {
- var1.setColor(this.highlightColor);
- } else {
- var1.setColor(this.bgColor);
- }
-
- var1.fillRect(var2, var3, this.width - 1, this.height);
- if (this.valueString != null) {
- switch (this.type) {
- case 0:
- case 1:
- var1.setColor(this.fgColor);
- break;
- case 2:
- var1.setColor(Color.blue);
- break;
- case 3:
- var1.setColor(Color.red);
- }
-
- if (this.transientValue) {
- var1.drawString("" + this.value, var2, var3 + this.height / 2 + 5);
- } else if (this.valueString.length() > 14) {
- var1.drawString(this.valueString.substring(0, 14), var2, var3 + this.height / 2 + 5);
- } else {
- var1.drawString(this.valueString, var2, var3 + this.height / 2 + 5);
- }
- }
-
- this.needRedisplay = false;
- }
- }
-