method header lines

This commit is contained in:
Denis Molony 2020-02-08 17:50:03 +10:00
parent 09965c02aa
commit 4788f4bca4
14 changed files with 348 additions and 239 deletions

View File

@ -6,7 +6,9 @@ import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class AppleworksADBFile extends AbstractFile
// -----------------------------------------------------------------------------------//
{
static final String line = "-------------------------------------------------------"
+ "-----------------------------------\n";
@ -42,7 +44,9 @@ public class AppleworksADBFile extends AbstractFile
final List<Record> records = new ArrayList<> ();
private final Record standardRecord;
// ---------------------------------------------------------------------------------//
public AppleworksADBFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
@ -125,8 +129,10 @@ public class AppleworksADBFile extends AbstractFile
}
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
@ -179,7 +185,9 @@ public class AppleworksADBFile extends AbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
private void removeTrailing (StringBuilder text, char c)
// ---------------------------------------------------------------------------------//
{
while (text.charAt (text.length () - 1) == c)
text.deleteCharAt (text.length () - 1);

View File

@ -6,12 +6,16 @@ import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class AppleworksSSFile extends AbstractFile
// -----------------------------------------------------------------------------------//
{
Header header;
List<Row> rows = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
public AppleworksSSFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
@ -32,8 +36,10 @@ public class AppleworksSSFile extends AbstractFile
}
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder (header.toString ());
@ -47,14 +53,18 @@ public class AppleworksSSFile extends AbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
static String getCellName (int row, int column)
// ---------------------------------------------------------------------------------//
{
char c1 = (char) ('A' + column / 26 - 1);
char c2 = (char) ('A' + column % 26);
return "" + (c1 == '@' ? "" : c1) + c2 + row;
}
// ---------------------------------------------------------------------------------//
private class Header
// ---------------------------------------------------------------------------------//
{
private final int[] columnWidths = new int[127];
private final char calcOrder;
@ -245,7 +255,9 @@ public class AppleworksSSFile extends AbstractFile
}
}
// ---------------------------------------------------------------------------------//
private class Row
// ---------------------------------------------------------------------------------//
{
private final int rowNumber;
private final List<Cell> cells = new ArrayList<> ();

View File

@ -2,19 +2,25 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.applefile.AbstractFile;
// -----------------------------------------------------------------------------------//
public class AppleworksWPFile extends AbstractFile
// -----------------------------------------------------------------------------------//
{
Header header;
// ---------------------------------------------------------------------------------//
public AppleworksWPFile (String name, byte[] buffer)
// ---------------------------------------------------------------------------------//
{
super (name, buffer);
header = new Header ();
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
int leftMargin = header.leftMargin;
int rightMargin;
@ -31,7 +37,6 @@ public class AppleworksWPFile extends AbstractFile
{
int b1 = buffer[ptr] & 0xFF;
int b2 = buffer[ptr + 1] & 0xFF;
// System.out.printf ("%02X%02X %n", (buffer[ptr] & 0xFF), (buffer[ptr + 1] & 0xFF));
if (b1 == 0xFF && b2 == 0xFF)
break;
@ -144,7 +149,9 @@ public class AppleworksWPFile extends AbstractFile
return text.toString ();
}
// ---------------------------------------------------------------------------------//
private class Header
// ---------------------------------------------------------------------------------//
{
private final char[] tabStops = new char[80];
private final String tabs;

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.appleworks;
// -----------------------------------------------------------------------------------//
class Cell
// -----------------------------------------------------------------------------------//
{
final String cellName;
final int row;
@ -8,14 +10,18 @@ class Cell
String value;
String type;
// ---------------------------------------------------------------------------------//
static String getCellName (int row, int column)
// ---------------------------------------------------------------------------------//
{
char c1 = (char) ('A' + column / 26 - 1);
char c2 = (char) ('A' + column % 26);
return "" + (c1 == '@' ? "" : c1) + c2 + row;
}
// ---------------------------------------------------------------------------------//
public Cell (int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{
this.row = row;
this.column = column;
@ -23,8 +29,10 @@ class Cell
cellName = getCellName (row, column);
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return String.format ("%5s : %s %s%n", cellName, type, value);
}

View File

@ -2,19 +2,25 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellAddress
// -----------------------------------------------------------------------------------//
class CellAddress
// -----------------------------------------------------------------------------------//
{
int colRef;
int rowRef;
public CellAddress (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
CellAddress (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{
colRef = buffer[offset];
rowRef = HexFormatter.intValue (buffer[offset + 1], buffer[offset + 2]);
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return String.format ("[Row=%04d, Col=%04d]", rowRef, colRef);
}

View File

@ -2,12 +2,16 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellConstant extends Cell
// -----------------------------------------------------------------------------------//
class CellConstant extends Cell
// -----------------------------------------------------------------------------------//
{
double saneDouble;
CellFormat format;
public CellConstant (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
CellConstant (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{
super (row, column, offset, length);

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.appleworks;
public class CellFormat
// -----------------------------------------------------------------------------------//
class CellFormat
// -----------------------------------------------------------------------------------//
{
boolean labelAllowed;
boolean valueAllowed;
@ -13,7 +15,9 @@ public class CellFormat
boolean appropriate;
int decimals;
public CellFormat (byte format)
// ---------------------------------------------------------------------------------//
CellFormat (byte format)
// ---------------------------------------------------------------------------------//
{
display = (format & 0x40) == 0;
labelAllowed = (format & 0x10) == 0;
@ -29,13 +33,17 @@ public class CellFormat
appropriate = formatting == 6;
}
public CellFormat (byte format, byte decimals)
// ---------------------------------------------------------------------------------//
CellFormat (byte format, byte decimals)
// ---------------------------------------------------------------------------------//
{
this (format);
this.decimals = decimals & 0x07;
}
public String mask ()
// ---------------------------------------------------------------------------------//
String mask ()
// ---------------------------------------------------------------------------------//
{
String fmt = dollars ? "$%" : "%";
if (commas)

View File

@ -2,10 +2,12 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellFormula
// -----------------------------------------------------------------------------------//
class CellFormula
// -----------------------------------------------------------------------------------//
{
private static String[] tokens = {//
"@Deg", "@Rad", "@Pi", "@True", "@False", "@Not", "@IsBlank", "@IsNA", "@IsError",
private static String[] tokens =
{ "@Deg", "@Rad", "@Pi", "@True", "@False", "@Not", "@IsBlank", "@IsNA", "@IsError",
"@Exp", "@Ln", "@Log", "@Cos", "@Sin", "@Tan", "@ACos", "@ASin", "@ATan2",
"@ATan", "@Mod", "@FV", "@PV", "@PMT", "@Term", "@Rate", "@Round", "@Or", "@And",
"@Sum", "@Avg", "@Choose", "@Count", "@Error", "@IRR", "@If", "@Int", "@Lookup",
@ -13,7 +15,9 @@ public class CellFormula
"<", ",", "^", ")", "-", "+", "/", "*", "(", "-", "+", "..." };
String value;
public CellFormula (Cell cell, byte[] buffer, int offset, int length)
// ---------------------------------------------------------------------------------//
CellFormula (Cell cell, byte[] buffer, int offset, int length)
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();

View File

@ -2,12 +2,16 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellLabel extends Cell
// -----------------------------------------------------------------------------------//
class CellLabel extends Cell
// -----------------------------------------------------------------------------------//
{
boolean propagated;
String label;
public CellLabel (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
CellLabel (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{
super (row, column, offset, length);

View File

@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class CellValue extends Cell
// -----------------------------------------------------------------------------------//
class CellValue extends Cell
// -----------------------------------------------------------------------------------//
{
CellFormat format;
CellFormula formula;
@ -10,7 +12,9 @@ public class CellValue extends Cell
boolean lastEvalError;
double saneDouble;
public CellValue (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
CellValue (byte[] buffer, int row, int column, int offset, int length)
// ---------------------------------------------------------------------------------//
{
super (row, column, offset, length);

View File

@ -1,15 +1,20 @@
package com.bytezone.diskbrowser.appleworks;
// -----------------------------------------------------------------------------------//
class LabelReport extends Report
// -----------------------------------------------------------------------------------//
{
public LabelReport (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
LabelReport (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{
super (parent, buffer, offset);
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
return "Skipping vertical report\n";
}

View File

@ -7,14 +7,18 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// -----------------------------------------------------------------------------------//
class Record
// -----------------------------------------------------------------------------------//
{
AppleworksADBFile parent;
int length;
List<String> items = new ArrayList<> ();
Map<Integer, Double> calculatedItems = new HashMap<Integer, Double> ();// move to TableReport
Map<Integer, Double> calculatedItems = new HashMap<> (); // move to TableReport
public Record (AppleworksADBFile parent, byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
Record (AppleworksADBFile parent, byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{
this.parent = parent;
int count;
@ -55,12 +59,16 @@ class Record
items.add ("");
}
public String getItem (int index)
// ---------------------------------------------------------------------------------//
String getItem (int index)
// ---------------------------------------------------------------------------------//
{
return items.get (index);
}
public double calculateItem (int pos, int name, String condition)
// ---------------------------------------------------------------------------------//
double calculateItem (int pos, int name, String condition)
// ---------------------------------------------------------------------------------//
{
try
{
@ -112,7 +120,9 @@ class Record
return 0.0;
}
// ---------------------------------------------------------------------------------//
private String valueOf (int field)
// ---------------------------------------------------------------------------------//
{
int itemNo = field - 'A';
@ -138,12 +148,16 @@ class Record
return "0.0";
}
public String getReportLine (String format)
// ---------------------------------------------------------------------------------//
String getReportLine (String format)
// ---------------------------------------------------------------------------------//
{
return String.format (format, (Object[]) items.toArray (new String[items.size ()]));
}
public String getReportLine ()
// ---------------------------------------------------------------------------------//
String getReportLine ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
String format = String.format ("%%-%ds : %%s%%n", parent.maxCategoryName);
@ -163,8 +177,10 @@ class Record
return text.toString ();
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
String format = "%-" + parent.maxCategoryName + "s [%s]%n";

View File

@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.appleworks;
import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
abstract class Report
// -----------------------------------------------------------------------------------//
{
static final String line = "-------------------------------------------------------"
+ "-----------------------------------\n";
@ -37,7 +39,9 @@ abstract class Report
private final boolean printDash;
private String fudgeReason;
public Report (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
Report (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{
this.parent = parent;
@ -126,24 +130,32 @@ abstract class Report
if (buffer[offset + 480 + fudge] == 0) // test high byte
for (int i = 0; i < 3; i++)
{
selectionRules[i] = HexFormatter.unsignedShort (buffer, offset + 479 + i * 2 + fudge);
selectionRules[i] =
HexFormatter.unsignedShort (buffer, offset + 479 + i * 2 + fudge);
testTypes[i] = HexFormatter.unsignedShort (buffer, offset + 485 + i * 2 + fudge);
continuation[i] = HexFormatter.unsignedShort (buffer, offset + 491 + i * 2 + fudge);
continuation[i] =
HexFormatter.unsignedShort (buffer, offset + 491 + i * 2 + fudge);
comparison[i] = pascalString (buffer, offset + 497 + i * 32 + fudge);
}
else
System.out.println ("*** Invalid value in report rules ***");
}
public abstract String getText ();
// ---------------------------------------------------------------------------------//
abstract String getText ();
// ---------------------------------------------------------------------------------//
// ---------------------------------------------------------------------------------//
protected String pascalString (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{
return new String (buffer, ptr + 1, buffer[ptr] & 0xFF);
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();

View File

@ -1,6 +1,8 @@
package com.bytezone.diskbrowser.appleworks;
// -----------------------------------------------------------------------------------//
class TableReport extends Report
// -----------------------------------------------------------------------------------//
{
private final int[] columnWidths = new int[33];
private final int[] spaces = new int[33];
@ -15,7 +17,9 @@ class TableReport extends Report
private final int groupTotalColumn;
private final boolean printGroupTotals;
public TableReport (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
TableReport (AppleworksADBFile parent, byte[] buffer, int offset)
// ---------------------------------------------------------------------------------//
{
super (parent, buffer, offset);
@ -39,8 +43,10 @@ class TableReport extends Report
printGroupTotals = buffer[offset + 217] != 0;
}
// ---------------------------------------------------------------------------------//
@Override
public String getText ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
@ -69,7 +75,8 @@ class TableReport extends Report
categoryName = categoryName.substring (0, columnWidths[i]);
header.append (categoryName);
header.append (gap.substring (0, columnWidths[i] + spaces[i] - categoryName.length ()));
header.append (
gap.substring (0, columnWidths[i] + spaces[i] - categoryName.length ()));
underline.append (line.substring (0, columnWidths[i]));
underline.append (gap.substring (0, spaces[i]));
}
@ -98,8 +105,8 @@ class TableReport extends Report
String cond = calculatedRules[calcField];
int col = calculatedColumn[calcField] - 1;
String format = "%12." + justification[col] + "f";
item =
String.format (format, record.calculateItem (calcField, i + 97, cond)).trim ();
item = String.format (format, record.calculateItem (calcField, i + 97, cond))
.trim ();
// System.out.println (item);
}
@ -178,15 +185,19 @@ class TableReport extends Report
return text.toString ();
}
// ---------------------------------------------------------------------------------//
private StringBuilder trimRight (StringBuilder text)
// ---------------------------------------------------------------------------------//
{
while (text.length () > 0 && text.charAt (text.length () - 1) == ' ')
text.deleteCharAt (text.length () - 1);
return text;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder (super.toString ());
text.append (String.format ("Calculated ......... %d %d %d%n", calculatedColumn[0],
@ -202,9 +213,9 @@ class TableReport extends Report
text.append (String.format ("%n Width Space Name Foot Just%n"));
for (int i = 0; i < categoriesOnThisReport; i++)
text.append (String.format (" %2d %2d %02X %02X %02X %n", columnWidths[i],
spaces[i], reportCategoryNames[i], footTotals[i],
justification[i]));
text.append (
String.format (" %2d %2d %02X %02X %02X %n", columnWidths[i],
spaces[i], reportCategoryNames[i], footTotals[i], justification[i]));
return text.toString ();
}