dmolony-DiskBrowser/src/com/bytezone/diskbrowser/visicalc/Cell.java

132 lines
2.8 KiB
Java
Raw Normal View History

2016-03-04 03:56:28 +00:00
package com.bytezone.diskbrowser.visicalc;
2016-03-09 10:38:53 +00:00
class Cell implements Comparable<Cell>, Value
2016-03-04 03:56:28 +00:00
{
2016-03-09 10:38:53 +00:00
// private static final Pattern cellContents =
// Pattern.compile ("([-+/*]?)(([A-Z]{1,2}[0-9]{1,3})|([0-9.]+)|(@[^-+/*]+))");
2016-03-04 03:56:28 +00:00
final Address address;
2016-03-06 08:05:32 +00:00
private final Sheet parent;
2016-03-04 03:56:28 +00:00
private String label;
2016-03-09 10:38:53 +00:00
// private double value;
// private String formulaText;
2016-03-07 12:16:11 +00:00
2016-03-05 21:53:29 +00:00
private char format = ' ';
2016-03-04 03:56:28 +00:00
private char repeatingChar;
private String repeat = "";
2016-03-09 10:38:53 +00:00
// private boolean valid;
private String expressionText;
private Expression expression;
2016-03-04 03:56:28 +00:00
2016-03-06 08:05:32 +00:00
public Cell (Sheet parent, Address address)
2016-03-04 03:56:28 +00:00
{
this.parent = parent;
this.address = address;
}
2016-03-08 09:39:35 +00:00
void format (String format)
{
// /FG - general
// /FD - default
// /FI - integer
// /F$ - dollars and cents
// /FL - left justified
// /FR - right justified
2016-03-10 02:39:23 +00:00
// /F* - graph (histogram)
2016-03-08 09:39:35 +00:00
if (format.startsWith ("/F"))
this.format = format.charAt (2);
else if (format.startsWith ("/-"))
{
repeatingChar = format.charAt (2);
for (int i = 0; i < 20; i++)
repeat += repeatingChar;
}
else
System.out.printf ("Unexpected format [%s]%n", format);
}
2016-03-04 05:27:14 +00:00
void doCommand (String command)
2016-03-04 03:56:28 +00:00
{
2016-03-04 05:27:14 +00:00
switch (command.charAt (0))
2016-03-04 03:56:28 +00:00
{
2016-03-04 05:27:14 +00:00
case '"':
label = command.substring (1);
break;
default:
2016-03-09 10:38:53 +00:00
expressionText = command;
2016-03-04 03:56:28 +00:00
}
2016-03-09 10:38:53 +00:00
// FUTURE.VC
if (address.sortValue == 67)
2016-03-10 02:39:23 +00:00
expressionText = "1000";
2016-03-09 10:38:53 +00:00
if (address.sortValue == 131)
2016-03-10 02:39:23 +00:00
expressionText = "10.5";
2016-03-09 10:38:53 +00:00
if (address.sortValue == 195)
expressionText = "12";
if (address.sortValue == 259)
2016-03-10 02:39:23 +00:00
expressionText = "8";
2016-03-04 03:56:28 +00:00
}
2016-03-04 05:27:14 +00:00
boolean hasValue ()
2016-03-04 03:56:28 +00:00
{
2016-03-09 10:38:53 +00:00
return expressionText != null;
2016-03-04 03:56:28 +00:00
}
2016-03-05 21:53:29 +00:00
char getFormat ()
{
return format;
}
2016-03-09 10:38:53 +00:00
String getText ()
2016-03-04 03:56:28 +00:00
{
2016-03-09 10:38:53 +00:00
if (label != null)
return label;
if (repeatingChar > 0)
return repeat;
return "bollocks";
}
2016-03-05 02:25:15 +00:00
2016-03-09 10:38:53 +00:00
@Override
public double getValue ()
{
if (expression == null)
2016-03-10 02:39:23 +00:00
{
System.out.printf ("%s Instantiating [%s]%n", address, expressionText);
2016-03-09 10:38:53 +00:00
expression = new Expression (parent, expressionText);
2016-03-10 02:39:23 +00:00
}
2016-03-09 10:38:53 +00:00
return expression.getValue ();
2016-03-10 02:39:23 +00:00
2016-03-08 09:39:35 +00:00
// [@IF(@ISERROR(BK24),0,BK24)]
// [@IF(D4=0,0,1)]
// [@IF(D4=0,0,B32+1)]
// [@IF(D4=0,0,1+(D3/100/D4)^D4-1*100)]
// [@SUM(C4...F4)]
// [+C4-@SUM(C5...C12)]
// [+D5/100/12]
// [.3*(B4+B7+B8+B9)]
// [+N12+(P12*(.2*K12+K9-O12))]
2016-03-04 03:56:28 +00:00
}
@Override
public String toString ()
{
2016-03-09 10:38:53 +00:00
String contents = "";
if (label != null)
contents = "Labl: " + label;
else if (repeatingChar != 0)
contents = "Rept: " + repeatingChar;
else if (expressionText != null)
contents = "Exp : " + expressionText;
return String.format ("[Cell:%5s %s]", address, contents);
2016-03-04 03:56:28 +00:00
}
@Override
2016-03-06 08:05:32 +00:00
public int compareTo (Cell o)
2016-03-04 03:56:28 +00:00
{
return address.compareTo (o.address);
}
}