pictures and quit handler

This commit is contained in:
Denis Molony 2018-07-26 13:43:07 +10:00
parent 2a79664404
commit 70e54cad1e
7 changed files with 99 additions and 54 deletions

View File

@ -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;

View File

@ -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++)
{

View File

@ -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;

View File

@ -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;
}

View File

@ -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<QuitListener> 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);
}
}

View File

@ -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

View File

@ -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);
}