mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-10-08 03:56:40 +00:00
tidying
This commit is contained in:
parent
74452add39
commit
bca4858087
@ -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 ()
|
||||
|
@ -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<Icon> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
+ "]";
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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 ());
|
||||
}
|
||||
|
@ -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)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
Loading…
Reference in New Issue
Block a user