From 4788f4bca4a857f4c0fadca66e1c4fa5906577ef Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sat, 8 Feb 2020 17:50:03 +1000 Subject: [PATCH] method header lines --- .../appleworks/AppleworksADBFile.java | 8 + .../appleworks/AppleworksSSFile.java | 12 + .../appleworks/AppleworksWPFile.java | 395 +++++++++--------- .../bytezone/diskbrowser/appleworks/Cell.java | 8 + .../diskbrowser/appleworks/CellAddress.java | 10 +- .../diskbrowser/appleworks/CellConstant.java | 8 +- .../diskbrowser/appleworks/CellFormat.java | 16 +- .../diskbrowser/appleworks/CellFormula.java | 24 +- .../diskbrowser/appleworks/CellLabel.java | 8 +- .../diskbrowser/appleworks/CellValue.java | 8 +- .../diskbrowser/appleworks/LabelReport.java | 11 +- .../diskbrowser/appleworks/Record.java | 32 +- .../diskbrowser/appleworks/Report.java | 20 +- .../diskbrowser/appleworks/TableReport.java | 27 +- 14 files changed, 348 insertions(+), 239 deletions(-) diff --git a/src/com/bytezone/diskbrowser/appleworks/AppleworksADBFile.java b/src/com/bytezone/diskbrowser/appleworks/AppleworksADBFile.java index 5ed48d9..e266500 100644 --- a/src/com/bytezone/diskbrowser/appleworks/AppleworksADBFile.java +++ b/src/com/bytezone/diskbrowser/appleworks/AppleworksADBFile.java @@ -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 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); diff --git a/src/com/bytezone/diskbrowser/appleworks/AppleworksSSFile.java b/src/com/bytezone/diskbrowser/appleworks/AppleworksSSFile.java index 58674ac..2effea3 100644 --- a/src/com/bytezone/diskbrowser/appleworks/AppleworksSSFile.java +++ b/src/com/bytezone/diskbrowser/appleworks/AppleworksSSFile.java @@ -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 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 cells = new ArrayList<> (); diff --git a/src/com/bytezone/diskbrowser/appleworks/AppleworksWPFile.java b/src/com/bytezone/diskbrowser/appleworks/AppleworksWPFile.java index 4e9f39c..dbc7295 100755 --- a/src/com/bytezone/diskbrowser/appleworks/AppleworksWPFile.java +++ b/src/com/bytezone/diskbrowser/appleworks/AppleworksWPFile.java @@ -1,195 +1,202 @@ -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; - int topMargin; - int bottomMargin; - int paperLength; - int indent; - - int ptr = 300; // skip the header - StringBuilder text = new StringBuilder (header.toString ()); - text.append ("\n"); - - while (true) - { - 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; - - switch (b2) - { - case 0: - int len = b1; - int b3 = buffer[ptr + 2] & 0xFF; - int b4 = buffer[ptr + 3] & 0xFF; - - int lineMargin = b3 & 0x7F; - boolean containsTabs = (b3 & 0x80) != 0; - int textLen = b4 & 0x7F; - boolean cr = (b4 & 0x80) != 0; - - if (false) - System.out.printf ("%02X %02X %d %d %s %s%n", b3, b4, lineMargin, textLen, - containsTabs, cr); - if (b3 == 0xFF) - text.append ("--------- Ruler ----------\n"); - else - { - // left margin - for (int i = 0; i < leftMargin; i++) - text.append (" "); - for (int i = 0; i < lineMargin; i++) - text.append (" "); - - // check for tabs (I'm guessing about how this works) - if (false) - { - while (buffer[ptr + 4] == 0x16) // tab character - { - ptr++; - len--; - while (buffer[ptr + 4] == 0x17) // tab fill character - { - text.append (" "); - ptr++; - len--; - } - } - text.append (new String (buffer, ptr + 4, len - 2)); - ptr += len; - } - else - { - StringBuilder line = new StringBuilder (); - int p = ptr + 4; - ptr += len; - len -= 2; - - while (--len >= 0) - { - char c = (char) buffer[p++]; - if (c >= 0x20) - line.append (c); - else if (c == 0x17) - line.append (' '); - } - - text.append (line.toString ()); - } - } - - text.append ("\n"); - - if (cr) - text.append ("\n"); - - break; - - case 0xD0: - text.append ("\n"); - break; - - case 0xD9: - leftMargin = b1; - break; - - case 0xDA: - rightMargin = b1; - break; - - case 0xDE: - indent = b1; - break; - - case 0xE2: - paperLength = b1; - break; - - case 0xE3: - topMargin = b1; - break; - - case 0xE4: - bottomMargin = b1; - break; - - default: - System.out.printf ("Unknown value in %s: %02X %02X%n", name, b1, b2); - } - ptr += 2; - } - if (false) - System.out.printf ("", leftMargin, rightMargin, topMargin, bottomMargin, - paperLength, indent); - return text.toString (); - } - - private class Header - { - private final char[] tabStops = new char[80]; - private final String tabs; - private final boolean zoom; - private final boolean paginated; - private final int leftMargin; - private final boolean mailMerge; - private final int sfMinVers; - - private final boolean multipleRulers; - - public Header () - { - // see Asimov disks/images 2/pd_collections/apple_linc/ - // 1988-02 side A (no boot).dsk - assert buffer[4] == 0x4F; - - int ptr = 5; - for (int i = 0; i < 80; i++) - tabStops[i] = (char) buffer[ptr++]; - - tabs = new String (tabStops); - zoom = buffer[85] != 0; - paginated = buffer[90] != 0; - leftMargin = buffer[91] & 0xFF; - mailMerge = buffer[92] != 0; - - multipleRulers = buffer[176] != 0; - sfMinVers = buffer[183] & 0xFF; - } - - @Override - public String toString () - { - StringBuilder text = new StringBuilder (); - - text.append (String.format ("Tabs ......... %s %n", tabs)); - text.append (String.format ("Zoom ......... %s %n", zoom)); - text.append (String.format ("Mail merge ... %s %n", mailMerge)); - text.append (String.format ("Left margin .. %d %n", leftMargin)); - text.append (String.format ("Min version .. %d %n", sfMinVers)); - text.append (String.format ("Mult rulers .. %s %n", multipleRulers)); - text.append (String.format ("Paginated .... %s %n", paginated)); - - return text.toString (); - } - } +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; + int topMargin; + int bottomMargin; + int paperLength; + int indent; + + int ptr = 300; // skip the header + StringBuilder text = new StringBuilder (header.toString ()); + text.append ("\n"); + + while (true) + { + int b1 = buffer[ptr] & 0xFF; + int b2 = buffer[ptr + 1] & 0xFF; + + if (b1 == 0xFF && b2 == 0xFF) + break; + + switch (b2) + { + case 0: + int len = b1; + int b3 = buffer[ptr + 2] & 0xFF; + int b4 = buffer[ptr + 3] & 0xFF; + + int lineMargin = b3 & 0x7F; + boolean containsTabs = (b3 & 0x80) != 0; + int textLen = b4 & 0x7F; + boolean cr = (b4 & 0x80) != 0; + + if (false) + System.out.printf ("%02X %02X %d %d %s %s%n", b3, b4, lineMargin, textLen, + containsTabs, cr); + if (b3 == 0xFF) + text.append ("--------- Ruler ----------\n"); + else + { + // left margin + for (int i = 0; i < leftMargin; i++) + text.append (" "); + for (int i = 0; i < lineMargin; i++) + text.append (" "); + + // check for tabs (I'm guessing about how this works) + if (false) + { + while (buffer[ptr + 4] == 0x16) // tab character + { + ptr++; + len--; + while (buffer[ptr + 4] == 0x17) // tab fill character + { + text.append (" "); + ptr++; + len--; + } + } + text.append (new String (buffer, ptr + 4, len - 2)); + ptr += len; + } + else + { + StringBuilder line = new StringBuilder (); + int p = ptr + 4; + ptr += len; + len -= 2; + + while (--len >= 0) + { + char c = (char) buffer[p++]; + if (c >= 0x20) + line.append (c); + else if (c == 0x17) + line.append (' '); + } + + text.append (line.toString ()); + } + } + + text.append ("\n"); + + if (cr) + text.append ("\n"); + + break; + + case 0xD0: + text.append ("\n"); + break; + + case 0xD9: + leftMargin = b1; + break; + + case 0xDA: + rightMargin = b1; + break; + + case 0xDE: + indent = b1; + break; + + case 0xE2: + paperLength = b1; + break; + + case 0xE3: + topMargin = b1; + break; + + case 0xE4: + bottomMargin = b1; + break; + + default: + System.out.printf ("Unknown value in %s: %02X %02X%n", name, b1, b2); + } + ptr += 2; + } + if (false) + System.out.printf ("", leftMargin, rightMargin, topMargin, bottomMargin, + paperLength, indent); + return text.toString (); + } + + // ---------------------------------------------------------------------------------// + private class Header + // ---------------------------------------------------------------------------------// + { + private final char[] tabStops = new char[80]; + private final String tabs; + private final boolean zoom; + private final boolean paginated; + private final int leftMargin; + private final boolean mailMerge; + private final int sfMinVers; + + private final boolean multipleRulers; + + public Header () + { + // see Asimov disks/images 2/pd_collections/apple_linc/ + // 1988-02 side A (no boot).dsk + assert buffer[4] == 0x4F; + + int ptr = 5; + for (int i = 0; i < 80; i++) + tabStops[i] = (char) buffer[ptr++]; + + tabs = new String (tabStops); + zoom = buffer[85] != 0; + paginated = buffer[90] != 0; + leftMargin = buffer[91] & 0xFF; + mailMerge = buffer[92] != 0; + + multipleRulers = buffer[176] != 0; + sfMinVers = buffer[183] & 0xFF; + } + + @Override + public String toString () + { + StringBuilder text = new StringBuilder (); + + text.append (String.format ("Tabs ......... %s %n", tabs)); + text.append (String.format ("Zoom ......... %s %n", zoom)); + text.append (String.format ("Mail merge ... %s %n", mailMerge)); + text.append (String.format ("Left margin .. %d %n", leftMargin)); + text.append (String.format ("Min version .. %d %n", sfMinVers)); + text.append (String.format ("Mult rulers .. %s %n", multipleRulers)); + text.append (String.format ("Paginated .... %s %n", paginated)); + + return text.toString (); + } + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/appleworks/Cell.java b/src/com/bytezone/diskbrowser/appleworks/Cell.java index 2d11415..4d475d4 100644 --- a/src/com/bytezone/diskbrowser/appleworks/Cell.java +++ b/src/com/bytezone/diskbrowser/appleworks/Cell.java @@ -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); } diff --git a/src/com/bytezone/diskbrowser/appleworks/CellAddress.java b/src/com/bytezone/diskbrowser/appleworks/CellAddress.java index 8be95ed..4227761 100644 --- a/src/com/bytezone/diskbrowser/appleworks/CellAddress.java +++ b/src/com/bytezone/diskbrowser/appleworks/CellAddress.java @@ -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); } diff --git a/src/com/bytezone/diskbrowser/appleworks/CellConstant.java b/src/com/bytezone/diskbrowser/appleworks/CellConstant.java index e13b571..b5d88bf 100644 --- a/src/com/bytezone/diskbrowser/appleworks/CellConstant.java +++ b/src/com/bytezone/diskbrowser/appleworks/CellConstant.java @@ -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); diff --git a/src/com/bytezone/diskbrowser/appleworks/CellFormat.java b/src/com/bytezone/diskbrowser/appleworks/CellFormat.java index e52d67c..5281d9e 100644 --- a/src/com/bytezone/diskbrowser/appleworks/CellFormat.java +++ b/src/com/bytezone/diskbrowser/appleworks/CellFormat.java @@ -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) diff --git a/src/com/bytezone/diskbrowser/appleworks/CellFormula.java b/src/com/bytezone/diskbrowser/appleworks/CellFormula.java index 3bbbd6d..8d919c6 100644 --- a/src/com/bytezone/diskbrowser/appleworks/CellFormula.java +++ b/src/com/bytezone/diskbrowser/appleworks/CellFormula.java @@ -2,18 +2,22 @@ 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", - "@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", - "@Max", "@Min", "@NA", "@NPV", "@Sqrt", "@Abs", "", "<>", ">=", "<=", "=", ">", - "<", ",", "^", ")", "-", "+", "/", "*", "(", "-", "+", "..." }; + 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", + "@Max", "@Min", "@NA", "@NPV", "@Sqrt", "@Abs", "", "<>", ">=", "<=", "=", ">", + "<", ",", "^", ")", "-", "+", "/", "*", "(", "-", "+", "..." }; 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 (); @@ -42,7 +46,7 @@ public class CellFormula { CellAddress address = new CellAddress (buffer, offset + i + 1); String cellName = - Cell.getCellName (cell.row + address.rowRef, cell.column + address.colRef); + Cell.getCellName (cell.row + address.rowRef, cell.column + address.colRef); i += 3; text.append (cellName); } diff --git a/src/com/bytezone/diskbrowser/appleworks/CellLabel.java b/src/com/bytezone/diskbrowser/appleworks/CellLabel.java index fcd1539..7029599 100644 --- a/src/com/bytezone/diskbrowser/appleworks/CellLabel.java +++ b/src/com/bytezone/diskbrowser/appleworks/CellLabel.java @@ -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); diff --git a/src/com/bytezone/diskbrowser/appleworks/CellValue.java b/src/com/bytezone/diskbrowser/appleworks/CellValue.java index 0463a81..69d2550 100644 --- a/src/com/bytezone/diskbrowser/appleworks/CellValue.java +++ b/src/com/bytezone/diskbrowser/appleworks/CellValue.java @@ -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); diff --git a/src/com/bytezone/diskbrowser/appleworks/LabelReport.java b/src/com/bytezone/diskbrowser/appleworks/LabelReport.java index d64b31c..519daba 100644 --- a/src/com/bytezone/diskbrowser/appleworks/LabelReport.java +++ b/src/com/bytezone/diskbrowser/appleworks/LabelReport.java @@ -1,16 +1,21 @@ 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"; } -} \ No newline at end of file +} diff --git a/src/com/bytezone/diskbrowser/appleworks/Record.java b/src/com/bytezone/diskbrowser/appleworks/Record.java index 75e54db..7353b63 100644 --- a/src/com/bytezone/diskbrowser/appleworks/Record.java +++ b/src/com/bytezone/diskbrowser/appleworks/Record.java @@ -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 items = new ArrayList<> (); - Map calculatedItems = new HashMap ();// move to TableReport + Map 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,16 +59,20 @@ 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 { - // System.out.printf ("%nCalculating %d (%s): %s%n", pos, (char) name, condition); + // System.out.printf ("%nCalculating %d (%s): %s%n", pos, (char) name, condition); Pattern p = Pattern.compile ("([A-Za-z]{1,2})(([-+*/]([A-Za-z]{1,2}|[0-9]))*)"); Matcher m = p.matcher (condition); if (m.matches ()) @@ -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"; @@ -175,4 +191,4 @@ class Record return text.toString (); } -} \ No newline at end of file +} diff --git a/src/com/bytezone/diskbrowser/appleworks/Report.java b/src/com/bytezone/diskbrowser/appleworks/Report.java index b888917..968d517 100644 --- a/src/com/bytezone/diskbrowser/appleworks/Report.java +++ b/src/com/bytezone/diskbrowser/appleworks/Report.java @@ -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 (); diff --git a/src/com/bytezone/diskbrowser/appleworks/TableReport.java b/src/com/bytezone/diskbrowser/appleworks/TableReport.java index eb89940..f0daa06 100644 --- a/src/com/bytezone/diskbrowser/appleworks/TableReport.java +++ b/src/com/bytezone/diskbrowser/appleworks/TableReport.java @@ -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,19 +185,23 @@ 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], - calculatedColumn[1], calculatedColumn[2])); + calculatedColumn[1], calculatedColumn[2])); text.append (String.format ("Group total ........ %d%n", groupTotalColumn)); text.append (String.format ("Print gr totals .... %s%n", printGroupTotals)); text.append (String.format ("Calc category1 ..... %s%n", calculatedCategory[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 (); }