mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-01 03:41:29 +00:00
tidying
This commit is contained in:
parent
eaf7449696
commit
9e72f55cbf
|
@ -106,12 +106,9 @@ class Cell implements Comparable<Cell>, Value
|
|||
|
||||
String getText (int colWidth, char defaultFormat)
|
||||
{
|
||||
// cell may have been formatted but no value set
|
||||
// cell may have been created when formatted but no type set
|
||||
if (type == null)
|
||||
{
|
||||
System.out.println (this);
|
||||
return justify ("", colWidth);
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
@ -171,12 +168,13 @@ class Cell implements Comparable<Cell>, Value
|
|||
@Override
|
||||
public boolean hasValue ()
|
||||
{
|
||||
if (label != null || repeatingChar > 0)
|
||||
return false;
|
||||
|
||||
if (value == null)
|
||||
createValue ();
|
||||
return value.hasValue ();
|
||||
if (type == CellType.VALUE)
|
||||
{
|
||||
if (value == null)
|
||||
createValue ();
|
||||
return value.hasValue ();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// this should be called when doing calculations
|
||||
|
@ -211,7 +209,7 @@ class Cell implements Comparable<Cell>, Value
|
|||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
String contents = "";
|
||||
String contents = "<empty>";
|
||||
if (type != null)
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -34,9 +34,10 @@ class Expression implements Value
|
|||
|
||||
private boolean hasValue;
|
||||
|
||||
public Expression (Sheet parent, String input)
|
||||
public Expression (Sheet parent, String text)
|
||||
{
|
||||
String line = checkBrackets (input);
|
||||
String line = checkBrackets (text);
|
||||
// System.out.printf ("Exp[%s]%n", line);
|
||||
|
||||
int ptr = 0;
|
||||
while (ptr < line.length ())
|
||||
|
@ -187,7 +188,7 @@ class Expression implements Value
|
|||
{
|
||||
int ptr = text.indexOf ('('); // find first left parenthesis
|
||||
if (ptr < 0)
|
||||
return "";
|
||||
return text;
|
||||
int depth = 1;
|
||||
|
||||
while (++ptr < text.length ()) // find matching right parenthesis
|
||||
|
|
|
@ -30,9 +30,9 @@ abstract class Function implements Value
|
|||
.compile ("\\(([A-B]?[A-Z])([0-9]{1,3})\\.\\.\\.([A-B]?[A-Z])([0-9]{1,3})\\)?");
|
||||
private static final Pattern addressList = Pattern.compile ("\\(([^,]+(,[^,]+)*)\\)");
|
||||
|
||||
Sheet parent;
|
||||
String functionText;
|
||||
boolean hasValue;
|
||||
protected final Sheet parent;
|
||||
protected String functionText;
|
||||
protected boolean hasValue;
|
||||
|
||||
static Function getInstance (Sheet parent, String text)
|
||||
{
|
||||
|
@ -66,7 +66,10 @@ abstract class Function implements Value
|
|||
if (text.startsWith ("@ERROR("))
|
||||
return new Error (parent, text);
|
||||
|
||||
System.out.printf ("Unknown function: %s%n", text);
|
||||
if (text.equals ("@NA"))
|
||||
return new Error (parent, text);
|
||||
|
||||
System.out.printf ("Unknown function: [%s]%n", text);
|
||||
return new Error (parent, "@ERROR()");
|
||||
}
|
||||
|
||||
|
@ -76,7 +79,8 @@ abstract class Function implements Value
|
|||
|
||||
// get function's parameter string
|
||||
int pos = text.indexOf ('(');
|
||||
this.functionText = text.substring (pos + 1, text.length () - 1);
|
||||
if (pos >= 0)
|
||||
this.functionText = text.substring (pos + 1, text.length () - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,4 +36,10 @@ class If extends Function
|
|||
return expFalse.getValue ();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return String.format ("[IF:%s, True:%s, False:%s]", condition, textTrue, textFalse);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -24,8 +23,8 @@ public class Sheet implements Iterable<Cell>
|
|||
|
||||
private final Map<Integer, Integer> columnWidths = new TreeMap<Integer, Integer> ();
|
||||
private int columnWidth = 12;
|
||||
private char recalculation = ' ';
|
||||
private char recalculationOrder = ' ';
|
||||
private char recalculation = ' '; // auto/manual
|
||||
private char recalculationOrder = ' '; // row/column
|
||||
private int columns;
|
||||
private int rows;
|
||||
|
||||
|
@ -82,26 +81,23 @@ public class Sheet implements Iterable<Cell>
|
|||
|
||||
/C CLEARS THE SHEET, SETTING ALL ENTRIES TO BLANK
|
||||
|
||||
/D DELETES THE ROW(/DR) OR COLUMN(/DC) ON WHICH THE CURSOR
|
||||
LIES.
|
||||
/D DELETE
|
||||
/DR THE ROW
|
||||
/DC COLUMN ON WHICH THE CURSOR LIES
|
||||
|
||||
/E ALLOWS EDITING OF THE ENTRY CONTENTS OF ANY ENTRY POSITION
|
||||
BY REDISPLAYING IT ON THE EDIT LINE. USE <- -> KEYS & ESC.
|
||||
|
||||
/F SETS THE DISPLAY FORMAT OF AN ENTRY TO ONE OF THE FOLLOWING
|
||||
FORMATS:
|
||||
|
||||
/F FORMATS:
|
||||
/FG GENERAL
|
||||
|
||||
/FI INTEGER
|
||||
/F$ DOLLAR AND CENTS
|
||||
/FL LEFT JUSTIFIED
|
||||
/FR RIGHT JUSTIFIED
|
||||
/F* GRAPH
|
||||
/FD DEFAULT
|
||||
/FI INTEGER
|
||||
/F$ DOLLAR AND CENTS
|
||||
/FL LEFT JUSTIFIED
|
||||
/FR RIGHT JUSTIFIED
|
||||
/F* GRAPH
|
||||
/FD DEFAULT
|
||||
|
||||
/G GLOBAL COMMANDS. THESE APPLY TO THE ENTIRE SHEET OR WINDOW.
|
||||
|
||||
/GC SETS COLUMN WIDTH
|
||||
/GF SETS THE GLOBAL DEFAULT FORMAT
|
||||
/GO SETS THE ORDER OF RECALCULATION TO BE DOWN THE
|
||||
|
@ -112,20 +108,22 @@ public class Sheet implements Iterable<Cell>
|
|||
/M MOVES AN ENTIRE ROW OR COLUMN TO A NEW POSITION.
|
||||
/P PRINT COMMAND
|
||||
/R REPLICATE COMMAND
|
||||
/S STORAGE COMMANDS ARE AS FOLLOWS:
|
||||
|
||||
|
||||
/S STORAGE COMMANDS
|
||||
/SS SAVE
|
||||
/SL LOAD
|
||||
/SD DELETES SPECIFIED FILE ON DISK
|
||||
/SI INITIALIZE A DISK ON SPECIFIED DRIVE
|
||||
/SQ QUITS VISICALC
|
||||
|
||||
/T SETS A HORIZONTAL TITLE AREA(/TH), A VERTICAL TITLE AREA
|
||||
(/TV), SET BOTH A HORIZONTAL & VERTICAL TITLE AREA(/TB)
|
||||
OR RESETS THE WINDOWS TO HAVE NO TITLE AREAS(/TN)
|
||||
/T
|
||||
/TH SETS A HORIZONTAL TITLE AREA
|
||||
/TV SETS A VERTICAL TITLE AREA
|
||||
/TB SET BOTH A HORIZONTAL & VERTICAL TITLE AREA
|
||||
/TN RESETS THE WINDOWS TO HAVE NO TITLE AREAS
|
||||
|
||||
/V DISPLAYS VISICALC'S VERSION NUMBER ON THE PROMPT LINE
|
||||
/W WINDOW CONTROL
|
||||
|
||||
/WH HORIZONTAL WINDOW
|
||||
/WV VERTICAL WINDOW
|
||||
/W1 RETURNS SCREEN TO ONE WINDOW
|
||||
|
@ -138,7 +136,7 @@ public class Sheet implements Iterable<Cell>
|
|||
public Sheet (byte[] buffer)
|
||||
{
|
||||
int last = buffer.length;
|
||||
while (buffer[--last] == 0)
|
||||
while (buffer[--last] == 0) // ignore trailing zeroes
|
||||
;
|
||||
|
||||
int ptr = 0;
|
||||
|
@ -151,24 +149,15 @@ public class Sheet implements Iterable<Cell>
|
|||
ptr += length + 1; // +1 for end-of-line token
|
||||
}
|
||||
|
||||
calculate (recalculationOrder);
|
||||
|
||||
if (false)
|
||||
{
|
||||
System.out.println ();
|
||||
System.out.println ("Lines:");
|
||||
for (String line : lines)
|
||||
System.out.println (line);
|
||||
printDebug ();
|
||||
}
|
||||
|
||||
System.out.println ();
|
||||
System.out.println ("Cells:");
|
||||
for (Cell cell : sheet.values ())
|
||||
System.out.println (cell);
|
||||
private void calculate (char order)
|
||||
{
|
||||
|
||||
System.out.println ();
|
||||
System.out.println ("Column widths:");
|
||||
System.out.printf ("Default width : %3d%n", columnWidth);
|
||||
for (Map.Entry<Integer, Integer> entry : columnWidths.entrySet ())
|
||||
System.out.printf (" column %3d: %3d%n", entry.getKey (), entry.getValue ());
|
||||
}
|
||||
}
|
||||
|
||||
private int getLineLength (byte[] buffer, int offset)
|
||||
|
@ -292,17 +281,12 @@ public class Sheet implements Iterable<Cell>
|
|||
|
||||
Cell getCell (String addressText)
|
||||
{
|
||||
Address address = new Address (addressText);
|
||||
return getCell (address);
|
||||
return getCell (new Address (addressText));
|
||||
}
|
||||
|
||||
Cell getCell (Address address)
|
||||
{
|
||||
Cell cell = sheet.get (address.sortValue);
|
||||
// if (cell == null)
|
||||
// System.out.printf ("Nonexistent cell requested [%s]%n", address);
|
||||
|
||||
return cell;
|
||||
return sheet.get (address.sortValue);
|
||||
}
|
||||
|
||||
public int size ()
|
||||
|
@ -345,8 +329,6 @@ public class Sheet implements Iterable<Cell>
|
|||
String underline = "---------------------------------------------------------"
|
||||
+ "-----------------------------------------------------------------";
|
||||
|
||||
DecimalFormat nf = new DecimalFormat ("$#####0.00");
|
||||
// NumberFormat nf = NumberFormat.getCurrencyInstance ();
|
||||
int lastRow = -1;
|
||||
int lastColumn = 0;
|
||||
|
||||
|
@ -357,18 +339,16 @@ public class Sheet implements Iterable<Cell>
|
|||
if (columnWidths.containsKey (cellNo))
|
||||
width = columnWidths.get (cellNo);
|
||||
|
||||
char letter1 = cellNo < 26 ? ' ' : cellNo < 52 ? 'A' : 'B';
|
||||
char letter2 = (char) ((cellNo % 26) + 'A');
|
||||
String fmt =
|
||||
String.format ("%s%s%%%d.%ds", letter1, letter2, (width - 2), (width - 2));
|
||||
if (width == 1)
|
||||
heading.append ("=");
|
||||
heading.append (letter2);
|
||||
else if (width == 2)
|
||||
heading.append ("==");
|
||||
heading.append (String.format ("%s%s", letter1, letter2));
|
||||
else
|
||||
{
|
||||
char letter1 = cellNo < 26 ? ' ' : cellNo < 52 ? 'A' : 'B';
|
||||
char letter2 = (char) ((cellNo % 26) + 'A');
|
||||
String fmt =
|
||||
String.format ("%s%s%%%d.%ds", letter1, letter2, (width - 2), (width - 2));
|
||||
heading.append (String.format (fmt, underline));
|
||||
}
|
||||
}
|
||||
text.append (heading);
|
||||
|
||||
|
@ -400,4 +380,23 @@ public class Sheet implements Iterable<Cell>
|
|||
}
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
private void printDebug ()
|
||||
{
|
||||
System.out.println ();
|
||||
System.out.println ("Lines:");
|
||||
for (String line : lines)
|
||||
System.out.println (line);
|
||||
|
||||
System.out.println ();
|
||||
System.out.println ("Cells:");
|
||||
for (Cell cell : sheet.values ())
|
||||
System.out.println (cell);
|
||||
|
||||
System.out.println ();
|
||||
System.out.println ("Column widths:");
|
||||
System.out.printf ("Default width : %3d%n", columnWidth);
|
||||
for (Map.Entry<Integer, Integer> entry : columnWidths.entrySet ())
|
||||
System.out.printf (" column %3d: %3d%n", entry.getKey (), entry.getValue ());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user