From 70e54cad1efd3cfdfc477e3a588abfcb39bda3a3 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Thu, 26 Jul 2018 13:43:07 +1000 Subject: [PATCH] pictures and quit handler --- .../applefile/SHRPictureFile1.java | 37 ++++++---- .../applefile/SHRPictureFile2.java | 27 +++++--- .../diskbrowser/gui/CatalogPanel.java | 1 - .../diskbrowser/gui/DebuggingAction.java | 6 +- .../bytezone/diskbrowser/gui/DiskBrowser.java | 68 ++++++++++++------- .../bytezone/diskbrowser/gui/MenuHandler.java | 4 +- .../diskbrowser/gui/QuitListener.java | 10 +++ 7 files changed, 99 insertions(+), 54 deletions(-) create mode 100644 src/com/bytezone/diskbrowser/gui/QuitListener.java diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java index da22643..01b4a57 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile1.java @@ -24,25 +24,34 @@ public class SHRPictureFile1 extends HiResImage int len = HexFormatter.unsignedLong (buffer, ptr); if (len == 0) break; - // int nameLen = buffer[ptr + 4] & 0xFF; + String kind = HexFormatter.getPascalString (buffer, ptr + 4); byte[] data = new byte[Math.min (len, buffer.length - ptr)]; System.arraycopy (buffer, ptr, data, 0, data.length); - if ("MAIN".equals (kind)) + switch (kind) { - mainBlock = new Main (kind, data); - blocks.add (mainBlock); - } - else if ("MULTIPAL".equals (kind)) - { - multipalBlock = new Multipal (kind, data); - blocks.add (multipalBlock); - } - else - { - blocks.add (new Block (kind, data)); - System.out.println ("Unknown block type: " + kind + " in " + name); + case "MAIN": + mainBlock = new Main (kind, data); + blocks.add (mainBlock); + break; + + case "MULTIPAL": + multipalBlock = new Multipal (kind, data); + blocks.add (multipalBlock); + break; + + // case "SuperConvert": + // case "EOA ": // DeluxePaint + // case "PATS": + // case "Platinum Paint": + // blocks.add (new Block (kind, data)); + // break; + + default: + blocks.add (new Block (kind, data)); + System.out.println ("Unknown block type: " + kind + " in " + name); + break; } ptr += len; diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java index 22f2254..0113d06 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile2.java @@ -9,7 +9,7 @@ import com.bytezone.diskbrowser.utilities.HexFormatter; public class SHRPictureFile2 extends HiResImage { ColorTable[] colorTables; - byte[] scb; // 0xC1 aux=0 + byte[] scb; // see Graphics & Animation.2mg @@ -27,7 +27,7 @@ public class SHRPictureFile2 extends HiResImage "%s: PNT aux 0 (Paintworks Packed SHR Image) not written yet%n", name); break; - case 1: // Eagle/PackBytes - unpacks to PIC/$00 + case 1: // packed version of PIC/$00 this.buffer = unpackBytes (buffer); scb = new byte[200]; System.arraycopy (this.buffer, 32000, scb, 0, scb.length); @@ -37,17 +37,24 @@ public class SHRPictureFile2 extends HiResImage colorTables[i] = new ColorTable (i, this.buffer, 32256 + i * 32); break; - case 2: // handled in SHRPictureFile1 + case 2: // handled in SHRPictureFile1 break; - case 3: + case 3: // packed version of PIC/$01 System.out.printf ("%s: PNT aux 3 (Packed IIGS SHR Image) not written yet%n", name); break; - case 4: - System.out.printf ( - "%s: PNT aux 4 (Packed SHR Brooks Image) not written yet%n", name); + case 4: // packed version of PIC/$02 + System.out.printf ("%s: PNT aux 4 (Packed SHR Brooks Image) not tested yet%n", + name); + this.buffer = unpackBytes (buffer); + colorTables = new ColorTable[200]; + for (int i = 0; i < colorTables.length; i++) + { + colorTables[i] = new ColorTable (i, buffer, 32000 + i * 32); + colorTables[i].reverse (); + } break; default: @@ -64,7 +71,7 @@ public class SHRPictureFile2 extends HiResImage switch (auxType) { - case 0: // 32,768 + case 0: // unpacked version of PNT/$01 scb = new byte[200]; System.arraycopy (buffer, 32000, scb, 0, scb.length); @@ -73,11 +80,11 @@ public class SHRPictureFile2 extends HiResImage colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32); break; - case 1: + case 1: // unpacked version of PNT/$03 System.out.printf ("%s: PIC aux 1 not written yet%n", name); break; - case 2: // Brooks 38,400 + case 2: // unpacked version of PNT/$04 colorTables = new ColorTable[200]; for (int i = 0; i < colorTables.length; i++) { diff --git a/src/com/bytezone/diskbrowser/gui/CatalogPanel.java b/src/com/bytezone/diskbrowser/gui/CatalogPanel.java index c75ba48..7a54fa3 100755 --- a/src/com/bytezone/diskbrowser/gui/CatalogPanel.java +++ b/src/com/bytezone/diskbrowser/gui/CatalogPanel.java @@ -26,7 +26,6 @@ import javax.swing.tree.TreePath; import com.bytezone.common.FontAction.FontChangeEvent; import com.bytezone.common.FontAction.FontChangeListener; -import com.bytezone.common.QuitAction.QuitListener; import com.bytezone.diskbrowser.applefile.AppleFileSource; import com.bytezone.diskbrowser.disk.DualDosDisk; import com.bytezone.diskbrowser.disk.FormattedDisk; diff --git a/src/com/bytezone/diskbrowser/gui/DebuggingAction.java b/src/com/bytezone/diskbrowser/gui/DebuggingAction.java index 992152b..3f254e4 100644 --- a/src/com/bytezone/diskbrowser/gui/DebuggingAction.java +++ b/src/com/bytezone/diskbrowser/gui/DebuggingAction.java @@ -1,8 +1,6 @@ package com.bytezone.diskbrowser.gui; -import java.awt.Toolkit; import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; import javax.swing.AbstractAction; import javax.swing.Action; @@ -16,9 +14,9 @@ public class DebuggingAction extends AbstractAction public DebuggingAction (DataPanel owner) { super ("Debugging"); - int mask = Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask (); - putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_D, mask)); putValue (Action.SHORT_DESCRIPTION, "Show debugging information"); + putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("ctrl D")); + // putValue (Action.MNEMONIC_KEY, KeyEvent.VK_D); this.owner = owner; } diff --git a/src/com/bytezone/diskbrowser/gui/DiskBrowser.java b/src/com/bytezone/diskbrowser/gui/DiskBrowser.java index c8d140f..0e54786 100755 --- a/src/com/bytezone/diskbrowser/gui/DiskBrowser.java +++ b/src/com/bytezone/diskbrowser/gui/DiskBrowser.java @@ -2,18 +2,15 @@ package com.bytezone.diskbrowser.gui; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Desktop; import java.awt.EventQueue; -import java.awt.desktop.QuitEvent; -import java.awt.desktop.QuitHandler; -import java.awt.desktop.QuitResponse; +import java.util.ArrayList; +import java.util.List; import java.util.prefs.Preferences; import javax.swing.*; -import com.apple.eawt.Application; import com.bytezone.common.Platform; -import com.bytezone.common.QuitAction; -import com.bytezone.common.QuitAction.QuitListener; import com.bytezone.common.State; import com.bytezone.diskbrowser.duplicates.RootFolderData; @@ -67,7 +64,7 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi RefreshTreeAction refreshTreeAction = new RefreshTreeAction (catalogPanel); // PreferencesAction preferencesAction = new PreferencesAction (this, prefs); AbstractAction print = new PrintAction (dataPanel); - AboutAction aboutAction = new AboutAction (); + // AboutAction aboutAction = new AboutAction (); HideCatalogAction hideCatalogAction = new HideCatalogAction (this, catalogBorderPanel); HideLayoutAction hideLayoutAction = new HideLayoutAction (this, layoutBorderPanel); @@ -81,7 +78,7 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi // toolBar.add (preferencesAction); toolBar.add (duplicateAction); toolBar.add (print); - toolBar.add (aboutAction); + // toolBar.add (aboutAction); // set the listeners catalogPanel.addDiskSelectionListener (this); @@ -114,7 +111,7 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi // set the MenuItem Actions menuHandler.printItem.setAction (print); // menuHandler.addHelpMenuAction (preferencesAction, "prefs"); - menuHandler.addHelpMenuAction (aboutAction, "about"); + // menuHandler.addHelpMenuAction (aboutAction, "about"); menuHandler.refreshTreeItem.setAction (refreshTreeAction); menuHandler.rootItem.setAction (rootDirectoryAction); menuHandler.showCatalogItem.setAction (hideCatalogAction); @@ -123,29 +120,26 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi menuHandler.duplicateItem.setAction (duplicateAction); menuHandler.closeTabItem.setAction (closeTabAction); - final QuitAction quitAction = Platform.setQuit (this, prefs, menuHandler.fileMenu); + // final QuitAction quitAction = Platform.setQuit (this, prefs, menuHandler.fileMenu); - quitAction.addQuitListener (menuHandler); - quitAction.addQuitListener (menuHandler.fontAction); - quitAction.addQuitListener (catalogPanel); - quitAction.addQuitListener (this); + addQuitListener (menuHandler); + addQuitListener (catalogPanel); + addQuitListener (this); - if (Platform.MAC) - Application.getApplication ().setQuitHandler (new QuitHandler () - { - @Override - public void handleQuitRequestWith (QuitEvent e, QuitResponse response) - { - quitAction.quit (); - } - }); + Desktop desktop = Desktop.getDesktop (); + desktop.setAboutHandler (e -> JOptionPane.showMessageDialog (null, + "Author - Denis Molony\nGitHub - https://github.com/dmolony/DiskBrowser", + "About DiskBrowser", JOptionPane.INFORMATION_MESSAGE)); + // desktop.setPreferencesHandler ( + // e -> JOptionPane.showMessageDialog (null, "Preferences dialog")); + desktop.setQuitHandler ( (e, r) -> fireQuitEvent ()); catalogPanel.setCloseTabAction (closeTabAction); pack (); // restore the menuHandler items before they are referenced - quitAction.restore (); + fireRestoreEvent (); diskLayoutPanel.setFree (menuHandler.showFreeSectorsItem.isSelected ()); // Remove the two optional panels if they were previously hidden @@ -202,4 +196,30 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi } }); } + + List quitListeners = new ArrayList<> (); + + public void addQuitListener (QuitListener listener) + { + quitListeners.add (listener); + } + + public void removeQuitListener (QuitListener listener) + { + quitListeners.remove (listener); + } + + private void fireQuitEvent () + { + for (QuitListener listener : quitListeners) + listener.quit (prefs); + + System.exit (0); + } + + private void fireRestoreEvent () + { + for (QuitListener listener : quitListeners) + listener.restore (prefs); + } } \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/gui/MenuHandler.java b/src/com/bytezone/diskbrowser/gui/MenuHandler.java index 381ee9d..4e415b3 100755 --- a/src/com/bytezone/diskbrowser/gui/MenuHandler.java +++ b/src/com/bytezone/diskbrowser/gui/MenuHandler.java @@ -11,7 +11,6 @@ import javax.swing.*; import com.bytezone.common.EnvironmentAction; import com.bytezone.common.FontAction; -import com.bytezone.common.QuitAction.QuitListener; import com.bytezone.diskbrowser.applefile.HiResImage; import com.bytezone.diskbrowser.applefile.Palette; import com.bytezone.diskbrowser.applefile.PaletteFactory; @@ -204,6 +203,7 @@ public class MenuHandler // prefs.putBoolean (PREFS_DEBUGGING, debuggingItem.isSelected ()); prefs.putInt (PREFS_PALETTE, HiResImage.getPaletteFactory ().getCurrentPaletteIndex ()); + fontAction.quit (prefs); } @Override @@ -235,6 +235,8 @@ public class MenuHandler HiResImage.setDefaultColourQuirks (colourQuirksItem.isSelected ()); HiResImage.setDefaultMonochrome (monochromeItem.isSelected ()); VisicalcFile.setDefaultDebug (debuggingItem.isSelected ()); + + fontAction.restore (prefs); } @Override diff --git a/src/com/bytezone/diskbrowser/gui/QuitListener.java b/src/com/bytezone/diskbrowser/gui/QuitListener.java new file mode 100644 index 0000000..0347a6e --- /dev/null +++ b/src/com/bytezone/diskbrowser/gui/QuitListener.java @@ -0,0 +1,10 @@ +package com.bytezone.diskbrowser.gui; + +import java.util.prefs.Preferences; + +public interface QuitListener +{ + public void quit (Preferences preferences); + + public void restore (Preferences preferences); +}