From bca4858087181ca36ae04630123ce0713d412010 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Thu, 7 Nov 2019 13:06:09 +1000 Subject: [PATCH] tidying --- .../diskbrowser/applefile/CharacterList.java | 15 ++-- .../diskbrowser/applefile/IconFile.java | 39 ++++++++--- .../diskbrowser/applefile/LodeRunner.java | 69 +++++++------------ .../diskbrowser/utilities/DateTime.java | 25 ++++--- .../utilities/FileFormatException.java | 6 ++ .../diskbrowser/utilities/FormatRenderer.java | 10 +++ .../diskbrowser/utilities/Utility.java | 7 ++ 7 files changed, 99 insertions(+), 72 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/CharacterList.java b/src/com/bytezone/diskbrowser/applefile/CharacterList.java index eefd4a9..dabd394 100644 --- a/src/com/bytezone/diskbrowser/applefile/CharacterList.java +++ b/src/com/bytezone/diskbrowser/applefile/CharacterList.java @@ -8,6 +8,8 @@ import java.awt.image.DataBuffer; import java.util.ArrayList; import java.util.List; +import com.bytezone.diskbrowser.utilities.Utility; + // -----------------------------------------------------------------------------------// abstract class CharacterList extends AbstractFile // -----------------------------------------------------------------------------------// @@ -35,9 +37,9 @@ abstract class CharacterList extends AbstractFile { super (name, buffer); - image = new BufferedImage ( // - dimension (charsX, borderX, sizeX, gapX), // - dimension (charsY, borderY, sizeY, gapY), // + image = new BufferedImage ( // + Utility.dimension (charsX, borderX, sizeX, gapX), // + Utility.dimension (charsY, borderY, sizeY, gapY), // BufferedImage.TYPE_BYTE_GRAY); Graphics2D g2d = image.createGraphics (); @@ -77,13 +79,6 @@ abstract class CharacterList extends AbstractFile abstract Character createCharacter (byte[] buffer, int ptr); // ---------------------------------------------------------------------------------// - // ---------------------------------------------------------------------------------// - int dimension (int chars, int border, int size, int gap) - // ---------------------------------------------------------------------------------// - { - return border * 2 + chars * (size + gap) - gap; - } - // ---------------------------------------------------------------------------------// @Override public String getText () diff --git a/src/com/bytezone/diskbrowser/applefile/IconFile.java b/src/com/bytezone/diskbrowser/applefile/IconFile.java index e957d92..492ae5b 100644 --- a/src/com/bytezone/diskbrowser/applefile/IconFile.java +++ b/src/com/bytezone/diskbrowser/applefile/IconFile.java @@ -10,8 +10,11 @@ import java.util.List; import com.bytezone.diskbrowser.prodos.ProdosConstants; import com.bytezone.diskbrowser.utilities.HexFormatter; +import com.bytezone.diskbrowser.utilities.Utility; +// -----------------------------------------------------------------------------------// public class IconFile extends AbstractFile implements ProdosConstants +// -----------------------------------------------------------------------------------// { private final int iBlkNext; private final int iBlkID; @@ -20,7 +23,9 @@ public class IconFile extends AbstractFile implements ProdosConstants private final List icons = new ArrayList<> (); private final boolean debug = false; + // ---------------------------------------------------------------------------------// public IconFile (String name, byte[] buffer) + // ---------------------------------------------------------------------------------// { super (name, buffer); @@ -59,9 +64,9 @@ public class IconFile extends AbstractFile implements ProdosConstants int columns = Math.min (icons.size (), 4); int rows = (icons.size () - 1) / columns + 1; - image = new BufferedImage ( // - dimension (columns, base, maxWidth, gap), // - dimension (rows, base, maxHeight, gap), // + image = new BufferedImage ( // + Utility.dimension (columns, base, maxWidth, gap), // + Utility.dimension (rows, base, maxHeight, gap), // BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics (); @@ -88,14 +93,9 @@ public class IconFile extends AbstractFile implements ProdosConstants } // ---------------------------------------------------------------------------------// - private int dimension (int chars, int border, int size, int gap) - // ---------------------------------------------------------------------------------// - { - return border * 2 + chars * (size + gap) - gap; - } - @Override public String getText () + // ---------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder ("Name : " + name + "\n\n"); @@ -114,7 +114,9 @@ public class IconFile extends AbstractFile implements ProdosConstants return text.toString (); } + // ---------------------------------------------------------------------------------// class Icon + // ---------------------------------------------------------------------------------// { byte[] buffer; int iDataLen; @@ -125,7 +127,9 @@ public class IconFile extends AbstractFile implements ProdosConstants Image largeImage; Image smallImage; + // -------------------------------------------------------------------------------// public Icon (byte[] fullBuffer, int ptr) + // -------------------------------------------------------------------------------// { iDataLen = HexFormatter.unsignedShort (fullBuffer, ptr); @@ -161,8 +165,10 @@ public class IconFile extends AbstractFile implements ProdosConstants } } + // -------------------------------------------------------------------------------// @Override public String toString () + // -------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder (); text.append (String.format ("Data length .. %04X%n", iDataLen)); @@ -177,7 +183,9 @@ public class IconFile extends AbstractFile implements ProdosConstants } } + // ---------------------------------------------------------------------------------// class Image + // ---------------------------------------------------------------------------------// { int iconType; int iconSize; @@ -188,7 +196,9 @@ public class IconFile extends AbstractFile implements ProdosConstants boolean colour; private final BufferedImage image; + // -------------------------------------------------------------------------------// public Image (byte[] buffer, int ptr) throws InvalidImageException + // -------------------------------------------------------------------------------// { iconType = HexFormatter.unsignedShort (buffer, ptr); iconSize = HexFormatter.unsignedShort (buffer, ptr + 2); @@ -210,6 +220,7 @@ public class IconFile extends AbstractFile implements ProdosConstants if (iconType != 0 && iconType != 0x8000 && iconType != 0xFFFF && iconType != 0x00FF) throw new InvalidImageException (String.format ("Bad icon type: %04X", iconType)); + // have also seen 0x7FFF and 0x8001 iconImage = new byte[iconSize]; iconMask = new byte[iconSize]; @@ -248,13 +259,17 @@ public class IconFile extends AbstractFile implements ProdosConstants } } + // -------------------------------------------------------------------------------// public int size () + // -------------------------------------------------------------------------------// { return 8 + iconSize * 2; } + // -------------------------------------------------------------------------------// @Override public String toString () + // -------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder (); @@ -306,7 +321,9 @@ public class IconFile extends AbstractFile implements ProdosConstants other color of pixel becoming black." */ + // -------------------------------------------------------------------------------// private void appendIcon (StringBuilder text, byte[] buffer) + // -------------------------------------------------------------------------------// { int rowBytes = (iconWidth - 1) / 2 + 1; for (int i = 0; i < iconImage.length; i += rowBytes) @@ -324,9 +341,13 @@ public class IconFile extends AbstractFile implements ProdosConstants } } + // ---------------------------------------------------------------------------------// class InvalidImageException extends Exception + // ---------------------------------------------------------------------------------// { + // -------------------------------------------------------------------------------// public InvalidImageException (String message) + // -------------------------------------------------------------------------------// { super (message); } diff --git a/src/com/bytezone/diskbrowser/applefile/LodeRunner.java b/src/com/bytezone/diskbrowser/applefile/LodeRunner.java index 6f2a802..e5e86e9 100644 --- a/src/com/bytezone/diskbrowser/applefile/LodeRunner.java +++ b/src/com/bytezone/diskbrowser/applefile/LodeRunner.java @@ -2,15 +2,33 @@ package com.bytezone.diskbrowser.applefile; import com.bytezone.diskbrowser.utilities.HexFormatter; +// -----------------------------------------------------------------------------------// public class LodeRunner extends AbstractFile +// -----------------------------------------------------------------------------------// { + private static char[] chars = { ' ', // space + '-', // diggable floor + '=', // undiggable floor + '+', // ladder + '^', // hand over hand bar + '~', // trap door + '#', // hidden ladder + '$', // gold + '*', // enemy + 'x' // player + }; + + // ---------------------------------------------------------------------------------// public LodeRunner (String name, byte[] buffer) + // ---------------------------------------------------------------------------------// { super (name, buffer); } + // ---------------------------------------------------------------------------------// @Override public String getText () + // ---------------------------------------------------------------------------------// { StringBuilder text = new StringBuilder (); text.append ("Lode Runner Level\n\n"); @@ -40,53 +58,14 @@ public class LodeRunner extends AbstractFile return text.toString (); } + // ---------------------------------------------------------------------------------// private StringBuilder addPosition (StringBuilder text, char c) + // ---------------------------------------------------------------------------------// { - switch (c) - { - case '0': - text.append (' '); // space - break; - - case '1': - text.append ('-'); // diggable floor - break; - - case '2': - text.append ('='); // undiggable floor - break; - - case '3': - text.append ('+'); // ladder - break; - - case '4': - text.append ('^'); // hand over hand bar - break; - - case '5': - text.append ('~'); // trap door - break; - - case '6': - text.append ('#'); // hidden ladder - break; - - case '7': - text.append ('$'); // gold - break; - - case '8': - text.append ('*'); // enemy - break; - - case '9': - text.append ('x'); // player - break; - - default: - text.append (c); - } + if (c >= 0 && c <= 9) + text.append (chars[c]); + else + text.append (c); return text; } diff --git a/src/com/bytezone/diskbrowser/utilities/DateTime.java b/src/com/bytezone/diskbrowser/utilities/DateTime.java index e448861..fceb8ee 100644 --- a/src/com/bytezone/diskbrowser/utilities/DateTime.java +++ b/src/com/bytezone/diskbrowser/utilities/DateTime.java @@ -1,11 +1,13 @@ package com.bytezone.diskbrowser.utilities; +// -----------------------------------------------------------------------------------// class DateTime +// -----------------------------------------------------------------------------------// { - private static String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", - "Sep", "Oct", "Nov", "Dec" }; - private static String[] days = { "", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", - "Friday", "Saturday" }; + private static String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", + "Aug", "Sep", "Oct", "Nov", "Dec" }; + private static String[] days = { "", "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" }; private final int second; private final int minute; @@ -15,7 +17,9 @@ class DateTime private final int month; private final int weekDay; + // ---------------------------------------------------------------------------------// public DateTime (byte[] buffer, int ptr) + // ---------------------------------------------------------------------------------// { second = buffer[ptr] & 0xFF; minute = buffer[++ptr] & 0xFF; @@ -27,16 +31,21 @@ class DateTime weekDay = buffer[++ptr] & 0xFF; } + // ---------------------------------------------------------------------------------// public String format () + // ---------------------------------------------------------------------------------// { - return String.format ("%02d:%02d:%02d %s %d %s %d", hour, minute, second, days[weekDay], - day, months[month], year); + return String.format ("%02d:%02d:%02d %s %d %s %d", hour, minute, second, + days[weekDay], day, months[month], year); } + // ---------------------------------------------------------------------------------// @Override public String toString () + // ---------------------------------------------------------------------------------// { - return "DateTime [second=" + second + ", minute=" + minute + ", hour=" + hour + ", year=" - + year + ", day=" + day + ", month=" + month + ", weekDay=" + weekDay + "]"; + return "DateTime [second=" + second + ", minute=" + minute + ", hour=" + hour + + ", year=" + year + ", day=" + day + ", month=" + month + ", weekDay=" + weekDay + + "]"; } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/utilities/FileFormatException.java b/src/com/bytezone/diskbrowser/utilities/FileFormatException.java index 5717b6e..552b1b5 100644 --- a/src/com/bytezone/diskbrowser/utilities/FileFormatException.java +++ b/src/com/bytezone/diskbrowser/utilities/FileFormatException.java @@ -1,16 +1,22 @@ package com.bytezone.diskbrowser.utilities; +// -----------------------------------------------------------------------------------// public class FileFormatException extends RuntimeException +// -----------------------------------------------------------------------------------// { String message; + // ---------------------------------------------------------------------------------// public FileFormatException (String string) + // ---------------------------------------------------------------------------------// { this.message = string; } + // ---------------------------------------------------------------------------------// @Override public String toString () + // ---------------------------------------------------------------------------------// { return message; } diff --git a/src/com/bytezone/diskbrowser/utilities/FormatRenderer.java b/src/com/bytezone/diskbrowser/utilities/FormatRenderer.java index 975d96c..74afef2 100644 --- a/src/com/bytezone/diskbrowser/utilities/FormatRenderer.java +++ b/src/com/bytezone/diskbrowser/utilities/FormatRenderer.java @@ -5,17 +5,23 @@ import java.text.Format; import javax.swing.table.DefaultTableCellRenderer; +// -----------------------------------------------------------------------------------// public class FormatRenderer extends DefaultTableCellRenderer +// -----------------------------------------------------------------------------------// { private final Format formatter; + // ---------------------------------------------------------------------------------// public FormatRenderer (Format formatter) + // ---------------------------------------------------------------------------------// { this.formatter = formatter; } + // ---------------------------------------------------------------------------------// @Override public void setValue (Object value) + // ---------------------------------------------------------------------------------// { try { @@ -29,12 +35,16 @@ public class FormatRenderer extends DefaultTableCellRenderer super.setValue (value); } + // ---------------------------------------------------------------------------------// public static FormatRenderer getDateTimeRenderer () + // ---------------------------------------------------------------------------------// { return new FormatRenderer (DateFormat.getDateTimeInstance ()); } + // ---------------------------------------------------------------------------------// public static FormatRenderer getTimeRenderer () + // ---------------------------------------------------------------------------------// { return new FormatRenderer (DateFormat.getTimeInstance ()); } diff --git a/src/com/bytezone/diskbrowser/utilities/Utility.java b/src/com/bytezone/diskbrowser/utilities/Utility.java index 561182a..8fbd8ab 100644 --- a/src/com/bytezone/diskbrowser/utilities/Utility.java +++ b/src/com/bytezone/diskbrowser/utilities/Utility.java @@ -38,6 +38,13 @@ public class Utility return a + b; } + // ---------------------------------------------------------------------------------// + public static int dimension (int chars, int border, int size, int gap) + // ---------------------------------------------------------------------------------// + { + return border * 2 + chars * (size + gap) - gap; + } + // ---------------------------------------------------------------------------------// public static boolean find (byte[] buffer, byte[] key) // ---------------------------------------------------------------------------------//