mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-24 08:29:20 +00:00
tidying
This commit is contained in:
parent
f7e9854dc8
commit
eaf7449696
@ -22,7 +22,7 @@ public class VisicalcFile extends AbstractFile
|
||||
|
||||
text.append ("Visicalc : " + name + "\n");
|
||||
text.append ("Cells : " + sheet.size () + "\n\n");
|
||||
text.append (sheet.getCells ());
|
||||
text.append (sheet.getTextDisplay ());
|
||||
text.append ("\n\n");
|
||||
text.append (sheet.getLines ());
|
||||
|
||||
|
@ -8,15 +8,21 @@ class Cell implements Comparable<Cell>, Value
|
||||
|
||||
final Address address;
|
||||
private final Sheet parent;
|
||||
|
||||
private CellType type;
|
||||
private char format = ' ';
|
||||
|
||||
private char repeatingChar;
|
||||
private String repeat = "";
|
||||
|
||||
private String label;
|
||||
|
||||
private String expressionText;
|
||||
private Value value;
|
||||
// private boolean hasValue;
|
||||
|
||||
enum CellType
|
||||
{
|
||||
LABEL, REPEATING_CHARACTER, VALUE
|
||||
}
|
||||
|
||||
public Cell (Sheet parent, Address address)
|
||||
{
|
||||
@ -41,6 +47,7 @@ class Cell implements Comparable<Cell>, Value
|
||||
repeatingChar = format.charAt (2);
|
||||
for (int i = 0; i < 20; i++)
|
||||
repeat += repeatingChar;
|
||||
type = CellType.REPEATING_CHARACTER;
|
||||
}
|
||||
else
|
||||
System.out.printf ("Unexpected format [%s]%n", format);
|
||||
@ -48,14 +55,15 @@ class Cell implements Comparable<Cell>, Value
|
||||
|
||||
void setValue (String command)
|
||||
{
|
||||
switch (command.charAt (0))
|
||||
if (command.charAt (0) == '"')
|
||||
{
|
||||
case '"':
|
||||
label = command.substring (1);
|
||||
break;
|
||||
|
||||
default:
|
||||
type = CellType.LABEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
expressionText = command;
|
||||
type = CellType.VALUE;
|
||||
}
|
||||
|
||||
// FUTURE.VC
|
||||
@ -96,13 +104,24 @@ class Cell implements Comparable<Cell>, Value
|
||||
expressionText = "D9*G5/(1-((1+G5)^-D4))";
|
||||
}
|
||||
|
||||
char getFormat ()
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
String getText (int colWidth, char defaultFormat)
|
||||
{
|
||||
// cell may have been formatted but no value set
|
||||
if (type == null)
|
||||
{
|
||||
System.out.println (this);
|
||||
return justify ("", colWidth);
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LABEL:
|
||||
return justify (label, colWidth);
|
||||
|
||||
case REPEATING_CHARACTER:
|
||||
return justify (repeat, colWidth);
|
||||
|
||||
case VALUE:
|
||||
if (hasValue ())
|
||||
if (format == 'I')
|
||||
{
|
||||
@ -117,6 +136,7 @@ class Cell implements Comparable<Cell>, Value
|
||||
else if (format == '*')
|
||||
{
|
||||
String graphFormat = String.format ("%%-%d.%ds", colWidth, colWidth);
|
||||
// this is not finished
|
||||
return String.format (graphFormat, "********************");
|
||||
}
|
||||
else
|
||||
@ -132,26 +152,21 @@ class Cell implements Comparable<Cell>, Value
|
||||
val = val.substring (val.length () - colWidth);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return getError ();
|
||||
}
|
||||
|
||||
String text;
|
||||
if (label != null)
|
||||
text = label;
|
||||
else if (repeatingChar > 0)
|
||||
text = repeat;
|
||||
else
|
||||
text = "?";
|
||||
|
||||
private String justify (String text, int colWidth)
|
||||
{
|
||||
if (format == 'R')
|
||||
{
|
||||
String labelFormat = String.format ("%%%d.%ds", colWidth, colWidth);
|
||||
return (String.format (labelFormat, text));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
String labelFormat = String.format ("%%-%d.%ds", colWidth, colWidth);
|
||||
return (String.format (labelFormat, text));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValue ()
|
||||
@ -197,12 +212,20 @@ class Cell implements Comparable<Cell>, Value
|
||||
public String toString ()
|
||||
{
|
||||
String contents = "";
|
||||
if (label != null)
|
||||
if (type != null)
|
||||
switch (type)
|
||||
{
|
||||
case LABEL:
|
||||
contents = "Labl: " + label;
|
||||
else if (repeatingChar != 0)
|
||||
break;
|
||||
case REPEATING_CHARACTER:
|
||||
contents = "Rept: " + repeatingChar;
|
||||
else if (expressionText != null)
|
||||
break;
|
||||
case VALUE:
|
||||
contents = "Exp : " + expressionText;
|
||||
break;
|
||||
}
|
||||
|
||||
return String.format ("[Cell:%5s %s]", address, contents);
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ public class Sheet implements Iterable<Cell>
|
||||
ptr += length + 1; // +1 for end-of-line token
|
||||
}
|
||||
|
||||
if (true)
|
||||
if (false)
|
||||
{
|
||||
System.out.println ();
|
||||
System.out.println ("Lines:");
|
||||
@ -286,7 +286,7 @@ public class Sheet implements Iterable<Cell>
|
||||
if (!line.isEmpty ())
|
||||
currentCell.setValue (line); // expression
|
||||
|
||||
if (true)
|
||||
if (false)
|
||||
System.out.printf ("[%s][%-3s][%s]%n", currentCell.address, format, line);
|
||||
}
|
||||
|
||||
@ -332,7 +332,7 @@ public class Sheet implements Iterable<Cell>
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
public String getCells ()
|
||||
public String getTextDisplay ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
String longLine;
|
||||
|
Loading…
Reference in New Issue
Block a user