This commit is contained in:
Denis Molony 2021-09-19 17:09:34 +10:00
parent 4a03c411fc
commit fb748df4ae
6 changed files with 94 additions and 90 deletions

View File

@ -89,9 +89,9 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
{ {
if (evt.getPropertyName ().equals ("RootDirectory")) if (evt.getPropertyName ().equals ("RootDirectory"))
rootDirectoryChanged ((File) evt.getOldValue (), (File) evt.getNewValue ()); rootDirectoryChanged ((File) evt.getOldValue (), (File) evt.getNewValue ());
// else // else
// closeCurrentTab (); // closeCurrentTab ();
// System.out.println (evt.getPropertyName ()); // System.out.println (evt.getPropertyName ());
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -158,8 +158,8 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
tab.refresh (); tab.refresh ();
// Any newly created disk needs to appear in the FileSystemTab's tree // Any newly created disk needs to appear in the FileSystemTab's tree
if (tab instanceof AppleDiskTab) if (tab instanceof AppleDiskTab appleDiskTab)
fileTab.replaceDisk (((AppleDiskTab) tab).disk); fileTab.replaceDisk (appleDiskTab.disk);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -221,8 +221,8 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
FormattedDisk fd = ((AppleDiskTab) selectedTab).disk; FormattedDisk fd = ((AppleDiskTab) selectedTab).disk;
prefs.put (prefsLastDiskUsed, fd.getAbsolutePath ()); prefs.put (prefsLastDiskUsed, fd.getAbsolutePath ());
if (fd instanceof HybridDisk) if (fd instanceof HybridDisk hybridDisk)
prefs.putInt (prefsLastDosUsed, ((HybridDisk) fd).getCurrentDiskNo ()); prefs.putInt (prefsLastDosUsed, hybridDisk.getCurrentDiskNo ());
else else
prefs.putInt (prefsLastDosUsed, -1); prefs.putInt (prefsLastDosUsed, -1);
@ -231,16 +231,16 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
{ {
EventObject event = redoEvent.value; EventObject event = redoEvent.value;
if (event instanceof FileSelectedEvent) if (event instanceof FileSelectedEvent fileSelectedEvent)
{ {
AppleFileSource afs = ((FileSelectedEvent) event).appleFileSource; AppleFileSource afs = fileSelectedEvent.appleFileSource;
prefs.put (prefsLastFileUsed, afs == null ? "" : afs.getUniqueName ()); prefs.put (prefsLastFileUsed, afs == null ? "" : afs.getUniqueName ());
prefs.put (prefsLastSectorsUsed, ""); prefs.put (prefsLastSectorsUsed, "");
} }
else if (event instanceof SectorSelectedEvent) else if (event instanceof SectorSelectedEvent sectorSelectedEvent)
{ {
prefs.put (prefsLastFileUsed, ""); prefs.put (prefsLastFileUsed, "");
prefs.put (prefsLastSectorsUsed, ((SectorSelectedEvent) event).toText ()); prefs.put (prefsLastSectorsUsed, sectorSelectedEvent.toText ());
} }
} }
} }
@ -273,8 +273,8 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
if (diskEvent != null) if (diskEvent != null)
{ {
fd1 = diskEvent.getFormattedDisk (); fd1 = diskEvent.getFormattedDisk ();
if (lastDosUsed >= 0 && fd1 instanceof HybridDisk) if (lastDosUsed >= 0 && fd1 instanceof HybridDisk hybridDisk)
((HybridDisk) fd1).setCurrentDiskNo (lastDosUsed); hybridDisk.setCurrentDiskNo (lastDosUsed);
} }
} }
else else
@ -399,13 +399,13 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
{ {
case "DiskEvent": case "DiskEvent":
case "FileNodeEvent": case "FileNodeEvent":
if (tab instanceof FileSystemTab) if (tab instanceof FileSystemTab fileSystemTab)
((FileSystemTab) tab).redoEvent (event); fileSystemTab.redoEvent (event);
break; break;
case "FileEvent": case "FileEvent":
if (tab instanceof AppleDiskTab) if (tab instanceof AppleDiskTab appleDiskTab)
((AppleDiskTab) tab).redoEvent (event); appleDiskTab.redoEvent (event);
break; break;
case "SectorEvent": case "SectorEvent":
@ -426,8 +426,8 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
{ {
// user has clicked in the DiskLayoutPanel, so turn off any current file selection // user has clicked in the DiskLayoutPanel, so turn off any current file selection
Tab tab = (Tab) getSelectedComponent (); Tab tab = (Tab) getSelectedComponent ();
if (tab instanceof AppleDiskTab) if (tab instanceof AppleDiskTab appleDiskTab)
((AppleDiskTab) tab).tree.setSelectionPath (null); appleDiskTab.tree.setSelectionPath (null);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -462,7 +462,7 @@ class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionL
FileNode node = (FileNode) selectedNode.getUserObject (); FileNode node = (FileNode) selectedNode.getUserObject ();
if (node.file.isDirectory ()) if (node.file.isDirectory ())
{ {
// lister.catalogLister.setNode (selectedNode); // lister.catalogLister.setNode (selectedNode);
} }
else if (e.getClickCount () == 2) else if (e.getClickCount () == 2)
addDiskPanel (node.getFormattedDisk (), true); addDiskPanel (node.getFormattedDisk (), true);

View File

@ -262,8 +262,8 @@ class DiskLayoutPanel extends JPanel implements DiskSelectionListener,
private void checkCorrectDisk (FormattedDisk newDisk) private void checkCorrectDisk (FormattedDisk newDisk)
{ {
if (newDisk instanceof HybridDisk) if (newDisk instanceof HybridDisk hybridDisk)
newDisk = ((HybridDisk) newDisk).getCurrentDisk (); // never set to a hybrid disk newDisk = hybridDisk.getCurrentDisk (); // never set to a hybrid disk
if (newDisk != diskLayoutImage.getDisk ()) if (newDisk != diskLayoutImage.getDisk ())
{ {
LayoutDetails layout = new LayoutDetails (newDisk); LayoutDetails layout = new LayoutDetails (newDisk);

View File

@ -43,7 +43,7 @@ public class OutputPanel extends JTabbedPane
{ {
private static final int TEXT_WIDTH = 65; private static final int TEXT_WIDTH = 65;
// final MenuHandler menuHandler; // final MenuHandler menuHandler;
private final JTextArea formattedText; private final JTextArea formattedText;
private final JTextArea hexText; private final JTextArea hexText;
private final JTextArea disassemblyText; private final JTextArea disassemblyText;
@ -78,12 +78,11 @@ public class OutputPanel extends JTabbedPane
public OutputPanel (MenuHandler menuHandler) public OutputPanel (MenuHandler menuHandler)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
// this.menuHandler = mh;
setTabPlacement (SwingConstants.BOTTOM); setTabPlacement (SwingConstants.BOTTOM);
formattedText = new JTextArea (10, TEXT_WIDTH); formattedText = new JTextArea (10, TEXT_WIDTH);
formattedPane = setPanel (formattedText, "Formatted"); formattedPane = setPanel (formattedText, "Formatted");
// formattedText.setLineWrap (prefs.getBoolean (MenuHandler.PREFS_LINE_WRAP, true)); // formattedText.setLineWrap (prefs.getBoolean (MenuHandler.PREFS_LINE_WRAP, true));
formattedText.setText ("Please use the 'File->Set HOME folder...' command to " formattedText.setText ("Please use the 'File->Set HOME folder...' command to "
+ "\ntell DiskBrowser where your Apple disks are located." + "\ntell DiskBrowser where your Apple disks are located."
+ "\n\nTo see the contents of a disk in more detail, double-click" + "\n\nTo see the contents of a disk in more detail, double-click"
@ -183,9 +182,8 @@ public class OutputPanel extends JTabbedPane
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
HiResImage.getPaletteFactory ().setCurrentPalette (palette); HiResImage.getPaletteFactory ().setCurrentPalette (palette);
if (currentDataSource instanceof HiResImage) if (currentDataSource instanceof HiResImage image)
{ {
HiResImage image = (HiResImage) currentDataSource;
image.setPalette (); image.setPalette ();
imagePanel.setImage (image.getImage ()); imagePanel.setImage (image.getImage ());
} }
@ -196,9 +194,8 @@ public class OutputPanel extends JTabbedPane
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
Palette palette = HiResImage.getPaletteFactory ().cyclePalette (direction); Palette palette = HiResImage.getPaletteFactory ().cyclePalette (direction);
if (currentDataSource instanceof HiResImage) if (currentDataSource instanceof HiResImage image)
{ {
HiResImage image = (HiResImage) currentDataSource;
image.setPalette (); image.setPalette ();
imagePanel.setImage (image.getImage ()); imagePanel.setImage (image.getImage ());
} }
@ -231,9 +228,8 @@ public class OutputPanel extends JTabbedPane
public void setColourQuirks (boolean value) public void setColourQuirks (boolean value)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (currentDataSource instanceof HiResImage) if (currentDataSource instanceof HiResImage image)
{ {
HiResImage image = (HiResImage) currentDataSource;
image.setColourQuirks (value); image.setColourQuirks (value);
imagePanel.setImage (image.getImage ()); imagePanel.setImage (image.getImage ());
} }
@ -243,9 +239,8 @@ public class OutputPanel extends JTabbedPane
public void setMonochrome (boolean value) public void setMonochrome (boolean value)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (currentDataSource instanceof HiResImage) if (currentDataSource instanceof HiResImage image)
{ {
HiResImage image = (HiResImage) currentDataSource;
image.setMonochrome (value); image.setMonochrome (value);
imagePanel.setImage (image.getImage ()); imagePanel.setImage (image.getImage ());
} }
@ -256,22 +251,16 @@ public class OutputPanel extends JTabbedPane
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
imagePanel.setScale (scale); imagePanel.setScale (scale);
if (currentDataSource instanceof HiResImage) if (currentDataSource instanceof HiResImage image)
{
HiResImage image = (HiResImage) currentDataSource;
imagePanel.setImage (image.getImage ()); imagePanel.setImage (image.getImage ());
}
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public void update () public void update ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (currentDataSource instanceof HiResImage) if (currentDataSource instanceof HiResImage image)
{
HiResImage image = (HiResImage) currentDataSource;
imagePanel.setImage (image.getImage ()); imagePanel.setImage (image.getImage ());
}
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -480,7 +469,6 @@ public class OutputPanel extends JTabbedPane
{ {
setSelectedIndex (0); setSelectedIndex (0);
setDataSource (event.getFileNode ()); setDataSource (event.getFileNode ());
// FileNode node = event.getFileNode ();
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//

View File

@ -104,20 +104,22 @@ public final class Utility
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
// public static int getLong (byte[] buffer, int ptr) // public static int getLong (byte[] buffer, int ptr)
// // ---------------------------------------------------------------------------------// // //
// { // ---------------------------------------------------------------------------------//
// return getWord (buffer, ptr) + getWord (buffer, ptr + 2) * 0x10000; // {
// } // return getWord (buffer, ptr) + getWord (buffer, ptr + 2) * 0x10000;
// }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
// public static int getWord (byte[] buffer, int ptr) // public static int getWord (byte[] buffer, int ptr)
// // ---------------------------------------------------------------------------------// // //
// { // ---------------------------------------------------------------------------------//
// int a = (buffer[ptr + 1] & 0xFF) << 8; // {
// int b = buffer[ptr] & 0xFF; // int a = (buffer[ptr + 1] & 0xFF) << 8;
// return a + b; // int b = buffer[ptr] & 0xFF;
// } // return a + b;
// }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public static int intValue (byte b1, byte b2) public static int intValue (byte b1, byte b2)
@ -137,19 +139,21 @@ public final class Utility
public static int getLong (byte[] buffer, int ptr) public static int getLong (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (ptr >= buffer.length) try
{ {
System.out.printf ("Index out of range (getLong): %08X%n", ptr); int val = 0;
for (int i = 3; i >= 0; i--)
{
val <<= 8;
val += buffer[ptr + i] & 0xFF;
}
return val;
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.printf ("Index out of range (getLong): %08X %<d%n", ptr);
return 0; return 0;
} }
int val = 0;
for (int i = 3; i >= 0; i--)
{
val <<= 8;
val += buffer[ptr + i] & 0xFF;
}
return val;
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -166,41 +170,52 @@ public final class Utility
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
// public static int getWordBigEndian (byte[] buffer, int ptr) // public static int getWordBigEndian (byte[] buffer, int ptr)
// // ---------------------------------------------------------------------------------// // //
// { // ---------------------------------------------------------------------------------//
// int val = 0; // {
// for (int i = 0; i < 2; i++) // int val = 0;
// { // for (int i = 0; i < 2; i++)
// val <<= 8; // {
// val += buffer[ptr + i] & 0xFF; // val <<= 8;
// } // val += buffer[ptr + i] & 0xFF;
// return val; // }
// } // return val;
// }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public static int getShort (byte[] buffer, int ptr) public static int getShort (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (ptr >= buffer.length) try
{ {
System.out.printf ("Index out of range (getShort): %04X%n", ptr); return (buffer[ptr] & 0xFF) | ((buffer[ptr + 1] & 0xFF) << 8);
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.printf ("Index out of range (getShort): %04X %<d%n", ptr);
return 0; return 0;
} }
return (buffer[ptr] & 0xFF) | ((buffer[ptr + 1] & 0xFF) << 8);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public static int signedShort (byte[] buffer, int ptr) public static int signedShort (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (ptr >= buffer.length) // if (ptr >= buffer.length)
// {
// System.out.println ("Index out of range (signed short): " + ptr);
// return 0;
// }
try
{ {
System.out.println ("Index out of range (signed short): " + ptr); return (short) ((buffer[ptr] & 0xFF) | ((buffer[ptr + 1] & 0xFF) << 8));
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.printf ("Index out of range (signedShort): %04X %<d%n", ptr);
return 0; return 0;
} }
return (short) ((buffer[ptr] & 0xFF) | ((buffer[ptr + 1] & 0xFF) << 8));
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -220,7 +235,7 @@ public final class Utility
public static LocalDateTime getAppleDate (byte[] buffer, int offset) public static LocalDateTime getAppleDate (byte[] buffer, int offset)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
// int yymmdd = readShort (buffer, offset); // int yymmdd = readShort (buffer, offset);
int yymmdd = getShort (buffer, offset); int yymmdd = getShort (buffer, offset);
if (yymmdd != 0) if (yymmdd != 0)
{ {
@ -297,11 +312,12 @@ public final class Utility
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
// public static int readShort (byte[] buffer, int ptr) // public static int readShort (byte[] buffer, int ptr)
// // ---------------------------------------------------------------------------------// // //
// { // ---------------------------------------------------------------------------------//
// return (buffer[ptr] & 0xFF) | (buffer[ptr + 1] & 0xFF) << 8; // {
// } // return (buffer[ptr] & 0xFF) | (buffer[ptr + 1] & 0xFF) << 8;
// }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public static int readTriple (byte[] buffer, int ptr) public static int readTriple (byte[] buffer, int ptr)

View File

@ -26,7 +26,7 @@ class Average extends ValueListFunction
for (Value v : list) for (Value v : list)
{ {
if (v instanceof Cell && ((Cell) v).isCellType (CellType.EMPTY)) if (v instanceof Cell cell && cell.isCellType (CellType.EMPTY))
continue; continue;
v.calculate (); v.calculate ();

View File

@ -27,7 +27,7 @@ class Count extends ValueListFunction
else else
for (Value v : list) for (Value v : list)
{ {
if (v instanceof Cell && ((Cell) v).isCellType (CellType.EMPTY)) if (v instanceof Cell cell && cell.isCellType (CellType.EMPTY))
continue; continue;
v.calculate (); // is this required? v.calculate (); // is this required?