mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-02-07 11:30:39 +00:00
method header lines
This commit is contained in:
parent
1043b8964f
commit
343e5da6d9
@ -1,57 +1,65 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
public class AboutAction extends DefaultAction
|
||||
{
|
||||
public AboutAction ()
|
||||
{
|
||||
super ("About...", "Display build information", "/com/bytezone/diskbrowser/icons/");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt A"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_A);
|
||||
|
||||
setIcon (Action.SMALL_ICON, "information_16.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "information_32.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
about ();
|
||||
}
|
||||
|
||||
public void about ()
|
||||
{
|
||||
// int build = 0;
|
||||
// String buildDate = "<no date>";
|
||||
// Properties props = new Properties ();
|
||||
// InputStream in = this.getClass ().getResourceAsStream ("build.properties");
|
||||
// if (in != null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// props.load (in);
|
||||
// in.close ();
|
||||
// build = Integer.parseInt (props.getProperty ("build.number"));
|
||||
// buildDate = props.getProperty ("build.date");
|
||||
// }
|
||||
// catch (IOException e1)
|
||||
// {
|
||||
// System.out.println ("Properties file not found");
|
||||
// }
|
||||
// }
|
||||
|
||||
JOptionPane.showMessageDialog (null, "Author - Denis Molony" //
|
||||
// + "\nBuild #" + String.format ("%d", build) + " - " + buildDate + "\n" //
|
||||
+ "\nGitHub - https://github.com/dmolony/DiskBrowser", //
|
||||
// + "\nContact - dmolony@iinet.net.au", //
|
||||
"About DiskBrowser", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class AboutAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
// ---------------------------------------------------------------------------------//
|
||||
AboutAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("About...", "Display build information", "/com/bytezone/diskbrowser/icons/");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt A"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_A);
|
||||
|
||||
setIcon (Action.SMALL_ICON, "information_16.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "information_32.png");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
about ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void about ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// int build = 0;
|
||||
// String buildDate = "<no date>";
|
||||
// Properties props = new Properties ();
|
||||
// InputStream in = this.getClass ().getResourceAsStream ("build.properties");
|
||||
// if (in != null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// props.load (in);
|
||||
// in.close ();
|
||||
// build = Integer.parseInt (props.getProperty ("build.number"));
|
||||
// buildDate = props.getProperty ("build.date");
|
||||
// }
|
||||
// catch (IOException e1)
|
||||
// {
|
||||
// System.out.println ("Properties file not found");
|
||||
// }
|
||||
// }
|
||||
|
||||
JOptionPane.showMessageDialog (null, "Author - Denis Molony" //
|
||||
// + "\nBuild #" + String.format ("%d", build) + " - " + buildDate + "\n" //
|
||||
+ "\nGitHub - https://github.com/dmolony/DiskBrowser", //
|
||||
// + "\nContact - dmolony@iinet.net.au", //
|
||||
"About DiskBrowser", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
@ -1,180 +1,206 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
/*****************************************************************************************
|
||||
* JPanel used to display a scrolling JTree containing details of a single disk. The JTree
|
||||
* consists entirely of AppleFileSource objects. Any number of these objects are contained
|
||||
* in Catalog Panel, along with a single FileSystemTab.
|
||||
****************************************************************************************/
|
||||
|
||||
import java.awt.Font;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.DiskFactory;
|
||||
import com.bytezone.diskbrowser.disk.DualDosDisk;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
|
||||
|
||||
class AppleDiskTab extends AbstractTab
|
||||
{
|
||||
FormattedDisk disk;
|
||||
|
||||
// restoring from a file selection
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font, FileSelectedEvent event)
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
create (disk);
|
||||
redoHandler.fileSelected (event);
|
||||
}
|
||||
|
||||
// restoring from a sector selection
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font, SectorSelectedEvent event)
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
create (disk);
|
||||
redoHandler.sectorSelected (event);
|
||||
}
|
||||
|
||||
// This constructor is only called when lastFileUsed is not null, but the disk
|
||||
// couldn't find the file entry. Either the file has been deleted, or it is a disk
|
||||
// with redefined files (Wizardry, Infocom etc).
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font, String lastFileUsed)
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
System.out.println ("****************** File not found");
|
||||
create (disk);
|
||||
// System.out.println ("ooh - couldn't find the previous file");
|
||||
DefaultMutableTreeNode node = findNode (lastFileUsed);
|
||||
if (node != null)
|
||||
{
|
||||
AppleFileSource afs = (AppleFileSource) node.getUserObject ();
|
||||
FileSelectedEvent event = new FileSelectedEvent (this, afs);
|
||||
redoHandler.fileSelected (event);
|
||||
}
|
||||
}
|
||||
|
||||
// User is selecting a new disk from the catalog
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font)
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
create (disk);
|
||||
|
||||
// select Catalog
|
||||
AppleFileSource afs = (AppleFileSource) findNode (2).getUserObject ();
|
||||
if (afs == null)
|
||||
afs = (AppleFileSource) findNode (1).getUserObject (); // select Disk
|
||||
redoHandler.fileSelected (new FileSelectedEvent (this, afs));
|
||||
}
|
||||
|
||||
private void create (FormattedDisk disk)
|
||||
{
|
||||
this.disk = disk;
|
||||
setTree (disk.getCatalogTree ());
|
||||
setSelectionListener (tree);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate ()
|
||||
{
|
||||
// System.out.println ("=========== Activating AppleDiskTab =============");
|
||||
eventHandler.redo = true;
|
||||
eventHandler.fireDiskSelectionEvent (disk);
|
||||
eventHandler.redo = false;
|
||||
tree.setSelectionPath (null); // turn off any current selection to force an event
|
||||
redoHandler.setCurrentData (redoData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh () // called when the user gives ALT-R command
|
||||
{
|
||||
Object o = getSelectedObject ();
|
||||
String currentFile = (o == null) ? null : ((AppleFileSource) o).getUniqueName ();
|
||||
disk = DiskFactory.createDisk (disk.getAbsolutePath ());
|
||||
setTree (disk.getCatalogTree ());
|
||||
setSelectionListener (tree);
|
||||
selectNode (currentFile);
|
||||
}
|
||||
|
||||
private void selectNode (String nodeName)
|
||||
{
|
||||
DefaultMutableTreeNode selectNode = null;
|
||||
if (nodeName != null)
|
||||
selectNode = findNode (nodeName);
|
||||
if (selectNode == null)
|
||||
selectNode = findNode (2);
|
||||
if (selectNode != null)
|
||||
showNode (selectNode);
|
||||
else
|
||||
System.out.println ("First node not found");
|
||||
}
|
||||
|
||||
void redoEvent (RedoEvent event)
|
||||
{
|
||||
AppleFileSource afs = ((FileSelectedEvent) event.value).appleFileSource;
|
||||
FileSelectedEvent fileSelectedEvent = (FileSelectedEvent) event.value;
|
||||
if (fileSelectedEvent.volumeNo >= 0)
|
||||
{
|
||||
DualDosDisk ddd = (DualDosDisk) afs.getFormattedDisk ().getParent ();
|
||||
ddd.setCurrentDiskNo (fileSelectedEvent.volumeNo);
|
||||
}
|
||||
selectNode (fileSelectedEvent.appleFileSource.getUniqueName ());
|
||||
}
|
||||
|
||||
private DefaultMutableTreeNode findNode (String nodeName)
|
||||
{
|
||||
DefaultMutableTreeNode rootNode = getRootNode ();
|
||||
|
||||
// check for multi-volume disk (only search the current branch)
|
||||
FormattedDisk fd = ((AppleFileSource) rootNode.getUserObject ()).getFormattedDisk ();
|
||||
if (fd instanceof DualDosDisk)
|
||||
{
|
||||
int volume = ((DualDosDisk) fd).getCurrentDiskNo ();
|
||||
rootNode = (DefaultMutableTreeNode) rootNode.getChildAt (volume);
|
||||
}
|
||||
|
||||
Enumeration<TreeNode> children = rootNode.breadthFirstEnumeration ();
|
||||
while (children.hasMoreElements ())
|
||||
{
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement ();
|
||||
Object userObject = node.getUserObject ();
|
||||
if (userObject instanceof AppleFileSource
|
||||
&& nodeName.equals (((AppleFileSource) userObject).getUniqueName ()))
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean contains (FormattedDisk disk)
|
||||
{
|
||||
return this.disk.getAbsolutePath ().equals (disk.getAbsolutePath ());
|
||||
}
|
||||
|
||||
// This action is triggered by AppleDiskTab.selectNode (String), which calls
|
||||
// AbstractTab.showNode (DefaultMutableTreeNode). That will trigger this listener
|
||||
// ONLY if the value is different, so it is set to null first to force the event.
|
||||
private void setSelectionListener (JTree tree)
|
||||
{
|
||||
tree.addTreeSelectionListener (new TreeSelectionListener ()
|
||||
{
|
||||
@Override
|
||||
public void valueChanged (TreeSelectionEvent e)
|
||||
{
|
||||
// A null happens when there is a click in the DiskLayoutPanel, in order
|
||||
// to turn off the currently selected file
|
||||
AppleFileSource afs = (AppleFileSource) getSelectedObject ();
|
||||
if (afs != null)
|
||||
eventHandler.fireFileSelectionEvent (afs);
|
||||
}
|
||||
});
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
/*****************************************************************************************
|
||||
* JPanel used to display a scrolling JTree containing details of a single disk. The JTree
|
||||
* consists entirely of AppleFileSource objects. Any number of these objects are contained
|
||||
* in Catalog Panel, along with a single FileSystemTab.
|
||||
****************************************************************************************/
|
||||
|
||||
import java.awt.Font;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.DiskFactory;
|
||||
import com.bytezone.diskbrowser.disk.DualDosDisk;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class AppleDiskTab extends AbstractTab
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
FormattedDisk disk;
|
||||
|
||||
// restoring from a file selection
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font, FileSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
create (disk);
|
||||
redoHandler.fileSelected (event);
|
||||
}
|
||||
|
||||
// restoring from a sector selection
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font, SectorSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
create (disk);
|
||||
redoHandler.sectorSelected (event);
|
||||
}
|
||||
|
||||
// This constructor is only called when lastFileUsed is not null, but the disk
|
||||
// couldn't find the file entry. Either the file has been deleted, or it is a disk
|
||||
// with redefined files (Wizardry, Infocom etc).
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font, String lastFileUsed)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
System.out.println ("****************** File not found");
|
||||
create (disk);
|
||||
// System.out.println ("ooh - couldn't find the previous file");
|
||||
DefaultMutableTreeNode node = findNode (lastFileUsed);
|
||||
if (node != null)
|
||||
{
|
||||
AppleFileSource afs = (AppleFileSource) node.getUserObject ();
|
||||
FileSelectedEvent event = new FileSelectedEvent (this, afs);
|
||||
redoHandler.fileSelected (event);
|
||||
}
|
||||
}
|
||||
|
||||
// User is selecting a new disk from the catalog
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public AppleDiskTab (FormattedDisk disk, DiskAndFileSelector selector,
|
||||
RedoHandler redoHandler, Font font)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (redoHandler, selector, font);
|
||||
create (disk);
|
||||
|
||||
// select Catalog
|
||||
AppleFileSource afs = (AppleFileSource) findNode (2).getUserObject ();
|
||||
if (afs == null)
|
||||
afs = (AppleFileSource) findNode (1).getUserObject (); // select Disk
|
||||
redoHandler.fileSelected (new FileSelectedEvent (this, afs));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void create (FormattedDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.disk = disk;
|
||||
setTree (disk.getCatalogTree ());
|
||||
setSelectionListener (tree);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void activate ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// System.out.println ("=========== Activating AppleDiskTab =============");
|
||||
eventHandler.redo = true;
|
||||
eventHandler.fireDiskSelectionEvent (disk);
|
||||
eventHandler.redo = false;
|
||||
tree.setSelectionPath (null); // turn off any current selection to force an event
|
||||
redoHandler.setCurrentData (redoData);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void refresh () // called when the user gives ALT-R command
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Object o = getSelectedObject ();
|
||||
String currentFile = (o == null) ? null : ((AppleFileSource) o).getUniqueName ();
|
||||
disk = DiskFactory.createDisk (disk.getAbsolutePath ());
|
||||
setTree (disk.getCatalogTree ());
|
||||
setSelectionListener (tree);
|
||||
selectNode (currentFile);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void selectNode (String nodeName)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
DefaultMutableTreeNode selectNode = null;
|
||||
if (nodeName != null)
|
||||
selectNode = findNode (nodeName);
|
||||
if (selectNode == null)
|
||||
selectNode = findNode (2);
|
||||
if (selectNode != null)
|
||||
showNode (selectNode);
|
||||
else
|
||||
System.out.println ("First node not found");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void redoEvent (RedoEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
AppleFileSource afs = ((FileSelectedEvent) event.value).appleFileSource;
|
||||
FileSelectedEvent fileSelectedEvent = (FileSelectedEvent) event.value;
|
||||
if (fileSelectedEvent.volumeNo >= 0)
|
||||
{
|
||||
DualDosDisk ddd = (DualDosDisk) afs.getFormattedDisk ().getParent ();
|
||||
ddd.setCurrentDiskNo (fileSelectedEvent.volumeNo);
|
||||
}
|
||||
selectNode (fileSelectedEvent.appleFileSource.getUniqueName ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private DefaultMutableTreeNode findNode (String nodeName)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
DefaultMutableTreeNode rootNode = getRootNode ();
|
||||
|
||||
// check for multi-volume disk (only search the current branch)
|
||||
FormattedDisk fd = ((AppleFileSource) rootNode.getUserObject ()).getFormattedDisk ();
|
||||
if (fd instanceof DualDosDisk)
|
||||
{
|
||||
int volume = ((DualDosDisk) fd).getCurrentDiskNo ();
|
||||
rootNode = (DefaultMutableTreeNode) rootNode.getChildAt (volume);
|
||||
}
|
||||
|
||||
Enumeration<TreeNode> children = rootNode.breadthFirstEnumeration ();
|
||||
while (children.hasMoreElements ())
|
||||
{
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement ();
|
||||
Object userObject = node.getUserObject ();
|
||||
if (userObject instanceof AppleFileSource
|
||||
&& nodeName.equals (((AppleFileSource) userObject).getUniqueName ()))
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public boolean contains (FormattedDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return this.disk.getAbsolutePath ().equals (disk.getAbsolutePath ());
|
||||
}
|
||||
|
||||
// This action is triggered by AppleDiskTab.selectNode (String), which calls
|
||||
// AbstractTab.showNode (DefaultMutableTreeNode). That will trigger this listener
|
||||
// ONLY if the value is different, so it is set to null first to force the event.
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setSelectionListener (JTree tree)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
tree.addTreeSelectionListener (new TreeSelectionListener ()
|
||||
{
|
||||
@Override
|
||||
public void valueChanged (TreeSelectionEvent e)
|
||||
{
|
||||
// A null happens when there is a click in the DiskLayoutPanel, in order
|
||||
// to turn off the currently selected file
|
||||
AppleFileSource afs = (AppleFileSource) getSelectedObject ();
|
||||
if (afs != null)
|
||||
eventHandler.fireFileSelectionEvent (afs);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class AssemblerPreferences
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public boolean showTargets = true;
|
||||
public boolean showStrings = true;
|
||||
public boolean offsetFromZero = false;
|
||||
public boolean showHeader = true;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface AssemblerPreferencesListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void setAssemblerPreferences (AssemblerPreferences assemblerPreferences);
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class BasicPreferences
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public boolean splitRem = false;
|
||||
public boolean alignAssign = true;
|
||||
@ -11,8 +13,10 @@ public class BasicPreferences
|
||||
public int wrapPrintAt = 40;
|
||||
public int wrapRemAt = 60;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface BasicPreferencesListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void setBasicPreferences (BasicPreferences basicPreferences);
|
||||
}
|
||||
|
@ -8,11 +8,15 @@ import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class CloseTabAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
CatalogPanel catalogPanel;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public CloseTabAction (CatalogPanel catalogPanel)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Close Tab");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Close the current disk tab");
|
||||
@ -23,8 +27,10 @@ public class CloseTabAction extends AbstractAction
|
||||
this.catalogPanel = catalogPanel;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
catalogPanel.closeCurrentTab ();
|
||||
}
|
||||
|
@ -8,11 +8,15 @@ import javax.swing.Action;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class ColourQuirksAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final DataPanel owner;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public ColourQuirksAction (DataPanel owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Smear HGR");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Display pixels like a TV screen");
|
||||
@ -21,8 +25,10 @@ public class ColourQuirksAction extends AbstractAction
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
owner.setColourQuirks (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
|
@ -6,18 +6,25 @@ import javax.swing.JOptionPane;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class CreateDatabaseAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public CreateDatabaseAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Create Database", "Not working yet", null);
|
||||
// putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt A"));
|
||||
// putValue (Action.MNEMONIC_KEY, KeyEvent.VK_A);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
JOptionPane.showMessageDialog (null, "Coming soon...", "Database",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
@ -1,442 +1,504 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import com.bytezone.common.FontAction.FontChangeEvent;
|
||||
import com.bytezone.common.FontAction.FontChangeListener;
|
||||
import com.bytezone.diskbrowser.applefile.*;
|
||||
import com.bytezone.diskbrowser.applefile.PaletteFactory.CycleDirection;
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.SectorList;
|
||||
|
||||
class DataPanel extends JTabbedPane
|
||||
implements DiskSelectionListener, FileSelectionListener, SectorSelectionListener,
|
||||
FileNodeSelectionListener, FontChangeListener, BasicPreferencesListener,
|
||||
AssemblerPreferencesListener
|
||||
{
|
||||
private static final int TEXT_WIDTH = 65;
|
||||
private static final int BACKGROUND = 245;
|
||||
|
||||
private final JTextArea formattedText;
|
||||
private final JTextArea hexText;
|
||||
private final JTextArea disassemblyText;
|
||||
|
||||
// these two panes are interchangeable
|
||||
private final JScrollPane formattedPane;
|
||||
private final JScrollPane imagePane;
|
||||
|
||||
private final ImagePanel imagePanel; // internal class
|
||||
private boolean debugMode;
|
||||
|
||||
private boolean imageVisible = false;
|
||||
|
||||
// used to determine whether the text has been set
|
||||
boolean formattedTextValid;
|
||||
boolean hexTextValid;
|
||||
boolean assemblerTextValid;
|
||||
DataSource currentDataSource;
|
||||
|
||||
final MenuHandler menuHandler;
|
||||
|
||||
public DataPanel (MenuHandler mh)
|
||||
{
|
||||
this.menuHandler = mh;
|
||||
setTabPlacement (SwingConstants.BOTTOM);
|
||||
|
||||
formattedText = new JTextArea (10, TEXT_WIDTH);
|
||||
formattedPane = setPanel (formattedText, "Formatted");
|
||||
// formattedText.setLineWrap (prefs.getBoolean (MenuHandler.PREFS_LINE_WRAP, true));
|
||||
formattedText.setText ("Please use the 'File->Set HOME folder...' command to "
|
||||
+ "\ntell DiskBrowser where your Apple disks are located."
|
||||
+ "\n\nTo see the contents of a disk in more detail, double-click"
|
||||
+ "\nthe disk. You will then be able to select individual files to "
|
||||
+ "view completely.");
|
||||
|
||||
hexText = new JTextArea (10, TEXT_WIDTH);
|
||||
setPanel (hexText, "Hex dump");
|
||||
|
||||
disassemblyText = new JTextArea (10, TEXT_WIDTH);
|
||||
setPanel (disassemblyText, "Disassembly");
|
||||
|
||||
imagePanel = new ImagePanel ();
|
||||
imagePane =
|
||||
new JScrollPane (imagePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
|
||||
imagePane.setBorder (null);
|
||||
|
||||
imagePane.getVerticalScrollBar ().setUnitIncrement (50);
|
||||
imagePane.getHorizontalScrollBar ().setUnitIncrement (25);
|
||||
|
||||
addChangeListener (new ChangeListener ()
|
||||
{
|
||||
@Override
|
||||
public void stateChanged (ChangeEvent e)
|
||||
{
|
||||
switch (getSelectedIndex ())
|
||||
{
|
||||
case 0:
|
||||
if (!formattedTextValid)
|
||||
{
|
||||
if (currentDataSource == null)
|
||||
formattedText.setText ("");
|
||||
else
|
||||
setText (formattedText, currentDataSource.getText ());
|
||||
formattedTextValid = true;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!hexTextValid)
|
||||
{
|
||||
if (currentDataSource == null)
|
||||
hexText.setText ("");
|
||||
else
|
||||
setText (hexText, currentDataSource.getHexDump ());
|
||||
hexTextValid = true;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!assemblerTextValid)
|
||||
{
|
||||
if (currentDataSource == null)
|
||||
disassemblyText.setText ("");
|
||||
else
|
||||
setText (disassemblyText, currentDataSource.getAssembler ());
|
||||
assemblerTextValid = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println ("Invalid index selected in DataPanel");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LineWrapAction lineWrapAction = new LineWrapAction ();
|
||||
menuHandler.lineWrapItem.setAction (lineWrapAction);
|
||||
lineWrapAction.addListener (formattedText);
|
||||
|
||||
menuHandler.colourQuirksItem.setAction (new ColourQuirksAction (this));
|
||||
menuHandler.monochromeItem.setAction (new MonochromeAction (this));
|
||||
menuHandler.debuggingItem.setAction (new DebuggingAction (this));
|
||||
|
||||
// fill in the placeholders created by the MenuHandler
|
||||
List<Palette> palettes = HiResImage.getPalettes ();
|
||||
ButtonGroup buttonGroup = menuHandler.paletteGroup;
|
||||
Enumeration<AbstractButton> enumeration = buttonGroup.getElements ();
|
||||
int ndx = 0;
|
||||
while (enumeration.hasMoreElements ())
|
||||
{
|
||||
JCheckBoxMenuItem item = (JCheckBoxMenuItem) enumeration.nextElement ();
|
||||
item.setAction (new PaletteAction (this, palettes.get (ndx++)));
|
||||
}
|
||||
menuHandler.nextPaletteItem.setAction (new NextPaletteAction (this, buttonGroup));
|
||||
menuHandler.prevPaletteItem.setAction (new PreviousPaletteAction (this, buttonGroup));
|
||||
}
|
||||
|
||||
public void selectPalette (Palette palette)
|
||||
{
|
||||
HiResImage.getPaletteFactory ().setCurrentPalette (palette);
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setPalette ();
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
}
|
||||
|
||||
public Palette cyclePalette (CycleDirection direction)
|
||||
{
|
||||
Palette palette = HiResImage.getPaletteFactory ().cyclePalette (direction);
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setPalette ();
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
void setLineWrap (boolean lineWrap)
|
||||
{
|
||||
formattedText.setLineWrap (lineWrap);
|
||||
}
|
||||
|
||||
public void setColourQuirks (boolean value)
|
||||
{
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setColourQuirks (value);
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
}
|
||||
|
||||
public void setMonochrome (boolean value)
|
||||
{
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setMonochrome (value);
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
}
|
||||
|
||||
public void setDebug (boolean value)
|
||||
{
|
||||
debugMode = value;
|
||||
|
||||
if (currentDataSource instanceof VisicalcFile)
|
||||
{
|
||||
VisicalcFile visicalcFile = (VisicalcFile) currentDataSource;
|
||||
VisicalcFile.setDebug (value);
|
||||
setText (formattedText, visicalcFile.getText ());
|
||||
}
|
||||
// should implement an interface for this
|
||||
else if (currentDataSource instanceof HiResImage
|
||||
|| currentDataSource instanceof QuickDrawFont)
|
||||
{
|
||||
setDataSource (currentDataSource); // toggles text/image
|
||||
}
|
||||
}
|
||||
|
||||
private void setTabsFont (Font font)
|
||||
{
|
||||
formattedText.setFont (font);
|
||||
hexText.setFont (font);
|
||||
disassemblyText.setFont (font);
|
||||
imagePane.getVerticalScrollBar ().setUnitIncrement (font.getSize ());
|
||||
}
|
||||
|
||||
public String getCurrentText ()
|
||||
{
|
||||
int index = getSelectedIndex ();
|
||||
return index == 0 ? formattedText.getText ()
|
||||
: index == 1 ? hexText.getText () : disassemblyText.getText ();
|
||||
}
|
||||
|
||||
private JScrollPane setPanel (JTextArea outputPanel, String tabName)
|
||||
{
|
||||
outputPanel.setEditable (false);
|
||||
outputPanel.setMargin (new Insets (5, 5, 5, 5));
|
||||
|
||||
JScrollPane outputScrollPane =
|
||||
new JScrollPane (outputPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
outputScrollPane.setBorder (null); // remove the ugly default border
|
||||
add (outputScrollPane, tabName);
|
||||
return outputScrollPane;
|
||||
}
|
||||
|
||||
private void setDataSource (DataSource dataSource)
|
||||
{
|
||||
currentDataSource = dataSource;
|
||||
|
||||
if (dataSource == null)
|
||||
{
|
||||
formattedText.setText ("");
|
||||
hexText.setText ("");
|
||||
disassemblyText.setText ("");
|
||||
removeImage ();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (getSelectedIndex ())
|
||||
{
|
||||
case 0: // Formatted/Image
|
||||
try
|
||||
{
|
||||
setText (formattedText, dataSource.getText ());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
setText (formattedText, e.toString ());
|
||||
e.printStackTrace ();
|
||||
}
|
||||
hexTextValid = false;
|
||||
assemblerTextValid = false;
|
||||
break;
|
||||
|
||||
case 1: // Hex Dump
|
||||
setText (hexText, dataSource.getHexDump ());
|
||||
formattedTextValid = false;
|
||||
assemblerTextValid = false;
|
||||
break;
|
||||
|
||||
case 2: // Disassembly
|
||||
setText (disassemblyText, dataSource.getAssembler ());
|
||||
hexTextValid = false;
|
||||
formattedTextValid = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println ("Invalid index selected in DataPanel");
|
||||
}
|
||||
|
||||
BufferedImage image = dataSource.getImage ();
|
||||
if (image == null || debugMode)
|
||||
removeImage ();
|
||||
else
|
||||
{
|
||||
if (dataSource instanceof HiResImage)
|
||||
{
|
||||
((HiResImage) dataSource).checkPalette ();
|
||||
image = dataSource.getImage ();
|
||||
}
|
||||
imagePanel.setImage (image);
|
||||
imagePane.setViewportView (imagePanel);
|
||||
|
||||
if (!imageVisible)
|
||||
{
|
||||
int selected = getSelectedIndex ();
|
||||
remove (formattedPane);
|
||||
add (imagePane, "Formatted", 0);
|
||||
setSelectedIndex (selected);
|
||||
imageVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeImage ()
|
||||
{
|
||||
if (imageVisible)
|
||||
{
|
||||
int selected = getSelectedIndex ();
|
||||
remove (imagePane);
|
||||
add (formattedPane, "Formatted", 0);
|
||||
setSelectedIndex (selected);
|
||||
imageVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void setText (JTextArea textArea, String text)
|
||||
{
|
||||
textArea.setText (text);
|
||||
textArea.setCaretPosition (0);
|
||||
}
|
||||
|
||||
private class ImagePanel extends JPanel
|
||||
{
|
||||
private BufferedImage image;
|
||||
private int scale = 1;
|
||||
|
||||
public ImagePanel ()
|
||||
{
|
||||
this.setBackground (new Color (BACKGROUND, BACKGROUND, BACKGROUND));
|
||||
}
|
||||
|
||||
private void setImage (BufferedImage image)
|
||||
{
|
||||
this.image = image;
|
||||
int width, height;
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
Graphics2D g2 = image.createGraphics ();
|
||||
g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
width = image.getWidth ();
|
||||
height = image.getHeight ();
|
||||
}
|
||||
else
|
||||
width = height = 0;
|
||||
|
||||
if (true)
|
||||
{
|
||||
if (width < 400 && width > 0)
|
||||
scale = (400 - 1) / width + 1;
|
||||
else
|
||||
scale = 1;
|
||||
if (scale > 4)
|
||||
scale = 4;
|
||||
}
|
||||
|
||||
setPreferredSize (new Dimension (width * scale, height * scale));
|
||||
repaint ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent (Graphics g)
|
||||
{
|
||||
super.paintComponent (g);
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
Graphics2D g2 = ((Graphics2D) g);
|
||||
g2.transform (AffineTransform.getScaleInstance (scale, scale));
|
||||
g2.drawImage (image, (getWidth () - image.getWidth () * scale) / 2 / scale, 4,
|
||||
this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void diskSelected (DiskSelectedEvent event)
|
||||
{
|
||||
setSelectedIndex (0);
|
||||
setDataSource (null);
|
||||
if (event.getFormattedDisk () != null)
|
||||
setDataSource (event.getFormattedDisk ().getCatalog ().getDataSource ());
|
||||
else
|
||||
System.out.println ("bollocks in diskSelected()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileSelected (FileSelectedEvent event)
|
||||
{
|
||||
DataSource dataSource = event.appleFileSource.getDataSource ();
|
||||
setDataSource (dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sectorSelected (SectorSelectedEvent event)
|
||||
{
|
||||
List<DiskAddress> sectors = event.getSectors ();
|
||||
if (sectors == null || sectors.size () == 0)
|
||||
return;
|
||||
|
||||
if (sectors.size () == 1)
|
||||
{
|
||||
DiskAddress da = sectors.get (0);
|
||||
if (da != null)
|
||||
setDataSource (event.getFormattedDisk ().getFormattedSector (da));
|
||||
}
|
||||
else
|
||||
setDataSource (new SectorList (event.getFormattedDisk (), sectors));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileNodeSelected (FileNodeSelectedEvent event)
|
||||
{
|
||||
setSelectedIndex (0);
|
||||
setDataSource (event.getFileNode ());
|
||||
// FileNode node = event.getFileNode ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeFont (FontChangeEvent fontChangeEvent)
|
||||
{
|
||||
setTabsFont (fontChangeEvent.font);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBasicPreferences (BasicPreferences basicPreferences)
|
||||
{
|
||||
if (currentDataSource instanceof ApplesoftBasicProgram)
|
||||
setDataSource (currentDataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAssemblerPreferences (AssemblerPreferences assemblerPreferences)
|
||||
{
|
||||
if (currentDataSource instanceof AssemblerProgram)
|
||||
setDataSource (currentDataSource);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import com.bytezone.common.FontAction.FontChangeEvent;
|
||||
import com.bytezone.common.FontAction.FontChangeListener;
|
||||
import com.bytezone.diskbrowser.applefile.ApplesoftBasicProgram;
|
||||
import com.bytezone.diskbrowser.applefile.AssemblerProgram;
|
||||
import com.bytezone.diskbrowser.applefile.HiResImage;
|
||||
import com.bytezone.diskbrowser.applefile.Palette;
|
||||
import com.bytezone.diskbrowser.applefile.PaletteFactory.CycleDirection;
|
||||
import com.bytezone.diskbrowser.applefile.QuickDrawFont;
|
||||
import com.bytezone.diskbrowser.applefile.VisicalcFile;
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.SectorList;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
||||
FileSelectionListener, SectorSelectionListener, FileNodeSelectionListener,
|
||||
FontChangeListener, BasicPreferencesListener, AssemblerPreferencesListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final int TEXT_WIDTH = 65;
|
||||
private static final int BACKGROUND = 245;
|
||||
|
||||
private final JTextArea formattedText;
|
||||
private final JTextArea hexText;
|
||||
private final JTextArea disassemblyText;
|
||||
|
||||
// these two panes are interchangeable
|
||||
private final JScrollPane formattedPane;
|
||||
private final JScrollPane imagePane;
|
||||
|
||||
private final ImagePanel imagePanel; // internal class
|
||||
private boolean debugMode;
|
||||
|
||||
private boolean imageVisible = false;
|
||||
|
||||
// used to determine whether the text has been set
|
||||
boolean formattedTextValid;
|
||||
boolean hexTextValid;
|
||||
boolean assemblerTextValid;
|
||||
DataSource currentDataSource;
|
||||
|
||||
final MenuHandler menuHandler;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DataPanel (MenuHandler mh)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.menuHandler = mh;
|
||||
setTabPlacement (SwingConstants.BOTTOM);
|
||||
|
||||
formattedText = new JTextArea (10, TEXT_WIDTH);
|
||||
formattedPane = setPanel (formattedText, "Formatted");
|
||||
// formattedText.setLineWrap (prefs.getBoolean (MenuHandler.PREFS_LINE_WRAP, true));
|
||||
formattedText.setText ("Please use the 'File->Set HOME folder...' command to "
|
||||
+ "\ntell DiskBrowser where your Apple disks are located."
|
||||
+ "\n\nTo see the contents of a disk in more detail, double-click"
|
||||
+ "\nthe disk. You will then be able to select individual files to "
|
||||
+ "view completely.");
|
||||
|
||||
hexText = new JTextArea (10, TEXT_WIDTH);
|
||||
setPanel (hexText, "Hex dump");
|
||||
|
||||
disassemblyText = new JTextArea (10, TEXT_WIDTH);
|
||||
setPanel (disassemblyText, "Disassembly");
|
||||
|
||||
imagePanel = new ImagePanel ();
|
||||
imagePane =
|
||||
new JScrollPane (imagePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
|
||||
imagePane.setBorder (null);
|
||||
|
||||
imagePane.getVerticalScrollBar ().setUnitIncrement (50);
|
||||
imagePane.getHorizontalScrollBar ().setUnitIncrement (25);
|
||||
|
||||
addChangeListener (new ChangeListener ()
|
||||
{
|
||||
@Override
|
||||
public void stateChanged (ChangeEvent e)
|
||||
{
|
||||
switch (getSelectedIndex ())
|
||||
{
|
||||
case 0:
|
||||
if (!formattedTextValid)
|
||||
{
|
||||
if (currentDataSource == null)
|
||||
formattedText.setText ("");
|
||||
else
|
||||
setText (formattedText, currentDataSource.getText ());
|
||||
formattedTextValid = true;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!hexTextValid)
|
||||
{
|
||||
if (currentDataSource == null)
|
||||
hexText.setText ("");
|
||||
else
|
||||
setText (hexText, currentDataSource.getHexDump ());
|
||||
hexTextValid = true;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!assemblerTextValid)
|
||||
{
|
||||
if (currentDataSource == null)
|
||||
disassemblyText.setText ("");
|
||||
else
|
||||
setText (disassemblyText, currentDataSource.getAssembler ());
|
||||
assemblerTextValid = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println ("Invalid index selected in DataPanel");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LineWrapAction lineWrapAction = new LineWrapAction ();
|
||||
menuHandler.lineWrapItem.setAction (lineWrapAction);
|
||||
lineWrapAction.addListener (formattedText);
|
||||
|
||||
menuHandler.colourQuirksItem.setAction (new ColourQuirksAction (this));
|
||||
menuHandler.monochromeItem.setAction (new MonochromeAction (this));
|
||||
menuHandler.debuggingItem.setAction (new DebuggingAction (this));
|
||||
|
||||
// fill in the placeholders created by the MenuHandler
|
||||
List<Palette> palettes = HiResImage.getPalettes ();
|
||||
ButtonGroup buttonGroup = menuHandler.paletteGroup;
|
||||
Enumeration<AbstractButton> enumeration = buttonGroup.getElements ();
|
||||
int ndx = 0;
|
||||
while (enumeration.hasMoreElements ())
|
||||
{
|
||||
JCheckBoxMenuItem item = (JCheckBoxMenuItem) enumeration.nextElement ();
|
||||
item.setAction (new PaletteAction (this, palettes.get (ndx++)));
|
||||
}
|
||||
menuHandler.nextPaletteItem.setAction (new NextPaletteAction (this, buttonGroup));
|
||||
menuHandler.prevPaletteItem.setAction (new PreviousPaletteAction (this, buttonGroup));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void selectPalette (Palette palette)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
HiResImage.getPaletteFactory ().setCurrentPalette (palette);
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setPalette ();
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public Palette cyclePalette (CycleDirection direction)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Palette palette = HiResImage.getPaletteFactory ().cyclePalette (direction);
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setPalette ();
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void setLineWrap (boolean lineWrap)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
formattedText.setLineWrap (lineWrap);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setColourQuirks (boolean value)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setColourQuirks (value);
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setMonochrome (boolean value)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.setMonochrome (value);
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setDebug (boolean value)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
debugMode = value;
|
||||
|
||||
if (currentDataSource instanceof VisicalcFile)
|
||||
{
|
||||
VisicalcFile visicalcFile = (VisicalcFile) currentDataSource;
|
||||
VisicalcFile.setDebug (value);
|
||||
setText (formattedText, visicalcFile.getText ());
|
||||
}
|
||||
// should implement an interface for this
|
||||
else if (currentDataSource instanceof HiResImage
|
||||
|| currentDataSource instanceof QuickDrawFont)
|
||||
{
|
||||
setDataSource (currentDataSource); // toggles text/image
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setTabsFont (Font font)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
formattedText.setFont (font);
|
||||
hexText.setFont (font);
|
||||
disassemblyText.setFont (font);
|
||||
imagePane.getVerticalScrollBar ().setUnitIncrement (font.getSize ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String getCurrentText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int index = getSelectedIndex ();
|
||||
return index == 0 ? formattedText.getText () : index == 1 ? hexText.getText ()
|
||||
: disassemblyText.getText ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private JScrollPane setPanel (JTextArea outputPanel, String tabName)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
outputPanel.setEditable (false);
|
||||
outputPanel.setMargin (new Insets (5, 5, 5, 5));
|
||||
|
||||
JScrollPane outputScrollPane =
|
||||
new JScrollPane (outputPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
outputScrollPane.setBorder (null); // remove the ugly default border
|
||||
add (outputScrollPane, tabName);
|
||||
return outputScrollPane;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setDataSource (DataSource dataSource)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
currentDataSource = dataSource;
|
||||
|
||||
if (dataSource == null)
|
||||
{
|
||||
formattedText.setText ("");
|
||||
hexText.setText ("");
|
||||
disassemblyText.setText ("");
|
||||
removeImage ();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (getSelectedIndex ())
|
||||
{
|
||||
case 0: // Formatted/Image
|
||||
try
|
||||
{
|
||||
setText (formattedText, dataSource.getText ());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
setText (formattedText, e.toString ());
|
||||
e.printStackTrace ();
|
||||
}
|
||||
hexTextValid = false;
|
||||
assemblerTextValid = false;
|
||||
break;
|
||||
|
||||
case 1: // Hex Dump
|
||||
setText (hexText, dataSource.getHexDump ());
|
||||
formattedTextValid = false;
|
||||
assemblerTextValid = false;
|
||||
break;
|
||||
|
||||
case 2: // Disassembly
|
||||
setText (disassemblyText, dataSource.getAssembler ());
|
||||
hexTextValid = false;
|
||||
formattedTextValid = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println ("Invalid index selected in DataPanel");
|
||||
}
|
||||
|
||||
BufferedImage image = dataSource.getImage ();
|
||||
if (image == null || debugMode)
|
||||
removeImage ();
|
||||
else
|
||||
{
|
||||
if (dataSource instanceof HiResImage)
|
||||
{
|
||||
((HiResImage) dataSource).checkPalette ();
|
||||
image = dataSource.getImage ();
|
||||
}
|
||||
imagePanel.setImage (image);
|
||||
imagePane.setViewportView (imagePanel);
|
||||
|
||||
if (!imageVisible)
|
||||
{
|
||||
int selected = getSelectedIndex ();
|
||||
remove (formattedPane);
|
||||
add (imagePane, "Formatted", 0);
|
||||
setSelectedIndex (selected);
|
||||
imageVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void removeImage ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (imageVisible)
|
||||
{
|
||||
int selected = getSelectedIndex ();
|
||||
remove (imagePane);
|
||||
add (formattedPane, "Formatted", 0);
|
||||
setSelectedIndex (selected);
|
||||
imageVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setText (JTextArea textArea, String text)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
textArea.setText (text);
|
||||
textArea.setCaretPosition (0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private class ImagePanel extends JPanel
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
private BufferedImage image;
|
||||
private int scale = 1;
|
||||
|
||||
public ImagePanel ()
|
||||
{
|
||||
this.setBackground (new Color (BACKGROUND, BACKGROUND, BACKGROUND));
|
||||
}
|
||||
|
||||
private void setImage (BufferedImage image)
|
||||
{
|
||||
this.image = image;
|
||||
int width, height;
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
Graphics2D g2 = image.createGraphics ();
|
||||
g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
width = image.getWidth ();
|
||||
height = image.getHeight ();
|
||||
}
|
||||
else
|
||||
width = height = 0;
|
||||
|
||||
if (true)
|
||||
{
|
||||
if (width < 400 && width > 0)
|
||||
scale = (400 - 1) / width + 1;
|
||||
else
|
||||
scale = 1;
|
||||
if (scale > 4)
|
||||
scale = 4;
|
||||
}
|
||||
|
||||
setPreferredSize (new Dimension (width * scale, height * scale));
|
||||
repaint ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent (Graphics g)
|
||||
{
|
||||
super.paintComponent (g);
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
Graphics2D g2 = ((Graphics2D) g);
|
||||
g2.transform (AffineTransform.getScaleInstance (scale, scale));
|
||||
g2.drawImage (image, (getWidth () - image.getWidth () * scale) / 2 / scale, 4,
|
||||
this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void diskSelected (DiskSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
setSelectedIndex (0);
|
||||
setDataSource (null);
|
||||
if (event.getFormattedDisk () != null)
|
||||
setDataSource (event.getFormattedDisk ().getCatalog ().getDataSource ());
|
||||
else
|
||||
System.out.println ("bollocks in diskSelected()");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void fileSelected (FileSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
DataSource dataSource = event.appleFileSource.getDataSource ();
|
||||
setDataSource (dataSource);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void sectorSelected (SectorSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
List<DiskAddress> sectors = event.getSectors ();
|
||||
if (sectors == null || sectors.size () == 0)
|
||||
return;
|
||||
|
||||
if (sectors.size () == 1)
|
||||
{
|
||||
DiskAddress da = sectors.get (0);
|
||||
if (da != null)
|
||||
setDataSource (event.getFormattedDisk ().getFormattedSector (da));
|
||||
}
|
||||
else
|
||||
setDataSource (new SectorList (event.getFormattedDisk (), sectors));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void fileNodeSelected (FileNodeSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
setSelectedIndex (0);
|
||||
setDataSource (event.getFileNode ());
|
||||
// FileNode node = event.getFileNode ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void changeFont (FontChangeEvent fontChangeEvent)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
setTabsFont (fontChangeEvent.font);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void setBasicPreferences (BasicPreferences basicPreferences)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (currentDataSource instanceof ApplesoftBasicProgram)
|
||||
setDataSource (currentDataSource);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void setAssemblerPreferences (AssemblerPreferences assemblerPreferences)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (currentDataSource instanceof AssemblerProgram)
|
||||
setDataSource (currentDataSource);
|
||||
}
|
||||
}
|
@ -1,18 +1,20 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
public interface DataSource
|
||||
{
|
||||
public String getText ();
|
||||
|
||||
public String getAssembler ();
|
||||
|
||||
public String getHexDump ();
|
||||
|
||||
public BufferedImage getImage ();
|
||||
|
||||
public JComponent getComponent ();
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface DataSource
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public String getText ();
|
||||
|
||||
public String getAssembler ();
|
||||
|
||||
public String getHexDump ();
|
||||
|
||||
public BufferedImage getImage ();
|
||||
|
||||
public JComponent getComponent ();
|
||||
}
|
@ -7,11 +7,15 @@ import javax.swing.Action;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class DebuggingAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final DataPanel owner;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DebuggingAction (DataPanel owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Debugging");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Show debugging information");
|
||||
@ -19,8 +23,10 @@ public class DebuggingAction extends AbstractAction
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
owner.setDebug (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
|
@ -1,138 +1,156 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.event.EventListenerList;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
||||
|
||||
class DiskAndFileSelector
|
||||
{
|
||||
EventListenerList listenerList = new EventListenerList ();
|
||||
FormattedDisk currentDisk;
|
||||
boolean redo;
|
||||
|
||||
/*
|
||||
* Apple DiskSelection routines
|
||||
*/
|
||||
public void addDiskSelectionListener (DiskSelectionListener listener)
|
||||
{
|
||||
listenerList.add (DiskSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
public void removeDiskSelectionListener (DiskSelectionListener listener)
|
||||
{
|
||||
listenerList.remove (DiskSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
public void addFileNodeSelectionListener (FileNodeSelectionListener listener)
|
||||
{
|
||||
listenerList.add (FileNodeSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
public void removeFileNodeSelectionListener (FileNodeSelectionListener listener)
|
||||
{
|
||||
listenerList.remove (FileNodeSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// public void fireDiskSelectionEvent (File file)
|
||||
// {
|
||||
// if (file.isDirectory ())
|
||||
// {
|
||||
// System.out.println ("Directory received : " + file.getAbsolutePath ());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (currentDisk != null) // will this screw up the refresh command?
|
||||
// {
|
||||
// System.out.println (currentDisk.getDisk ().getFile ().getAbsolutePath ());
|
||||
// System.out.println (file.getAbsolutePath ());
|
||||
// }
|
||||
// if (currentDisk != null
|
||||
// && currentDisk.getDisk ().getFile ().getAbsolutePath ().equals (file.getAbsolutePath ()))
|
||||
// fireDiskSelectionEvent (currentDisk);
|
||||
// else
|
||||
// {
|
||||
// System.out.println (" creating disk from a file");
|
||||
// fireDiskSelectionEvent (DiskFactory.createDisk (file.getAbsolutePath ()));
|
||||
// }
|
||||
// }
|
||||
|
||||
void fireDiskSelectionEvent (FileNode node)
|
||||
{
|
||||
if (node.file.isDirectory ())
|
||||
{
|
||||
fireFileNodeSelectionEvent (node);
|
||||
currentDisk = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
FormattedDisk fd = node.getFormattedDisk ();
|
||||
if (fd == null)
|
||||
JOptionPane.showMessageDialog (null, "Unrecognised file format", "Format error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
else
|
||||
fireDiskSelectionEvent (fd);
|
||||
}
|
||||
}
|
||||
|
||||
void fireFileNodeSelectionEvent (FileNode node)
|
||||
{
|
||||
FileNodeSelectedEvent e = new FileNodeSelectedEvent (this, node);
|
||||
e.redo = redo;
|
||||
FileNodeSelectionListener[] listeners =
|
||||
(listenerList.getListeners (FileNodeSelectionListener.class));
|
||||
for (FileNodeSelectionListener listener : listeners)
|
||||
listener.fileNodeSelected (e);
|
||||
}
|
||||
|
||||
void fireDiskSelectionEvent (FormattedDisk disk)
|
||||
{
|
||||
if (disk == currentDisk)
|
||||
{
|
||||
// System.out.println ("Disk event duplicated");
|
||||
return;
|
||||
}
|
||||
|
||||
if (disk == null)
|
||||
{
|
||||
System.out.println ("Null disk in fireDiskSelectionEvent()");
|
||||
return;
|
||||
}
|
||||
|
||||
DiskSelectedEvent e = new DiskSelectedEvent (this, disk);
|
||||
e.redo = redo;
|
||||
DiskSelectionListener[] listeners =
|
||||
(listenerList.getListeners (DiskSelectionListener.class));
|
||||
for (DiskSelectionListener listener : listeners)
|
||||
listener.diskSelected (e);
|
||||
currentDisk = disk;
|
||||
}
|
||||
|
||||
/*
|
||||
* Apple FileSelection routines
|
||||
*/
|
||||
|
||||
public void addFileSelectionListener (FileSelectionListener listener)
|
||||
{
|
||||
listenerList.add (FileSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
public void removeFileSelectionListener (FileSelectionListener listener)
|
||||
{
|
||||
listenerList.remove (FileSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
void fireFileSelectionEvent (AppleFileSource file)
|
||||
{
|
||||
assert file != null;
|
||||
currentDisk = null;
|
||||
FileSelectedEvent e = new FileSelectedEvent (this, file);
|
||||
e.redo = redo;
|
||||
FileSelectionListener[] listeners =
|
||||
(listenerList.getListeners (FileSelectionListener.class));
|
||||
for (FileSelectionListener listener : listeners)
|
||||
listener.fileSelected (e);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.event.EventListenerList;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskAndFileSelector
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
EventListenerList listenerList = new EventListenerList ();
|
||||
FormattedDisk currentDisk;
|
||||
boolean redo;
|
||||
|
||||
/*
|
||||
* Apple DiskSelection routines
|
||||
*/
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addDiskSelectionListener (DiskSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.add (DiskSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void removeDiskSelectionListener (DiskSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.remove (DiskSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addFileNodeSelectionListener (FileNodeSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.add (FileNodeSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void removeFileNodeSelectionListener (FileNodeSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.remove (FileNodeSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// public void fireDiskSelectionEvent (File file)
|
||||
// {
|
||||
// if (file.isDirectory ())
|
||||
// {
|
||||
// System.out.println ("Directory received : " + file.getAbsolutePath ());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (currentDisk != null) // will this screw up the refresh command?
|
||||
// {
|
||||
// System.out.println (currentDisk.getDisk ().getFile ().getAbsolutePath ());
|
||||
// System.out.println (file.getAbsolutePath ());
|
||||
// }
|
||||
// if (currentDisk != null
|
||||
// && currentDisk.getDisk ().getFile ().getAbsolutePath ().equals (file.getAbsolutePath ()))
|
||||
// fireDiskSelectionEvent (currentDisk);
|
||||
// else
|
||||
// {
|
||||
// System.out.println (" creating disk from a file");
|
||||
// fireDiskSelectionEvent (DiskFactory.createDisk (file.getAbsolutePath ()));
|
||||
// }
|
||||
// }
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void fireDiskSelectionEvent (FileNode node)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (node.file.isDirectory ())
|
||||
{
|
||||
fireFileNodeSelectionEvent (node);
|
||||
currentDisk = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
FormattedDisk fd = node.getFormattedDisk ();
|
||||
if (fd == null)
|
||||
JOptionPane.showMessageDialog (null, "Unrecognised file format", "Format error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
else
|
||||
fireDiskSelectionEvent (fd);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void fireFileNodeSelectionEvent (FileNode node)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
FileNodeSelectedEvent e = new FileNodeSelectedEvent (this, node);
|
||||
e.redo = redo;
|
||||
FileNodeSelectionListener[] listeners =
|
||||
(listenerList.getListeners (FileNodeSelectionListener.class));
|
||||
for (FileNodeSelectionListener listener : listeners)
|
||||
listener.fileNodeSelected (e);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void fireDiskSelectionEvent (FormattedDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (disk == currentDisk)
|
||||
{
|
||||
// System.out.println ("Disk event duplicated");
|
||||
return;
|
||||
}
|
||||
|
||||
if (disk == null)
|
||||
{
|
||||
System.out.println ("Null disk in fireDiskSelectionEvent()");
|
||||
return;
|
||||
}
|
||||
|
||||
DiskSelectedEvent e = new DiskSelectedEvent (this, disk);
|
||||
e.redo = redo;
|
||||
DiskSelectionListener[] listeners =
|
||||
(listenerList.getListeners (DiskSelectionListener.class));
|
||||
for (DiskSelectionListener listener : listeners)
|
||||
listener.diskSelected (e);
|
||||
currentDisk = disk;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addFileSelectionListener (FileSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.add (FileSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void removeFileSelectionListener (FileSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.remove (FileSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void fireFileSelectionEvent (AppleFileSource file)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
assert file != null;
|
||||
currentDisk = null;
|
||||
FileSelectedEvent e = new FileSelectedEvent (this, file);
|
||||
e.redo = redo;
|
||||
FileSelectionListener[] listeners =
|
||||
(listenerList.getListeners (FileSelectionListener.class));
|
||||
for (FileSelectionListener listener : listeners)
|
||||
listener.fileSelected (e);
|
||||
}
|
||||
}
|
@ -1,6 +1,12 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
@ -19,7 +25,9 @@ import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final Cursor crosshairCursor = new Cursor (Cursor.CROSSHAIR_CURSOR);
|
||||
private static final Color[] lightColors =
|
||||
@ -33,7 +41,9 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
private int gridWidth = 8;
|
||||
private int gridHeight = 35;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DiskLayoutImage ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
setPreferredSize (new Dimension (240 + 1, 525 + 1));
|
||||
addMouseListener (new MyMouseListener ());
|
||||
@ -45,8 +55,10 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
addKeyListener (new MyKeyListener ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void setDisk (FormattedDisk disk, LayoutDetails details)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super.setDisk (disk, details);
|
||||
|
||||
@ -60,12 +72,16 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FormattedDisk getDisk ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return formattedDisk;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setShowFreeSectors (boolean showFree)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (showFree != showFreeSectors)
|
||||
{
|
||||
@ -74,7 +90,9 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void setSelection (List<DiskAddress> sectors)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
selectionHandler.setSelection (sectors);
|
||||
if (sectors != null && sectors.size () > 0)
|
||||
@ -86,8 +104,10 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
protected void paintComponent (Graphics g)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super.paintComponent (g);
|
||||
|
||||
@ -130,8 +150,10 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void drawBlock (Graphics2D g, SectorType type, int x, int y, boolean flagFree,
|
||||
boolean selected)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
g.setColor (type.colour);
|
||||
g.fillRect (x + 1, y + 1, blockWidth - 1, blockHeight - 1);
|
||||
@ -148,7 +170,9 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private Color getContrastColor (SectorType type)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
for (Color color : lightColors)
|
||||
if (type.colour == color)
|
||||
@ -156,40 +180,52 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
return Color.WHITE;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public Dimension getPreferredScrollableViewportSize ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return new Dimension (240 + 1, 525 + 1); // floppy disk size
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public int getScrollableUnitIncrement (Rectangle visibleRect, int orientation,
|
||||
int direction)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return orientation == SwingConstants.HORIZONTAL ? blockWidth : blockHeight;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public int getScrollableBlockIncrement (Rectangle visibleRect, int orientation,
|
||||
int direction)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return orientation == SwingConstants.HORIZONTAL ? blockWidth * 4 : blockHeight * 10;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportHeight ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportWidth ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void redo (RedoEvent redoEvent)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
redo = true;
|
||||
SectorSelectedEvent event = (SectorSelectedEvent) redoEvent.value;
|
||||
@ -200,14 +236,18 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
requestFocusInWindow ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void fireSectorSelectionEvent ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
SectorSelectedEvent event =
|
||||
new SectorSelectedEvent (this, selectionHandler.getHighlights (), formattedDisk);
|
||||
fireSectorSelectionEvent (event);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void fireSectorSelectionEvent (SectorSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
event.redo = redo;
|
||||
SectorSelectionListener[] listeners =
|
||||
@ -216,17 +256,23 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
listener.sectorSelected (event);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addSectorSelectionListener (SectorSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.add (SectorSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void removeSectorSelectionListener (SectorSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
listenerList.remove (SectorSelectionListener.class, listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class MyKeyListener extends KeyAdapter
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
@Override
|
||||
public void keyPressed (KeyEvent e)
|
||||
@ -244,7 +290,9 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class MyMouseListener extends MouseAdapter
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
private Cursor currentCursor;
|
||||
|
||||
|
@ -24,8 +24,10 @@ import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoEvent;
|
||||
import com.bytezone.diskbrowser.gui.RedoHandler.RedoListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskLayoutPanel extends JPanel
|
||||
implements DiskSelectionListener, FileSelectionListener, RedoListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final int SIZE = 15; // basic unit of a display block
|
||||
|
||||
@ -36,7 +38,9 @@ class DiskLayoutPanel extends JPanel
|
||||
private final JScrollPane sp;
|
||||
private LayoutDetails layout;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DiskLayoutPanel ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (new BorderLayout ());
|
||||
|
||||
@ -63,7 +67,9 @@ class DiskLayoutPanel extends JPanel
|
||||
add (legendPanel, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setDisk (final FormattedDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
layout = new LayoutDetails (disk);
|
||||
diskLayoutImage.setDisk (disk, layout);
|
||||
@ -105,41 +111,55 @@ class DiskLayoutPanel extends JPanel
|
||||
repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setHex (boolean hex)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
verticalRuler.setHex (hex);
|
||||
horizontalRuler.setHex (hex);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setBlock (boolean block)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
verticalRuler.setTrackMode (block);
|
||||
horizontalRuler.setTrackMode (block);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setFree (boolean free)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
diskLayoutImage.setShowFreeSectors (free);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addSectorSelectionListener (SectorSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
diskLayoutImage.addSectorSelectionListener (listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void removeSectorSelectionListener (SectorSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
diskLayoutImage.removeSectorSelectionListener (listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void diskSelected (DiskSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
setDisk (event.getFormattedDisk ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void fileSelected (FileSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// This can happen if a file is selected from a dual-dos disk
|
||||
checkCorrectDisk (event.appleFileSource.getFormattedDisk ());
|
||||
@ -147,7 +167,9 @@ class DiskLayoutPanel extends JPanel
|
||||
diskLayoutImage.setSelection (event.appleFileSource.getSectors ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class LayoutDetails
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Dimension block;
|
||||
Dimension grid;
|
||||
@ -178,7 +200,9 @@ class DiskLayoutPanel extends JPanel
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class Corner extends JComponent
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Color backgroundColor = Color.WHITE;
|
||||
boolean showHex = true;
|
||||
|
@ -1,201 +1,223 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.AppleDiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.Disk;
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
class DiskLayoutSelection implements Iterable<DiskAddress>
|
||||
{
|
||||
private final List<DiskAddress> highlights;
|
||||
|
||||
public DiskLayoutSelection ()
|
||||
{
|
||||
highlights = new ArrayList<> ();
|
||||
}
|
||||
|
||||
public void doClick (Disk disk, DiskAddress da, boolean extend, boolean append)
|
||||
{
|
||||
/*
|
||||
* Single click without modifiers - just replace previous highlights with the new
|
||||
* sector. If there are no current highlights then even modifiers have the same
|
||||
* effect.
|
||||
*/
|
||||
if ((!extend && !append) || highlights.size () == 0)
|
||||
{
|
||||
highlights.clear ();
|
||||
addHighlight (da);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the click was on an existing highlight, just remove it (regardless of modifiers)
|
||||
*/
|
||||
for (DiskAddress setDA : highlights)
|
||||
if (da.matches (setDA))
|
||||
{
|
||||
highlights.remove (setDA);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Appending - just add the sector to the existing highlights
|
||||
*/
|
||||
if (append)
|
||||
{
|
||||
addHighlight (da);
|
||||
Collections.sort (highlights);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extending - if the existing selection is contiguous then just extend it. If not
|
||||
* then things get a bit trickier.
|
||||
*/
|
||||
if (checkContiguous ())
|
||||
extendHighlights (disk, da);
|
||||
else
|
||||
adjustHighlights (disk, da);
|
||||
|
||||
Collections.sort (highlights);
|
||||
}
|
||||
|
||||
void cursorMove (FormattedDisk formattedDisk, KeyEvent e)
|
||||
{
|
||||
if (highlights.size () == 0)
|
||||
{
|
||||
System.out.println ("Nothing to move");
|
||||
return;
|
||||
}
|
||||
|
||||
Disk disk = formattedDisk.getDisk ();
|
||||
|
||||
DiskAddress first = highlights.get (0);
|
||||
DiskAddress last = highlights.get (highlights.size () - 1);
|
||||
|
||||
if (!e.isShiftDown ())
|
||||
highlights.clear ();
|
||||
|
||||
int totalBlocks = disk.getTotalBlocks ();
|
||||
// int rowSize = disk.getTrackSize () / disk.getBlockSize ();
|
||||
Dimension gridLayout = formattedDisk.getGridLayout ();
|
||||
int rowSize = gridLayout.width;
|
||||
|
||||
switch (e.getKeyCode ())
|
||||
{
|
||||
case KeyEvent.VK_LEFT:
|
||||
int block = first.getBlock () - 1;
|
||||
if (block < 0)
|
||||
block = totalBlocks - 1;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
|
||||
case KeyEvent.VK_RIGHT:
|
||||
block = last.getBlock () + 1;
|
||||
if (block >= totalBlocks)
|
||||
block = 0;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
|
||||
case KeyEvent.VK_UP:
|
||||
block = first.getBlock () - rowSize;
|
||||
if (block < 0)
|
||||
block += totalBlocks;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
|
||||
case KeyEvent.VK_DOWN:
|
||||
block = last.getBlock () + rowSize;
|
||||
if (block >= totalBlocks)
|
||||
block -= totalBlocks;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
}
|
||||
Collections.sort (highlights);
|
||||
}
|
||||
|
||||
private void addHighlight (DiskAddress da)
|
||||
{
|
||||
assert da != null;
|
||||
highlights.add (da);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<DiskAddress> iterator ()
|
||||
{
|
||||
return highlights.iterator ();
|
||||
}
|
||||
|
||||
// This must return a copy, or the redo function will get very confused
|
||||
public List<DiskAddress> getHighlights ()
|
||||
{
|
||||
return new ArrayList<> (highlights);
|
||||
}
|
||||
|
||||
public boolean isSelected (DiskAddress da)
|
||||
{
|
||||
for (DiskAddress selection : highlights)
|
||||
if (selection != null && da.matches (selection))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSelection (List<DiskAddress> list)
|
||||
{
|
||||
// sparse files contain empty blocks
|
||||
highlights.clear ();
|
||||
if (list != null)
|
||||
for (DiskAddress da : list)
|
||||
if (da != null && (da.getBlock () > 0 || ((AppleDiskAddress) da).zeroFlag ()))
|
||||
highlights.add (da);
|
||||
}
|
||||
|
||||
private boolean checkContiguous ()
|
||||
{
|
||||
int range = highlights.get (highlights.size () - 1).getBlock ()
|
||||
- highlights.get (0).getBlock () + 1;
|
||||
return (range == highlights.size ());
|
||||
}
|
||||
|
||||
private void extendHighlights (Disk disk, DiskAddress da)
|
||||
{
|
||||
int lo, hi;
|
||||
|
||||
// Are we extending in front of the current block?
|
||||
if (highlights.get (0).getBlock () > da.getBlock ())
|
||||
{
|
||||
lo = da.getBlock ();
|
||||
hi = highlights.get (0).getBlock () - 1;
|
||||
}
|
||||
else
|
||||
// No, must be extending at the end
|
||||
{
|
||||
lo = highlights.get (highlights.size () - 1).getBlock () + 1;
|
||||
hi = da.getBlock ();
|
||||
}
|
||||
|
||||
for (int i = lo; i <= hi; i++)
|
||||
addHighlight (disk.getDiskAddress (i));
|
||||
}
|
||||
|
||||
private void adjustHighlights (Disk disk, DiskAddress da)
|
||||
{
|
||||
// If we are outside the discontiguous range, just extend as usual
|
||||
if (da.getBlock () < highlights.get (0).getBlock ()
|
||||
|| da.getBlock () > highlights.get (highlights.size () - 1).getBlock ())
|
||||
{
|
||||
extendHighlights (disk, da);
|
||||
return;
|
||||
}
|
||||
|
||||
// just treat it like a ctrl-click (hack!!)
|
||||
addHighlight (da);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.AppleDiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.Disk;
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskLayoutSelection implements Iterable<DiskAddress>
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final List<DiskAddress> highlights;
|
||||
|
||||
public DiskLayoutSelection ()
|
||||
{
|
||||
highlights = new ArrayList<> ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void doClick (Disk disk, DiskAddress da, boolean extend, boolean append)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
/*
|
||||
* Single click without modifiers - just replace previous highlights with the new
|
||||
* sector. If there are no current highlights then even modifiers have the same
|
||||
* effect.
|
||||
*/
|
||||
if ((!extend && !append) || highlights.size () == 0)
|
||||
{
|
||||
highlights.clear ();
|
||||
addHighlight (da);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the click was on an existing highlight, just remove it (regardless of modifiers)
|
||||
*/
|
||||
for (DiskAddress setDA : highlights)
|
||||
if (da.matches (setDA))
|
||||
{
|
||||
highlights.remove (setDA);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Appending - just add the sector to the existing highlights
|
||||
*/
|
||||
if (append)
|
||||
{
|
||||
addHighlight (da);
|
||||
Collections.sort (highlights);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extending - if the existing selection is contiguous then just extend it. If not
|
||||
* then things get a bit trickier.
|
||||
*/
|
||||
if (checkContiguous ())
|
||||
extendHighlights (disk, da);
|
||||
else
|
||||
adjustHighlights (disk, da);
|
||||
|
||||
Collections.sort (highlights);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void cursorMove (FormattedDisk formattedDisk, KeyEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (highlights.size () == 0)
|
||||
{
|
||||
System.out.println ("Nothing to move");
|
||||
return;
|
||||
}
|
||||
|
||||
Disk disk = formattedDisk.getDisk ();
|
||||
|
||||
DiskAddress first = highlights.get (0);
|
||||
DiskAddress last = highlights.get (highlights.size () - 1);
|
||||
|
||||
if (!e.isShiftDown ())
|
||||
highlights.clear ();
|
||||
|
||||
int totalBlocks = disk.getTotalBlocks ();
|
||||
// int rowSize = disk.getTrackSize () / disk.getBlockSize ();
|
||||
Dimension gridLayout = formattedDisk.getGridLayout ();
|
||||
int rowSize = gridLayout.width;
|
||||
|
||||
switch (e.getKeyCode ())
|
||||
{
|
||||
case KeyEvent.VK_LEFT:
|
||||
int block = first.getBlock () - 1;
|
||||
if (block < 0)
|
||||
block = totalBlocks - 1;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
|
||||
case KeyEvent.VK_RIGHT:
|
||||
block = last.getBlock () + 1;
|
||||
if (block >= totalBlocks)
|
||||
block = 0;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
|
||||
case KeyEvent.VK_UP:
|
||||
block = first.getBlock () - rowSize;
|
||||
if (block < 0)
|
||||
block += totalBlocks;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
|
||||
case KeyEvent.VK_DOWN:
|
||||
block = last.getBlock () + rowSize;
|
||||
if (block >= totalBlocks)
|
||||
block -= totalBlocks;
|
||||
addHighlight (disk.getDiskAddress (block));
|
||||
break;
|
||||
}
|
||||
Collections.sort (highlights);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addHighlight (DiskAddress da)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
assert da != null;
|
||||
highlights.add (da);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public Iterator<DiskAddress> iterator ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return highlights.iterator ();
|
||||
}
|
||||
|
||||
// This must return a copy, or the redo function will get very confused
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public List<DiskAddress> getHighlights ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return new ArrayList<> (highlights);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public boolean isSelected (DiskAddress da)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
for (DiskAddress selection : highlights)
|
||||
if (selection != null && da.matches (selection))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setSelection (List<DiskAddress> list)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// sparse files contain empty blocks
|
||||
highlights.clear ();
|
||||
if (list != null)
|
||||
for (DiskAddress da : list)
|
||||
if (da != null && (da.getBlock () > 0 || ((AppleDiskAddress) da).zeroFlag ()))
|
||||
highlights.add (da);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private boolean checkContiguous ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int range = highlights.get (highlights.size () - 1).getBlock ()
|
||||
- highlights.get (0).getBlock () + 1;
|
||||
return (range == highlights.size ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void extendHighlights (Disk disk, DiskAddress da)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int lo, hi;
|
||||
|
||||
// Are we extending in front of the current block?
|
||||
if (highlights.get (0).getBlock () > da.getBlock ())
|
||||
{
|
||||
lo = da.getBlock ();
|
||||
hi = highlights.get (0).getBlock () - 1;
|
||||
}
|
||||
else
|
||||
// No, must be extending at the end
|
||||
{
|
||||
lo = highlights.get (highlights.size () - 1).getBlock () + 1;
|
||||
hi = da.getBlock ();
|
||||
}
|
||||
|
||||
for (int i = lo; i <= hi; i++)
|
||||
addHighlight (disk.getDiskAddress (i));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void adjustHighlights (Disk disk, DiskAddress da)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// If we are outside the discontiguous range, just extend as usual
|
||||
if (da.getBlock () < highlights.get (0).getBlock ()
|
||||
|| da.getBlock () > highlights.get (highlights.size () - 1).getBlock ())
|
||||
{
|
||||
extendHighlights (disk, da);
|
||||
return;
|
||||
}
|
||||
|
||||
// just treat it like a ctrl-click (hack!!)
|
||||
addHighlight (da);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user