home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / WDESAMPL.BIN / Cell.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-06  |  4.7 KB  |  269 lines

  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3.  
  4. class Cell {
  5.    public static final int VALUE = 0;
  6.    public static final int LABEL = 1;
  7.    public static final int URL = 2;
  8.    public static final int FORMULA = 3;
  9.    Node parseRoot;
  10.    boolean needRedisplay;
  11.    boolean selected = false;
  12.    boolean transientValue = false;
  13.    public int type;
  14.    String valueString = "";
  15.    String printString = "v";
  16.    float value;
  17.    Color bgColor;
  18.    Color fgColor;
  19.    Color highlightColor;
  20.    int width;
  21.    int height;
  22.    SpreadSheet app;
  23.    CellUpdater updaterThread;
  24.    boolean paused = false;
  25.  
  26.    public Cell(SpreadSheet var1, Color var2, Color var3, Color var4, int var5, int var6) {
  27.       this.app = var1;
  28.       this.bgColor = var2;
  29.       this.fgColor = var3;
  30.       this.highlightColor = var4;
  31.       this.width = var5;
  32.       this.height = var6;
  33.       this.needRedisplay = true;
  34.    }
  35.  
  36.    public void setRawValue(float var1) {
  37.       this.valueString = Float.toString(var1);
  38.       this.value = var1;
  39.    }
  40.  
  41.    public void setValue(float var1) {
  42.       this.setRawValue(var1);
  43.       this.printString = "v" + this.valueString;
  44.       this.type = 0;
  45.       this.paused = false;
  46.       this.app.recalculate();
  47.       this.needRedisplay = true;
  48.    }
  49.  
  50.    public void setTransientValue(float var1) {
  51.       this.transientValue = true;
  52.       this.value = var1;
  53.       this.needRedisplay = true;
  54.       this.app.recalculate();
  55.    }
  56.  
  57.    public void setUnparsedValue(String var1) {
  58.       switch (var1.charAt(0)) {
  59.          case 'f':
  60.             this.setValue(3, var1.substring(1));
  61.             return;
  62.          case 'l':
  63.             this.setValue(1, var1.substring(1));
  64.             return;
  65.          case 'u':
  66.             this.setValue(2, var1.substring(1));
  67.             return;
  68.          case 'v':
  69.             this.setValue(0, var1.substring(1));
  70.             return;
  71.          default:
  72.       }
  73.    }
  74.  
  75.    public String parseFormula(String var1, Node var2) {
  76.       var1.length();
  77.       if (var1 == null) {
  78.          return null;
  79.       } else {
  80.          String var3 = this.parseValue(var1, var2);
  81.          if (var3 != null && var3.length() != 0) {
  82.             if (var3 == var1) {
  83.                return var1;
  84.             } else {
  85.                char var7;
  86.                switch (var7 = var3.charAt(0)) {
  87.                   case '\u0000':
  88.                      return null;
  89.                   case ')':
  90.                      return var3;
  91.                   case '*':
  92.                   case '+':
  93.                   case '-':
  94.                   case '/':
  95.                      String var4 = var3.substring(1);
  96.                      Node var6;
  97.                      var3 = this.parseValue(var4, var6 = new Node());
  98.                      if (var3 != var4) {
  99.                         Node var5 = new Node(var2);
  100.                         var2.left = var5;
  101.                         var2.right = var6;
  102.                         var2.op = var7;
  103.                         var2.type = 0;
  104.                         return var3;
  105.                      }
  106.  
  107.                      return var1;
  108.                   default:
  109.                      return var1;
  110.                }
  111.             }
  112.          } else {
  113.             return null;
  114.          }
  115.       }
  116.    }
  117.  
  118.    public String parseValue(String var1, Node var2) {
  119.       char var3 = var1.charAt(0);
  120.       String var5 = var1;
  121.       if (var3 == '(') {
  122.          var5 = var1.substring(1);
  123.          String var4 = this.parseFormula(var5, var2);
  124.          if (var4 == null || var4.length() == var5.length()) {
  125.             return var1;
  126.          }
  127.  
  128.          if (var4.charAt(0) != ')') {
  129.             return var1;
  130.          }
  131.  
  132.          var5 = var4;
  133.       } else {
  134.          if (var3 >= '0' && var3 <= '9') {
  135.             int var16;
  136.             for(var16 = 0; var16 < var1.length(); ++var16) {
  137.                var3 = var1.charAt(var16);
  138.                if ((var3 < '0' || var3 > '9') && var3 != '.') {
  139.                   break;
  140.                }
  141.             }
  142.  
  143.             float var6;
  144.             try {
  145.                var6 = Float.valueOf(var1.substring(0, var16));
  146.             } catch (NumberFormatException var10) {
  147.                return var1;
  148.             }
  149.  
  150.             var2.type = 1;
  151.             var2.value = var6;
  152.             var5 = var1.substring(var16);
  153.             return var5;
  154.          }
  155.  
  156.          if (var3 >= 'A' && var3 <= 'Z') {
  157.             int var8 = var3 - 65;
  158.             var5 = var1.substring(1);
  159.  
  160.             int var9;
  161.             for(var9 = 0; var9 < var5.length(); ++var9) {
  162.                var3 = var5.charAt(var9);
  163.                if (var3 < '0' || var3 > '9') {
  164.                   break;
  165.                }
  166.             }
  167.  
  168.             int var7 = Float.valueOf(var5.substring(0, var9)).intValue();
  169.             var2.row = var7 - 1;
  170.             var2.column = var8;
  171.             var2.type = 2;
  172.             if (var9 == var5.length()) {
  173.                var5 = null;
  174.             } else {
  175.                var5 = var5.substring(var9);
  176.                if (var5.charAt(0) == 0) {
  177.                   return null;
  178.                }
  179.             }
  180.          }
  181.       }
  182.  
  183.       return var5;
  184.    }
  185.  
  186.    public void setValue(int var1, String var2) {
  187.       this.paused = false;
  188.       if (this.type == 2) {
  189.          this.updaterThread.stop();
  190.          this.updaterThread = null;
  191.       }
  192.  
  193.       this.valueString = new String(var2);
  194.       this.type = var1;
  195.       this.needRedisplay = true;
  196.       switch (var1) {
  197.          case 0:
  198.             this.setValue(Float.valueOf(var2));
  199.             break;
  200.          case 1:
  201.             this.printString = "l" + this.valueString;
  202.             break;
  203.          case 2:
  204.             this.printString = "u" + this.valueString;
  205.             this.updaterThread = new CellUpdater(this);
  206.             this.updaterThread.start();
  207.             break;
  208.          case 3:
  209.             this.parseFormula(this.valueString, this.parseRoot = new Node());
  210.             this.printString = "f" + this.valueString;
  211.       }
  212.  
  213.       this.app.recalculate();
  214.    }
  215.  
  216.    public String getValueString() {
  217.       return this.valueString;
  218.    }
  219.  
  220.    public String getPrintString() {
  221.       return this.printString;
  222.    }
  223.  
  224.    public void select() {
  225.       this.selected = true;
  226.       this.paused = true;
  227.    }
  228.  
  229.    public void deselect() {
  230.       this.selected = false;
  231.       this.paused = false;
  232.       this.needRedisplay = true;
  233.       this.app.repaint();
  234.    }
  235.  
  236.    public void paint(Graphics var1, int var2, int var3) {
  237.       if (this.selected) {
  238.          var1.setColor(this.highlightColor);
  239.       } else {
  240.          var1.setColor(this.bgColor);
  241.       }
  242.  
  243.       var1.fillRect(var2, var3, this.width - 1, this.height);
  244.       if (this.valueString != null) {
  245.          switch (this.type) {
  246.             case 0:
  247.             case 1:
  248.                var1.setColor(this.fgColor);
  249.                break;
  250.             case 2:
  251.                var1.setColor(Color.blue);
  252.                break;
  253.             case 3:
  254.                var1.setColor(Color.red);
  255.          }
  256.  
  257.          if (this.transientValue) {
  258.             var1.drawString("" + this.value, var2, var3 + this.height / 2 + 5);
  259.          } else if (this.valueString.length() > 14) {
  260.             var1.drawString(this.valueString.substring(0, 14), var2, var3 + this.height / 2 + 5);
  261.          } else {
  262.             var1.drawString(this.valueString, var2, var3 + this.height / 2 + 5);
  263.          }
  264.       }
  265.  
  266.       this.needRedisplay = false;
  267.    }
  268. }
  269.