mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-01-02 22:32:45 +00:00
member header lines
This commit is contained in:
parent
343e5da6d9
commit
ed872ce87e
@ -12,35 +12,45 @@ import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.disk.SectorType;
|
||||
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskLegendPanel extends DiskPanel
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final int LEFT = 3;
|
||||
private static final int TOP = 10;
|
||||
|
||||
private final Font font;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DiskLegendPanel ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
font = Platform.getFont (FontType.SANS_SERIF, FontSize.BASE);
|
||||
setBackground (Color.WHITE);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void setDisk (FormattedDisk disk, LayoutDetails details)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super.setDisk (disk, details);
|
||||
|
||||
repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public Dimension getPreferredSize ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return new Dimension (0, 160); // width/height
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
protected void paintComponent (Graphics g)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super.paintComponent (g);
|
||||
|
||||
|
@ -7,7 +7,9 @@ import javax.swing.JPanel;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class DiskPanel extends JPanel
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
FormattedDisk formattedDisk;
|
||||
LayoutDetails layoutDetails;
|
||||
@ -17,7 +19,9 @@ public class DiskPanel extends JPanel
|
||||
|
||||
Color backgroundColor = new Color (0xE0, 0xE0, 0xE0);
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setDisk (FormattedDisk disk, LayoutDetails details)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
formattedDisk = disk;
|
||||
layoutDetails = details;
|
||||
|
@ -1,40 +1,52 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.DiskFactory;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
public class DiskSelectedEvent extends EventObject
|
||||
{
|
||||
private final FormattedDisk owner;
|
||||
boolean redo;
|
||||
|
||||
public DiskSelectedEvent (Object source, FormattedDisk disk)
|
||||
{
|
||||
super (source);
|
||||
this.owner = disk;
|
||||
}
|
||||
|
||||
public FormattedDisk getFormattedDisk ()
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return owner.getDisk ().getFile ().getAbsolutePath ();
|
||||
}
|
||||
|
||||
public String toText ()
|
||||
{
|
||||
return owner.getAbsolutePath ();
|
||||
}
|
||||
|
||||
public static DiskSelectedEvent create (Object source, String path)
|
||||
{
|
||||
FormattedDisk formattedDisk = DiskFactory.createDisk (path);
|
||||
return formattedDisk == null ? null : new DiskSelectedEvent (source, formattedDisk);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.DiskFactory;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class DiskSelectedEvent extends EventObject
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final FormattedDisk owner;
|
||||
boolean redo;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
DiskSelectedEvent (Object source, FormattedDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (source);
|
||||
this.owner = disk;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FormattedDisk getFormattedDisk ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return owner.getDisk ().getFile ().getAbsolutePath ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String toText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return owner.getAbsolutePath ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public static DiskSelectedEvent create (Object source, String path)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
FormattedDisk formattedDisk = DiskFactory.createDisk (path);
|
||||
return formattedDisk == null ? null : new DiskSelectedEvent (source, formattedDisk);
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface DiskSelectionListener extends EventListener
|
||||
{
|
||||
public void diskSelected (DiskSelectedEvent event);
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface DiskSelectionListener extends EventListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void diskSelected (DiskSelectedEvent event);
|
||||
}
|
@ -13,11 +13,15 @@ import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.diskbrowser.duplicates.DiskDetails;
|
||||
import com.bytezone.diskbrowser.duplicates.RootFolderData;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class DuplicateAction extends DefaultAction implements RootDirectoryChangeListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
RootFolderData rootFolderData;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public DuplicateAction (RootFolderData rootFolderData)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("List disks...", "Display a sortable list of disks",
|
||||
"/com/bytezone/diskbrowser/icons/");
|
||||
@ -31,15 +35,19 @@ public class DuplicateAction extends DefaultAction implements RootDirectoryChang
|
||||
setEnabled (rootFolderData.getRootFolder () != null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
assert rootFolderData.getRootFolder () == newRootFolder;
|
||||
setEnabled (rootFolderData.getRootFolder () != null);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent arg0)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (rootFolderData.disksWindow == null)
|
||||
{
|
||||
@ -58,13 +66,17 @@ public class DuplicateAction extends DefaultAction implements RootDirectoryChang
|
||||
rootFolderData.disksWindow.setVisible (true);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addTableSelectionListener (DiskTableSelectionListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (!rootFolderData.listeners.contains (listener))
|
||||
rootFolderData.listeners.add (listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public interface DiskTableSelectionListener
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
public void diskSelected (DiskDetails diskDetails);
|
||||
}
|
||||
|
@ -1,38 +1,46 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
class ExecuteDiskAction extends AbstractAction
|
||||
{
|
||||
// should replace this by making the action a listener
|
||||
MenuHandler owner;
|
||||
|
||||
public ExecuteDiskAction (MenuHandler owner)
|
||||
{
|
||||
super ("Run current disk");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Same as double-clicking on the disk");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt X"));
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Desktop.getDesktop ().open (owner.currentDisk.getDisk ().getFile ());
|
||||
}
|
||||
catch (IOException e1)
|
||||
{
|
||||
e1.printStackTrace ();
|
||||
JOptionPane.showMessageDialog (null, "Error opening disk : "
|
||||
+ owner.currentDisk.getDisk ().getFile (), "Bugger", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class ExecuteDiskAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
// should replace this by making the action a listener
|
||||
MenuHandler owner;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public ExecuteDiskAction (MenuHandler owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Run current disk");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Same as double-clicking on the disk");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt X"));
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
try
|
||||
{
|
||||
Desktop.getDesktop ().open (owner.currentDisk.getDisk ().getFile ());
|
||||
}
|
||||
catch (IOException e1)
|
||||
{
|
||||
e1.printStackTrace ();
|
||||
JOptionPane.showMessageDialog (null,
|
||||
"Error opening disk : " + owner.currentDisk.getDisk ().getFile (), "Bugger",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,11 +3,14 @@ package com.bytezone.diskbrowser.gui;
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class FileComparator implements Comparator<File>
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public int compare (File thisFile, File thatFile)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
boolean thisFileIsDirectory = thisFile.isDirectory ();
|
||||
boolean thatFileIsDirectory = thatFile.isDirectory ();
|
||||
|
@ -5,14 +5,14 @@ import java.util.EventObject;
|
||||
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class FileNodeSelectedEvent extends EventObject
|
||||
class FileNodeSelectedEvent extends EventObject
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final FileNode node;
|
||||
boolean redo;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FileNodeSelectedEvent (Object source, FileNode node)
|
||||
FileNodeSelectedEvent (Object source, FileNode node)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (source);
|
||||
@ -20,12 +20,19 @@ public class FileNodeSelectedEvent extends EventObject
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FileNode getFileNode ()
|
||||
FileNode getFileNode ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
String toText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return node.file.getAbsolutePath ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
@ -33,11 +40,4 @@ public class FileNodeSelectedEvent extends EventObject
|
||||
{
|
||||
return node.file.getAbsolutePath ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String toText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return node.file.getAbsolutePath ();
|
||||
}
|
||||
}
|
@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface FileNodeSelectionListener extends EventListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void fileNodeSelected (FileNodeSelectedEvent event);
|
||||
}
|
@ -1,41 +1,49 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.DualDosDisk;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
public class FileSelectedEvent extends EventObject
|
||||
{
|
||||
public final AppleFileSource appleFileSource;
|
||||
boolean redo;
|
||||
int volumeNo = -1;
|
||||
|
||||
public FileSelectedEvent (Object source, AppleFileSource appleFileSource)
|
||||
{
|
||||
super (source);
|
||||
this.appleFileSource = appleFileSource;
|
||||
|
||||
// If a file is selected from a disk which is contained in a Dual-dos disk, then the DDS
|
||||
// must be told so that it can ensure its internal currentDisk is set correctly
|
||||
FormattedDisk fd = appleFileSource.getFormattedDisk ();
|
||||
DualDosDisk ddd = (DualDosDisk) fd.getParent ();
|
||||
if (ddd != null)
|
||||
{
|
||||
ddd.setCurrentDisk (fd);
|
||||
volumeNo = ddd.getCurrentDiskNo ();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return appleFileSource.toString ();
|
||||
}
|
||||
|
||||
public String toText ()
|
||||
{
|
||||
return appleFileSource.getUniqueName ();
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
import com.bytezone.diskbrowser.disk.DualDosDisk;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class FileSelectedEvent extends EventObject
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public final AppleFileSource appleFileSource;
|
||||
boolean redo;
|
||||
int volumeNo = -1;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
FileSelectedEvent (Object source, AppleFileSource appleFileSource)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (source);
|
||||
this.appleFileSource = appleFileSource;
|
||||
|
||||
// If a file is selected from a disk which is contained in a Dual-dos disk, then the DDS
|
||||
// must be told so that it can ensure its internal currentDisk is set correctly
|
||||
FormattedDisk fd = appleFileSource.getFormattedDisk ();
|
||||
DualDosDisk ddd = (DualDosDisk) fd.getParent ();
|
||||
if (ddd != null)
|
||||
{
|
||||
ddd.setCurrentDisk (fd);
|
||||
volumeNo = ddd.getCurrentDiskNo ();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String toText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return appleFileSource.getUniqueName ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return appleFileSource.toString ();
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface FileSelectionListener extends EventListener
|
||||
{
|
||||
public void fileSelected (FileSelectedEvent event);
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface FileSelectionListener extends EventListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void fileSelected (FileSelectedEvent event);
|
||||
}
|
@ -1,47 +1,56 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
class HideCatalogAction extends AbstractAction
|
||||
{
|
||||
JFrame owner;
|
||||
JPanel catalogPanel;
|
||||
|
||||
public HideCatalogAction (JFrame owner, JPanel catalogPanel)
|
||||
{
|
||||
super ("Show catalog panel");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Show/hide the catalog panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt C"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_C);
|
||||
this.owner = owner;
|
||||
this.catalogPanel = catalogPanel;
|
||||
}
|
||||
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
set (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
|
||||
public void set (boolean show)
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
owner.add (catalogPanel, BorderLayout.WEST);
|
||||
owner.validate ();
|
||||
}
|
||||
else
|
||||
{
|
||||
owner.remove (catalogPanel);
|
||||
owner.validate ();
|
||||
}
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class HideCatalogAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
JFrame owner;
|
||||
JPanel catalogPanel;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public HideCatalogAction (JFrame owner, JPanel catalogPanel)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Show catalog panel");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Show/hide the catalog panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt C"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_C);
|
||||
this.owner = owner;
|
||||
this.catalogPanel = catalogPanel;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
set (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void set (boolean show)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
owner.add (catalogPanel, BorderLayout.WEST);
|
||||
owner.validate ();
|
||||
}
|
||||
else
|
||||
{
|
||||
owner.remove (catalogPanel);
|
||||
owner.validate ();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +1,56 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
class HideLayoutAction extends AbstractAction
|
||||
{
|
||||
JFrame owner;
|
||||
JPanel layoutPanel;
|
||||
|
||||
public HideLayoutAction (JFrame owner, JPanel layoutPanel)
|
||||
{
|
||||
super ("Show disk layout panel");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Show/hide the disk layout panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt D"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_D);
|
||||
this.owner = owner;
|
||||
this.layoutPanel = layoutPanel;
|
||||
}
|
||||
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
set (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
|
||||
public void set (boolean show)
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
owner.add (layoutPanel, BorderLayout.EAST);
|
||||
owner.validate ();
|
||||
}
|
||||
else
|
||||
{
|
||||
owner.remove (layoutPanel);
|
||||
owner.validate ();
|
||||
}
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class HideLayoutAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
JFrame owner;
|
||||
JPanel layoutPanel;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public HideLayoutAction (JFrame owner, JPanel layoutPanel)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Show disk layout panel");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Show/hide the disk layout panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt D"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_D);
|
||||
this.owner = owner;
|
||||
this.layoutPanel = layoutPanel;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
set (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void set (boolean show)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
owner.add (layoutPanel, BorderLayout.EAST);
|
||||
owner.validate ();
|
||||
}
|
||||
else
|
||||
{
|
||||
owner.remove (layoutPanel);
|
||||
owner.validate ();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,34 +1,42 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
public class InterleaveAction extends DefaultAction
|
||||
{
|
||||
int interleave;
|
||||
FormattedDisk currentDisk;
|
||||
static String[] names = { "No Interleave", "Prodos/Pascal", "Infocom", "CPM" };
|
||||
|
||||
public InterleaveAction (int interleave)
|
||||
{
|
||||
super (names[interleave], "Alter interleave");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt " + interleave));
|
||||
this.interleave = interleave;
|
||||
}
|
||||
|
||||
public void setDisk (FormattedDisk disk)
|
||||
{
|
||||
currentDisk = disk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
currentDisk.getDisk ().setInterleave (interleave);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class InterleaveAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
int interleave;
|
||||
FormattedDisk currentDisk;
|
||||
static String[] names = { "No Interleave", "Prodos/Pascal", "Infocom", "CPM" };
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
InterleaveAction (int interleave)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (names[interleave], "Alter interleave");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt " + interleave));
|
||||
this.interleave = interleave;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void setDisk (FormattedDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
currentDisk = disk;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
currentDisk.getDisk ().setInterleave (interleave);
|
||||
}
|
||||
}
|
@ -1,38 +1,46 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
class LineWrapAction extends AbstractAction
|
||||
{
|
||||
List<JTextArea> listeners = new ArrayList<> ();
|
||||
|
||||
public LineWrapAction ()
|
||||
{
|
||||
super ("Line wrap");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Print the contents of the output panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt W"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_W);
|
||||
}
|
||||
|
||||
public void addListener (JTextArea listener)
|
||||
{
|
||||
if (!listeners.contains (listener))
|
||||
listeners.add (listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
for (JTextArea listener : listeners)
|
||||
listener.setLineWrap (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class LineWrapAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
List<JTextArea> listeners = new ArrayList<> ();
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public LineWrapAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Line wrap");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Print the contents of the output panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt W"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_W);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addListener (JTextArea listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (!listeners.contains (listener))
|
||||
listeners.add (listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
for (JTextArea listener : listeners)
|
||||
listener.setLineWrap (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -8,11 +8,15 @@ import javax.swing.Action;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
public class MonochromeAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class MonochromeAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final DataPanel owner;
|
||||
|
||||
public MonochromeAction (DataPanel owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
MonochromeAction (DataPanel owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Monochrome");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Display image in monochrome or color");
|
||||
@ -21,8 +25,10 @@ public class MonochromeAction extends AbstractAction
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
owner.setMonochrome (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
|
@ -3,17 +3,26 @@ package com.bytezone.diskbrowser.gui;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.Palette;
|
||||
import com.bytezone.diskbrowser.applefile.PaletteFactory.CycleDirection;
|
||||
|
||||
public class NextPaletteAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class NextPaletteAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final DataPanel owner;
|
||||
private final ButtonGroup buttonGroup;
|
||||
|
||||
public NextPaletteAction (DataPanel owner, ButtonGroup buttonGroup)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
NextPaletteAction (DataPanel owner, ButtonGroup buttonGroup)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Next Palette");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Select next color palette");
|
||||
@ -22,8 +31,10 @@ public class NextPaletteAction extends AbstractAction
|
||||
this.buttonGroup = buttonGroup;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Palette palette = owner.cyclePalette (CycleDirection.FORWARDS);
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class NoDisksFoundException extends Exception
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
|
||||
// is this used?
|
||||
}
|
@ -7,12 +7,16 @@ import javax.swing.Action;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.Palette;
|
||||
|
||||
public class PaletteAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class PaletteAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final Palette palette;
|
||||
private final DataPanel owner;
|
||||
|
||||
public PaletteAction (DataPanel owner, Palette palette)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
PaletteAction (DataPanel owner, Palette palette)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (palette.getName ());
|
||||
putValue (Action.SHORT_DESCRIPTION, "Select color palette: " + palette.getName ());
|
||||
@ -20,8 +24,10 @@ public class PaletteAction extends AbstractAction
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
owner.selectPalette (palette);
|
||||
}
|
||||
|
@ -12,12 +12,16 @@ import com.bytezone.common.DefaultAction;
|
||||
|
||||
// ********** not currently used ***********
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class PreferencesAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
JFrame owner;
|
||||
Preferences prefs;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public PreferencesAction (JFrame owner, Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Preferences...", "Set preferences", "/com/bytezone/diskbrowser/icons/");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt P"));
|
||||
@ -28,13 +32,17 @@ public class PreferencesAction extends DefaultAction
|
||||
this.prefs = prefs;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
prefs ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void prefs ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
new PreferencesDialog (owner, prefs);
|
||||
}
|
||||
|
@ -6,13 +6,25 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.InputMap;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SpringLayout;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.bytezone.common.FontTester;
|
||||
import com.bytezone.input.SpringUtilities;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class PreferencesDialog extends JDialog
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
static final String prefsCatalogFont = "CatalogFont";
|
||||
static final String prefsDataFont = "DataFont";
|
||||
@ -38,7 +50,9 @@ class PreferencesDialog extends JDialog
|
||||
private int catalogFontSize;
|
||||
private int dataFontSize;
|
||||
|
||||
public PreferencesDialog (JFrame owner, Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
PreferencesDialog (JFrame owner, Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (owner, "Set Preferences", false);
|
||||
|
||||
@ -96,7 +110,9 @@ class PreferencesDialog extends JDialog
|
||||
setVisible (true);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private JComponent getCommandPanel ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
JButton cancel = new JButton ("Cancel");
|
||||
cancel.addActionListener (new ActionListener ()
|
||||
@ -139,7 +155,9 @@ class PreferencesDialog extends JDialog
|
||||
return commandPanel;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void updatePreferences ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String newFontName = (String) catalogFontList.getSelectedItem ();
|
||||
if (!newFontName.equals (catalogFontName))
|
||||
@ -170,7 +188,9 @@ class PreferencesDialog extends JDialog
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addCancelByEscapeKey ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY";
|
||||
int noModifiers = 0;
|
||||
@ -189,12 +209,16 @@ class PreferencesDialog extends JDialog
|
||||
getRootPane ().getActionMap ().put (CANCEL_ACTION_KEY, cancelAction);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void closeDialog ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
dispose ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class Listener implements ActionListener
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
|
@ -3,17 +3,26 @@ package com.bytezone.diskbrowser.gui;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.Palette;
|
||||
import com.bytezone.diskbrowser.applefile.PaletteFactory.CycleDirection;
|
||||
|
||||
public class PreviousPaletteAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class PreviousPaletteAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final DataPanel owner;
|
||||
private final ButtonGroup buttonGroup;
|
||||
|
||||
public PreviousPaletteAction (DataPanel owner, ButtonGroup buttonGroup)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
PreviousPaletteAction (DataPanel owner, ButtonGroup buttonGroup)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Previous Palette");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Select previous color palette");
|
||||
@ -22,8 +31,10 @@ public class PreviousPaletteAction extends AbstractAction
|
||||
this.buttonGroup = buttonGroup;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Palette palette = owner.cyclePalette (CycleDirection.BACKWARDS);
|
||||
|
||||
|
@ -1,56 +1,62 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.print.PrinterException;
|
||||
import java.awt.print.PrinterJob;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
class PrintAction extends DefaultAction
|
||||
{
|
||||
DataPanel owner;
|
||||
|
||||
public PrintAction (DataPanel owner)
|
||||
{
|
||||
super ("Print...", "Print the contents of the output panel",
|
||||
"/com/bytezone/diskbrowser/icons/");
|
||||
int mask = Toolkit.getDefaultToolkit ().getMenuShortcutKeyMaskEx ();
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_P, mask));
|
||||
// putValue (Action.MNEMONIC_KEY, KeyEvent.VK_P);
|
||||
|
||||
this.owner = owner;
|
||||
|
||||
setIcon (Action.SMALL_ICON, "printer_16.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "printer_32.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
Runnable runner = new Runnable ()
|
||||
{
|
||||
@Override
|
||||
public void run ()
|
||||
{
|
||||
try
|
||||
{
|
||||
PrinterJob job = PrinterJob.getPrinterJob ();
|
||||
job.setPrintable (new PrintDocument (owner.getCurrentText ()));
|
||||
if (job.printDialog ())
|
||||
job.print ();
|
||||
}
|
||||
catch (PrinterException e)
|
||||
{
|
||||
System.out.println ("printer error");
|
||||
}
|
||||
}
|
||||
};
|
||||
EventQueue.invokeLater (runner);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.print.PrinterException;
|
||||
import java.awt.print.PrinterJob;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class PrintAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
DataPanel owner;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public PrintAction (DataPanel owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Print...", "Print the contents of the output panel",
|
||||
"/com/bytezone/diskbrowser/icons/");
|
||||
int mask = Toolkit.getDefaultToolkit ().getMenuShortcutKeyMaskEx ();
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_P, mask));
|
||||
// putValue (Action.MNEMONIC_KEY, KeyEvent.VK_P);
|
||||
|
||||
this.owner = owner;
|
||||
|
||||
setIcon (Action.SMALL_ICON, "printer_16.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "printer_32.png");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Runnable runner = new Runnable ()
|
||||
{
|
||||
@Override
|
||||
public void run ()
|
||||
{
|
||||
try
|
||||
{
|
||||
PrinterJob job = PrinterJob.getPrinterJob ();
|
||||
job.setPrintable (new PrintDocument (owner.getCurrentText ()));
|
||||
if (job.printDialog ())
|
||||
job.print ();
|
||||
}
|
||||
catch (PrinterException e)
|
||||
{
|
||||
System.out.println ("printer error");
|
||||
}
|
||||
}
|
||||
};
|
||||
EventQueue.invokeLater (runner);
|
||||
}
|
||||
}
|
@ -1,129 +1,139 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.Printable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
class PrintDocument extends Component implements Printable
|
||||
{
|
||||
String lines[];
|
||||
int lineHeight;
|
||||
int pages;
|
||||
Font font = new Font ("Lucida Sans Typewriter", Font.PLAIN, 7);
|
||||
int linesPerPage;
|
||||
int x = 50;
|
||||
int y = 20;
|
||||
|
||||
public PrintDocument (String text)
|
||||
{
|
||||
lines = wrapText (text, 112);
|
||||
}
|
||||
|
||||
public int print (Graphics g, PageFormat pageFormat, int page)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
if (lineHeight == 0)
|
||||
{
|
||||
LineMetrics lm = font.getLineMetrics ("0", g2.getFontRenderContext ());
|
||||
lineHeight = (int) lm.getHeight ();
|
||||
linesPerPage = (int) pageFormat.getImageableHeight () / lineHeight - 5;
|
||||
pages = (lines.length - 1) / linesPerPage;
|
||||
}
|
||||
|
||||
if (pages < page)
|
||||
return Printable.NO_SUCH_PAGE;
|
||||
|
||||
g2.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
|
||||
g2.setPaint (Color.black);
|
||||
g2.setStroke (new BasicStroke (2));
|
||||
|
||||
g2.setFont (font);
|
||||
|
||||
int first = page * linesPerPage;
|
||||
int last = first + linesPerPage;
|
||||
if (last > lines.length)
|
||||
last = lines.length;
|
||||
|
||||
for (int line = first; line < last; line++)
|
||||
g2.drawString (lines[line], x, y + (line % linesPerPage + 2) * lineHeight);
|
||||
|
||||
return (PAGE_EXISTS);
|
||||
}
|
||||
|
||||
// Routine copied from http://progcookbook.blogspot.com/2006/02/text-wrapping-function-for-java.html
|
||||
static String[] wrapText (String text, int len)
|
||||
{
|
||||
// return empty array for null text
|
||||
if (text == null)
|
||||
return new String[] {};
|
||||
|
||||
// return text if len is zero or less
|
||||
if (len <= 0)
|
||||
return new String[] { text };
|
||||
|
||||
// return text if less than length
|
||||
if (text.length () <= len)
|
||||
return new String[] { text };
|
||||
|
||||
char[] chars = text.toCharArray ();
|
||||
Vector<String> lines = new Vector<String> ();
|
||||
StringBuilder line = new StringBuilder ();
|
||||
StringBuilder word = new StringBuilder ();
|
||||
|
||||
for (int i = 0; i < chars.length; i++)
|
||||
{
|
||||
if (chars[i] == 10)
|
||||
{
|
||||
line.append (word);
|
||||
word.delete (0, word.length ());
|
||||
lines.add (line.toString ());
|
||||
line.delete (0, line.length ());
|
||||
continue;
|
||||
}
|
||||
|
||||
word.append (chars[i]);
|
||||
|
||||
if (chars[i] == ' ')
|
||||
{
|
||||
if ((line.length () + word.length ()) > len)
|
||||
{
|
||||
lines.add (line.toString ());
|
||||
line.delete (0, line.length ());
|
||||
}
|
||||
|
||||
line.append (word);
|
||||
word.delete (0, word.length ());
|
||||
}
|
||||
}
|
||||
|
||||
// handle any extra chars in current word
|
||||
if (word.length () > 0)
|
||||
{
|
||||
if ((line.length () + word.length ()) > len)
|
||||
{
|
||||
lines.add (line.toString ());
|
||||
line.delete (0, line.length ());
|
||||
}
|
||||
line.append (word);
|
||||
}
|
||||
|
||||
// handle extra line
|
||||
if (line.length () > 0)
|
||||
lines.add (line.toString ());
|
||||
|
||||
String[] ret = new String[lines.size ()];
|
||||
int c = 0; // counter
|
||||
for (Enumeration<String> e = lines.elements (); e.hasMoreElements (); c++)
|
||||
ret[c] = e.nextElement ();
|
||||
|
||||
return ret;
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.Printable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class PrintDocument extends Component implements Printable
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
String lines[];
|
||||
int lineHeight;
|
||||
int pages;
|
||||
Font font = new Font ("Lucida Sans Typewriter", Font.PLAIN, 7);
|
||||
int linesPerPage;
|
||||
int x = 50;
|
||||
int y = 20;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
PrintDocument (String text)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
lines = wrapText (text, 112);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public int print (Graphics g, PageFormat pageFormat, int page)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
if (lineHeight == 0)
|
||||
{
|
||||
LineMetrics lm = font.getLineMetrics ("0", g2.getFontRenderContext ());
|
||||
lineHeight = (int) lm.getHeight ();
|
||||
linesPerPage = (int) pageFormat.getImageableHeight () / lineHeight - 5;
|
||||
pages = (lines.length - 1) / linesPerPage;
|
||||
}
|
||||
|
||||
if (pages < page)
|
||||
return Printable.NO_SUCH_PAGE;
|
||||
|
||||
g2.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
|
||||
g2.setPaint (Color.black);
|
||||
g2.setStroke (new BasicStroke (2));
|
||||
|
||||
g2.setFont (font);
|
||||
|
||||
int first = page * linesPerPage;
|
||||
int last = first + linesPerPage;
|
||||
if (last > lines.length)
|
||||
last = lines.length;
|
||||
|
||||
for (int line = first; line < last; line++)
|
||||
g2.drawString (lines[line], x, y + (line % linesPerPage + 2) * lineHeight);
|
||||
|
||||
return (PAGE_EXISTS);
|
||||
}
|
||||
|
||||
// Routine copied from http://progcookbook.blogspot.com/
|
||||
// 2006/02/text-wrapping-function-for-java.html
|
||||
// ---------------------------------------------------------------------------------//
|
||||
static String[] wrapText (String text, int len)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// return empty array for null text
|
||||
if (text == null)
|
||||
return new String[] {};
|
||||
|
||||
// return text if len is zero or less
|
||||
if (len <= 0)
|
||||
return new String[] { text };
|
||||
|
||||
// return text if less than length
|
||||
if (text.length () <= len)
|
||||
return new String[] { text };
|
||||
|
||||
char[] chars = text.toCharArray ();
|
||||
Vector<String> lines = new Vector<String> ();
|
||||
StringBuilder line = new StringBuilder ();
|
||||
StringBuilder word = new StringBuilder ();
|
||||
|
||||
for (int i = 0; i < chars.length; i++)
|
||||
{
|
||||
if (chars[i] == 10)
|
||||
{
|
||||
line.append (word);
|
||||
word.delete (0, word.length ());
|
||||
lines.add (line.toString ());
|
||||
line.delete (0, line.length ());
|
||||
continue;
|
||||
}
|
||||
|
||||
word.append (chars[i]);
|
||||
|
||||
if (chars[i] == ' ')
|
||||
{
|
||||
if ((line.length () + word.length ()) > len)
|
||||
{
|
||||
lines.add (line.toString ());
|
||||
line.delete (0, line.length ());
|
||||
}
|
||||
|
||||
line.append (word);
|
||||
word.delete (0, word.length ());
|
||||
}
|
||||
}
|
||||
|
||||
// handle any extra chars in current word
|
||||
if (word.length () > 0)
|
||||
{
|
||||
if ((line.length () + word.length ()) > len)
|
||||
{
|
||||
lines.add (line.toString ());
|
||||
line.delete (0, line.length ());
|
||||
}
|
||||
line.append (word);
|
||||
}
|
||||
|
||||
// handle extra line
|
||||
if (line.length () > 0)
|
||||
lines.add (line.toString ());
|
||||
|
||||
String[] ret = new String[lines.size ()];
|
||||
int c = 0; // counter
|
||||
for (Enumeration<String> e = lines.elements (); e.hasMoreElements (); c++)
|
||||
ret[c] = e.nextElement ();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -1,15 +1,19 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class ProdosPreferences
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public boolean sortDirectories;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
text.append (String.format ("Sort directies ........ %s%n", sortDirectories));
|
||||
text.append (String.format ("Sort directories ...... %s%n", sortDirectories));
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface ProdosPreferencesListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void setProdosPreferences (ProdosPreferences prodosPreferences);
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface QuitListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void quit (Preferences preferences);
|
||||
|
||||
|
@ -1,34 +1,40 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
class RefreshTreeAction extends DefaultAction
|
||||
{
|
||||
CatalogPanel owner;
|
||||
|
||||
public RefreshTreeAction (CatalogPanel owner)
|
||||
{
|
||||
super ("Refresh current tree", "Makes newly added/modified disks available",
|
||||
"/com/bytezone/diskbrowser/icons/");
|
||||
// putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt R"));
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_F5, 0));
|
||||
// putValue (Action.MNEMONIC_KEY, KeyEvent.VK_R);
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_F5);
|
||||
this.owner = owner;
|
||||
|
||||
setIcon (Action.SMALL_ICON, "arrow_refresh.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "arrow_refresh_32.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
owner.refreshTree ();
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class RefreshTreeAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
CatalogPanel owner;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public RefreshTreeAction (CatalogPanel owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Refresh current tree", "Makes newly added/modified disks available",
|
||||
"/com/bytezone/diskbrowser/icons/");
|
||||
// putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt R"));
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke (KeyEvent.VK_F5, 0));
|
||||
// putValue (Action.MNEMONIC_KEY, KeyEvent.VK_R);
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_F5);
|
||||
this.owner = owner;
|
||||
|
||||
setIcon (Action.SMALL_ICON, "arrow_refresh.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "arrow_refresh_32.png");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
owner.refreshTree ();
|
||||
}
|
||||
}
|
@ -1,89 +1,103 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.common.Platform;
|
||||
|
||||
public class RootDirectoryAction extends DefaultAction implements QuitListener
|
||||
{
|
||||
private static final String prefsRootDirectory = "Root directory";
|
||||
private final List<RootDirectoryChangeListener> listeners = new ArrayList<> ();
|
||||
private File rootFolder;
|
||||
|
||||
public RootDirectoryAction ()
|
||||
{
|
||||
super ("Set HOME folder...", "Defines root folder where the disk images are kept",
|
||||
"/com/bytezone/diskbrowser/icons/");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt H"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_H);
|
||||
|
||||
setIcon (Action.SMALL_ICON, "folder_explore_16.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "folder_explore_32.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
JFileChooser chooser = new JFileChooser (Platform.userHome);
|
||||
chooser.setDialogTitle ("Select FOLDER containing disk images");
|
||||
chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
|
||||
if (rootFolder != null)
|
||||
chooser.setSelectedFile (rootFolder);
|
||||
|
||||
int result = chooser.showDialog (null, "Accept");
|
||||
if (result == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
File rootDirectoryFile = chooser.getSelectedFile ();
|
||||
if (!rootDirectoryFile.isDirectory ())
|
||||
rootDirectoryFile = rootDirectoryFile.getParentFile ();
|
||||
if (rootDirectoryFile != null)
|
||||
notifyListeners (rootDirectoryFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener (RootDirectoryChangeListener listener)
|
||||
{
|
||||
if (!listeners.contains (listener))
|
||||
listeners.add (listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quit (Preferences prefs)
|
||||
{
|
||||
prefs.put (prefsRootDirectory,
|
||||
rootFolder == null ? "" : rootFolder.getAbsolutePath ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore (Preferences prefs)
|
||||
{
|
||||
String rootDirectory = prefs.get (prefsRootDirectory, "");
|
||||
|
||||
File rootDirectoryFile = new File (rootDirectory);
|
||||
|
||||
if (!rootDirectoryFile.exists () || !rootDirectoryFile.isDirectory ())
|
||||
{
|
||||
System.out.println ("No root directory");
|
||||
return;
|
||||
}
|
||||
notifyListeners (rootDirectoryFile);
|
||||
}
|
||||
|
||||
private void notifyListeners (File newRootFolder)
|
||||
{
|
||||
File oldRootFolder = rootFolder;
|
||||
rootFolder = newRootFolder;
|
||||
for (RootDirectoryChangeListener listener : listeners)
|
||||
listener.rootDirectoryChanged (oldRootFolder, newRootFolder);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.common.Platform;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class RootDirectoryAction extends DefaultAction implements QuitListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final String prefsRootDirectory = "Root directory";
|
||||
private final List<RootDirectoryChangeListener> listeners = new ArrayList<> ();
|
||||
private File rootFolder;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
RootDirectoryAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Set HOME folder...", "Defines root folder where the disk images are kept",
|
||||
"/com/bytezone/diskbrowser/icons/");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt H"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_H);
|
||||
|
||||
setIcon (Action.SMALL_ICON, "folder_explore_16.png");
|
||||
setIcon (Action.LARGE_ICON_KEY, "folder_explore_32.png");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
JFileChooser chooser = new JFileChooser (Platform.userHome);
|
||||
chooser.setDialogTitle ("Select FOLDER containing disk images");
|
||||
chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
|
||||
if (rootFolder != null)
|
||||
chooser.setSelectedFile (rootFolder);
|
||||
|
||||
int result = chooser.showDialog (null, "Accept");
|
||||
if (result == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
File rootDirectoryFile = chooser.getSelectedFile ();
|
||||
if (!rootDirectoryFile.isDirectory ())
|
||||
rootDirectoryFile = rootDirectoryFile.getParentFile ();
|
||||
if (rootDirectoryFile != null)
|
||||
notifyListeners (rootDirectoryFile);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void addListener (RootDirectoryChangeListener listener)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (!listeners.contains (listener))
|
||||
listeners.add (listener);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void quit (Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
prefs.put (prefsRootDirectory,
|
||||
rootFolder == null ? "" : rootFolder.getAbsolutePath ());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void restore (Preferences prefs)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String rootDirectory = prefs.get (prefsRootDirectory, "");
|
||||
|
||||
File rootDirectoryFile = new File (rootDirectory);
|
||||
|
||||
if (!rootDirectoryFile.exists () || !rootDirectoryFile.isDirectory ())
|
||||
{
|
||||
System.out.println ("No root directory");
|
||||
return;
|
||||
}
|
||||
notifyListeners (rootDirectoryFile);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void notifyListeners (File newRootFolder)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
File oldRootFolder = rootFolder;
|
||||
rootFolder = newRootFolder;
|
||||
for (RootDirectoryChangeListener listener : listeners)
|
||||
listener.rootDirectoryChanged (oldRootFolder, newRootFolder);
|
||||
}
|
||||
}
|
@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface RootDirectoryChangeListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder);
|
||||
}
|
||||
|
@ -11,18 +11,24 @@ import javax.swing.JOptionPane;
|
||||
|
||||
import com.bytezone.common.DefaultAction;
|
||||
|
||||
public class SaveSectorsAction extends DefaultAction implements SectorSelectionListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class SaveSectorsAction extends DefaultAction implements SectorSelectionListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
SectorSelectedEvent event;
|
||||
|
||||
public SaveSectorsAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
SaveSectorsAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Save sectors...", "Save sectors");
|
||||
this.setEnabled (false);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent evt)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (event == null)
|
||||
{
|
||||
@ -50,8 +56,10 @@ public class SaveSectorsAction extends DefaultAction implements SectorSelectionL
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void sectorSelected (SectorSelectedEvent event)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.event = event;
|
||||
this.setEnabled (true);
|
||||
|
@ -11,17 +11,23 @@ import javax.swing.JOptionPane;
|
||||
import com.bytezone.common.DefaultAction;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
|
||||
public class SaveTempFileAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class SaveTempFileAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
FormattedDisk disk;
|
||||
|
||||
public SaveTempFileAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
SaveTempFileAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Save converted disk...", "Save converted disk");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent evt)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (disk == null)
|
||||
{
|
||||
@ -48,7 +54,9 @@ public class SaveTempFileAction extends DefaultAction
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void setDisk (FormattedDisk disk)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.disk = disk;
|
||||
this.setEnabled (true);
|
||||
|
@ -13,7 +13,9 @@ import com.bytezone.common.Platform.FontSize;
|
||||
import com.bytezone.common.Platform.FontType;
|
||||
import com.bytezone.diskbrowser.gui.DiskLayoutPanel.LayoutDetails;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class ScrollRuler extends JComponent
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
// dimensions of the ruler
|
||||
public static final int HEIGHT = 20;
|
||||
@ -29,7 +31,9 @@ class ScrollRuler extends JComponent
|
||||
private LayoutDetails layoutDetails;
|
||||
private final JComponent image;
|
||||
|
||||
public ScrollRuler (JComponent image, int orientation)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
ScrollRuler (JComponent image, int orientation)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.orientation = orientation;
|
||||
this.image = image;
|
||||
@ -41,7 +45,9 @@ class ScrollRuler extends JComponent
|
||||
setPreferredSize (new Dimension (WIDTH, 0));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setLayout (LayoutDetails layout)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.layoutDetails = layout;
|
||||
|
||||
@ -56,20 +62,26 @@ class ScrollRuler extends JComponent
|
||||
setTrackMode (layout.grid.width == 16 || layout.grid.width == 13);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setTrackMode (boolean trackMode)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
isTrackMode = trackMode;
|
||||
repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public void setHex (boolean hex)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
isHex = hex;
|
||||
repaint ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
protected void paintComponent (Graphics g)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
Rectangle clipRect = g.getClipBounds ();
|
||||
g.setColor (Color.WHITE);
|
||||
@ -87,7 +99,9 @@ class ScrollRuler extends JComponent
|
||||
drawVertical (g, clipRect, layoutDetails.block.height);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void drawHorizontal (Graphics g, Rectangle clipRect, int width)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int start = (clipRect.x / width);
|
||||
int end = start + clipRect.width / width;
|
||||
@ -111,7 +125,9 @@ class ScrollRuler extends JComponent
|
||||
g.drawString (String.format (format, i), i * width + offset, 15);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void drawVertical (Graphics g, Rectangle clipRect, int height)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int start = (clipRect.y / height);
|
||||
int end = start + clipRect.height / height;
|
||||
|
@ -1,50 +1,63 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.disk.SectorListConverter;
|
||||
|
||||
public class SectorSelectedEvent extends EventObject
|
||||
{
|
||||
private final List<DiskAddress> sectors;
|
||||
private final FormattedDisk owner;
|
||||
boolean redo;
|
||||
|
||||
public SectorSelectedEvent (Object source, List<DiskAddress> sectors, FormattedDisk owner)
|
||||
{
|
||||
super (source);
|
||||
this.sectors = sectors;
|
||||
// always store the parent if this disk is part of a dual-dos disk
|
||||
this.owner = owner.getParent () == null ? owner : owner.getParent ();
|
||||
}
|
||||
|
||||
public List<DiskAddress> getSectors ()
|
||||
{
|
||||
return sectors;
|
||||
}
|
||||
|
||||
public FormattedDisk getFormattedDisk ()
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
public String toText ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
SectorListConverter slc = new SectorListConverter (sectors);
|
||||
text.append (slc.sectorText);
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
public static SectorSelectedEvent create (Object source, FormattedDisk owner, String sectorsText)
|
||||
{
|
||||
if (sectorsText.startsWith ("$"))
|
||||
sectorsText = sectorsText.substring (3); // only for old records
|
||||
|
||||
SectorListConverter slc = new SectorListConverter (sectorsText, owner.getDisk ());
|
||||
return new SectorSelectedEvent (source, slc.sectors, owner);
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.disk.SectorListConverter;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class SectorSelectedEvent extends EventObject
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final List<DiskAddress> sectors;
|
||||
private final FormattedDisk owner;
|
||||
boolean redo;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
SectorSelectedEvent (Object source, List<DiskAddress> sectors, FormattedDisk owner)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (source);
|
||||
this.sectors = sectors;
|
||||
// always store the parent if this disk is part of a dual-dos disk
|
||||
this.owner = owner.getParent () == null ? owner : owner.getParent ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public List<DiskAddress> getSectors ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return sectors;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FormattedDisk getFormattedDisk ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public String toText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
SectorListConverter slc = new SectorListConverter (sectors);
|
||||
text.append (slc.sectorText);
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public static SectorSelectedEvent create (Object source, FormattedDisk owner,
|
||||
String sectorsText)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (sectorsText.startsWith ("$"))
|
||||
sectorsText = sectorsText.substring (3); // only for old records
|
||||
|
||||
SectorListConverter slc = new SectorListConverter (sectorsText, owner.getDisk ());
|
||||
return new SectorSelectedEvent (source, slc.sectors, owner);
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface SectorSelectionListener extends EventListener
|
||||
{
|
||||
public void sectorSelected (SectorSelectedEvent event);
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public interface SectorSelectionListener extends EventListener
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void sectorSelected (SectorSelectedEvent event);
|
||||
}
|
@ -1,31 +1,37 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
class ShowFreeSectorsAction extends AbstractAction
|
||||
{
|
||||
DiskLayoutPanel panel;
|
||||
MenuHandler mh;
|
||||
|
||||
public ShowFreeSectorsAction (MenuHandler mh, DiskLayoutPanel panel)
|
||||
{
|
||||
super ("Show free sectors");
|
||||
putValue (Action.SHORT_DESCRIPTION,
|
||||
"Display which sectors are marked free in the disk layout panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt F"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_F);
|
||||
this.panel = panel;
|
||||
this.mh = mh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
panel.setFree (mh.showFreeSectorsItem.isSelected ());
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class ShowFreeSectorsAction extends AbstractAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
DiskLayoutPanel panel;
|
||||
MenuHandler mh;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
ShowFreeSectorsAction (MenuHandler mh, DiskLayoutPanel panel)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Show free sectors");
|
||||
putValue (Action.SHORT_DESCRIPTION,
|
||||
"Display which sectors are marked free in the disk layout panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt F"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_F);
|
||||
this.panel = panel;
|
||||
this.mh = mh;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
panel.setFree (mh.showFreeSectorsItem.isSelected ());
|
||||
}
|
||||
}
|
@ -1,18 +1,20 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
/***********************************************************************************************
|
||||
* Interface implemented by AbstractTab, and in turn FileSystemTab and AppleDiskTab.
|
||||
*
|
||||
*
|
||||
***********************************************************************************************/
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
interface Tab
|
||||
{
|
||||
public void refresh ();
|
||||
|
||||
public void activate ();
|
||||
|
||||
public DefaultMutableTreeNode getRootNode ();
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
/***********************************************************************************************
|
||||
* Interface implemented by AbstractTab, and in turn FileSystemTab and AppleDiskTab.
|
||||
*
|
||||
*
|
||||
***********************************************************************************************/
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
interface Tab
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
public void refresh ();
|
||||
|
||||
public void activate ();
|
||||
|
||||
public DefaultMutableTreeNode getRootNode ();
|
||||
}
|
||||
|
@ -1,266 +1,266 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.DiskFactory;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.utilities.FileFormatException;
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class TreeBuilder
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat ("dd MMM yyyy");
|
||||
|
||||
private final FileComparator fileComparator = new FileComparator ();
|
||||
private final JTree tree;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public TreeBuilder (File rootFolder)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
assert (rootFolder.exists ());
|
||||
assert (rootFolder.isDirectory ());
|
||||
|
||||
FileNode fileNode = new FileNode (rootFolder);
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode (fileNode);
|
||||
fileNode.setTreeNode (root);
|
||||
|
||||
addFiles (root, rootFolder);
|
||||
DefaultTreeModel treeModel = new DefaultTreeModel (root);
|
||||
tree = new JTree (treeModel);
|
||||
|
||||
treeModel.setAsksAllowsChildren (true); // allows empty nodes to appear as folders
|
||||
setDiskIcon ("/com/bytezone/diskbrowser/icons/disk.png");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public JTree getTree ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return tree;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addFiles (DefaultMutableTreeNode parentNode, File directory)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
File[] files = directory.listFiles ();
|
||||
if (files == null || files.length == 0)
|
||||
{
|
||||
System.out.println ("Empty folder : " + directory.getAbsolutePath ());
|
||||
return;
|
||||
}
|
||||
|
||||
Arrays.sort (files, fileComparator);
|
||||
|
||||
for (File file : files)
|
||||
{
|
||||
if (file.isHidden ())
|
||||
continue;
|
||||
if (file.isDirectory ())
|
||||
parentNode.add (createNode (file, true));
|
||||
else if (Utility.validFileType (file.getName ()) && file.length () > 0)
|
||||
parentNode.add (createNode (file, false));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private DefaultMutableTreeNode createNode (File file, boolean allowsChildren)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
FileNode fileNode = new FileNode (file);
|
||||
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode (fileNode);
|
||||
fileNode.setTreeNode (newNode);
|
||||
newNode.setAllowsChildren (allowsChildren);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setDiskIcon (String iconName)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
URL url = this.getClass ().getResource (iconName);
|
||||
if (url != null)
|
||||
{
|
||||
ImageIcon icon = new ImageIcon (url);
|
||||
DefaultTreeCellRenderer renderer =
|
||||
(DefaultTreeCellRenderer) tree.getCellRenderer ();
|
||||
renderer.setLeafIcon (icon);
|
||||
tree.setCellRenderer (renderer);
|
||||
tree.setRowHeight (18);
|
||||
}
|
||||
else
|
||||
System.out.println ("Failed to set the disk icon : " + iconName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class used to control the text displayed by the JTree.
|
||||
*/
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public class FileNode implements DataSource // why does it implement DataSource?
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
DefaultMutableTreeNode parentNode;
|
||||
public final File file;
|
||||
private static final int MAX_NAME_LENGTH = 36;
|
||||
private static final int SUFFIX_LENGTH = 12;
|
||||
private static final int PREFIX_LENGTH = MAX_NAME_LENGTH - SUFFIX_LENGTH - 3;
|
||||
private FormattedDisk formattedDisk;
|
||||
int disks;
|
||||
boolean showDisks;
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
public FileNode (File file)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
public void setTreeNode (DefaultMutableTreeNode node)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
this.parentNode = node;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
public void readFiles ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
addFiles (parentNode, file);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
public FormattedDisk getFormattedDisk ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
if (formattedDisk == null)
|
||||
try
|
||||
{
|
||||
formattedDisk = DiskFactory.createDisk (file);
|
||||
}
|
||||
catch (FileFormatException e)
|
||||
{
|
||||
System.out.println ("Swallowing a FileFormatException in TreeBuilder");
|
||||
System.out.println (e.getMessage ());
|
||||
return null;
|
||||
}
|
||||
return formattedDisk;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
public boolean replaceDisk (FormattedDisk disk)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
String path = disk.getDisk ().getFile ().getAbsolutePath ();
|
||||
if (formattedDisk != null && path.equals (file.getAbsolutePath ()))
|
||||
{
|
||||
formattedDisk = disk;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
String name = file.getName ();
|
||||
if (name.length () > MAX_NAME_LENGTH)
|
||||
name = name.substring (0, PREFIX_LENGTH) + "..."
|
||||
+ name.substring (name.length () - SUFFIX_LENGTH);
|
||||
if (showDisks && disks > 0)
|
||||
return String.format ("%s (%,d)", name, disks);
|
||||
return name;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getText ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
String home = System.getProperty ("user.home");
|
||||
String path = file.getAbsolutePath ();
|
||||
if (path.startsWith (home))
|
||||
path = "~" + path.substring (home.length ());
|
||||
text.append ("Directory : " + path + "\n\n");
|
||||
text.append ("D File names "
|
||||
+ " Date Size Type\n");
|
||||
text.append ("- ----------------------------------------"
|
||||
+ " ----------- -------------- ---------\n");
|
||||
|
||||
File[] files = file.listFiles ();
|
||||
if (files != null)
|
||||
{
|
||||
Arrays.sort (files, fileComparator);
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.isHidden ())
|
||||
continue;
|
||||
String name = f.getName ();
|
||||
|
||||
Date d = new Date (f.lastModified ());
|
||||
int pos = name.lastIndexOf ('.');
|
||||
String type = pos > 0 && !f.isDirectory () ? name.substring (pos) : "";
|
||||
String size = f.isDirectory () ? "" : String.format ("%,14d", f.length ());
|
||||
text.append (String.format ("%s %-40.40s %s %-14s %s%n",
|
||||
f.isDirectory () ? "D" : " ", name, sdf.format (d).replace (".", ""), size,
|
||||
type));
|
||||
}
|
||||
}
|
||||
|
||||
if (text.length () > 0)
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getAssembler ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getHexDump ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public BufferedImage getImage ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public JComponent getComponent ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.DiskFactory;
|
||||
import com.bytezone.diskbrowser.disk.FormattedDisk;
|
||||
import com.bytezone.diskbrowser.utilities.FileFormatException;
|
||||
import com.bytezone.diskbrowser.utilities.Utility;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class TreeBuilder
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat ("dd MMM yyyy");
|
||||
|
||||
private final FileComparator fileComparator = new FileComparator ();
|
||||
private final JTree tree;
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
TreeBuilder (File rootFolder)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
assert (rootFolder.exists ());
|
||||
assert (rootFolder.isDirectory ());
|
||||
|
||||
FileNode fileNode = new FileNode (rootFolder);
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode (fileNode);
|
||||
fileNode.setTreeNode (root);
|
||||
|
||||
addFiles (root, rootFolder);
|
||||
DefaultTreeModel treeModel = new DefaultTreeModel (root);
|
||||
tree = new JTree (treeModel);
|
||||
|
||||
treeModel.setAsksAllowsChildren (true); // allows empty nodes to appear as folders
|
||||
setDiskIcon ("/com/bytezone/diskbrowser/icons/disk.png");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
JTree getTree ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return tree;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void addFiles (DefaultMutableTreeNode parentNode, File directory)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
File[] files = directory.listFiles ();
|
||||
if (files == null || files.length == 0)
|
||||
{
|
||||
System.out.println ("Empty folder : " + directory.getAbsolutePath ());
|
||||
return;
|
||||
}
|
||||
|
||||
Arrays.sort (files, fileComparator);
|
||||
|
||||
for (File file : files)
|
||||
{
|
||||
if (file.isHidden ())
|
||||
continue;
|
||||
if (file.isDirectory ())
|
||||
parentNode.add (createNode (file, true));
|
||||
else if (Utility.validFileType (file.getName ()) && file.length () > 0)
|
||||
parentNode.add (createNode (file, false));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private DefaultMutableTreeNode createNode (File file, boolean allowsChildren)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
FileNode fileNode = new FileNode (file);
|
||||
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode (fileNode);
|
||||
fileNode.setTreeNode (newNode);
|
||||
newNode.setAllowsChildren (allowsChildren);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void setDiskIcon (String iconName)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
URL url = this.getClass ().getResource (iconName);
|
||||
if (url != null)
|
||||
{
|
||||
ImageIcon icon = new ImageIcon (url);
|
||||
DefaultTreeCellRenderer renderer =
|
||||
(DefaultTreeCellRenderer) tree.getCellRenderer ();
|
||||
renderer.setLeafIcon (icon);
|
||||
tree.setCellRenderer (renderer);
|
||||
tree.setRowHeight (18);
|
||||
}
|
||||
else
|
||||
System.out.println ("Failed to set the disk icon : " + iconName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class used to control the text displayed by the JTree.
|
||||
*/
|
||||
// ---------------------------------------------------------------------------------//
|
||||
class FileNode implements DataSource // why does it implement DataSource?
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
DefaultMutableTreeNode parentNode;
|
||||
public final File file;
|
||||
private static final int MAX_NAME_LENGTH = 36;
|
||||
private static final int SUFFIX_LENGTH = 12;
|
||||
private static final int PREFIX_LENGTH = MAX_NAME_LENGTH - SUFFIX_LENGTH - 3;
|
||||
private FormattedDisk formattedDisk;
|
||||
int disks;
|
||||
boolean showDisks;
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
FileNode (File file)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
void setTreeNode (DefaultMutableTreeNode node)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
this.parentNode = node;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
void readFiles ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
addFiles (parentNode, file);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
FormattedDisk getFormattedDisk ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
if (formattedDisk == null)
|
||||
try
|
||||
{
|
||||
formattedDisk = DiskFactory.createDisk (file);
|
||||
}
|
||||
catch (FileFormatException e)
|
||||
{
|
||||
System.out.println ("Swallowing a FileFormatException in TreeBuilder");
|
||||
System.out.println (e.getMessage ());
|
||||
return null;
|
||||
}
|
||||
return formattedDisk;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
boolean replaceDisk (FormattedDisk disk)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
String path = disk.getDisk ().getFile ().getAbsolutePath ();
|
||||
if (formattedDisk != null && path.equals (file.getAbsolutePath ()))
|
||||
{
|
||||
formattedDisk = disk;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String toString ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
String name = file.getName ();
|
||||
if (name.length () > MAX_NAME_LENGTH)
|
||||
name = name.substring (0, PREFIX_LENGTH) + "..."
|
||||
+ name.substring (name.length () - SUFFIX_LENGTH);
|
||||
if (showDisks && disks > 0)
|
||||
return String.format ("%s (%,d)", name, disks);
|
||||
return name;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getText ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
String home = System.getProperty ("user.home");
|
||||
String path = file.getAbsolutePath ();
|
||||
if (path.startsWith (home))
|
||||
path = "~" + path.substring (home.length ());
|
||||
text.append ("Directory : " + path + "\n\n");
|
||||
text.append ("D File names "
|
||||
+ " Date Size Type\n");
|
||||
text.append ("- ----------------------------------------"
|
||||
+ " ----------- -------------- ---------\n");
|
||||
|
||||
File[] files = file.listFiles ();
|
||||
if (files != null)
|
||||
{
|
||||
Arrays.sort (files, fileComparator);
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.isHidden ())
|
||||
continue;
|
||||
String name = f.getName ();
|
||||
|
||||
Date d = new Date (f.lastModified ());
|
||||
int pos = name.lastIndexOf ('.');
|
||||
String type = pos > 0 && !f.isDirectory () ? name.substring (pos) : "";
|
||||
String size = f.isDirectory () ? "" : String.format ("%,14d", f.length ());
|
||||
text.append (String.format ("%s %-40.40s %s %-14s %s%n",
|
||||
f.isDirectory () ? "D" : " ", name, sdf.format (d).replace (".", ""), size,
|
||||
type));
|
||||
}
|
||||
}
|
||||
|
||||
if (text.length () > 0)
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getAssembler ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getHexDump ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public BufferedImage getImage ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public JComponent getComponent ()
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,20 +5,26 @@ import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class WindowSaver
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class WindowSaver
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private final Preferences prefs;
|
||||
private final JFrame frame;
|
||||
private final String key;
|
||||
|
||||
public WindowSaver (Preferences prefs, JFrame frame, String key)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
WindowSaver (Preferences prefs, JFrame frame, String key)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.prefs = prefs;
|
||||
this.frame = frame;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void saveWindow ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void saveWindow ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
prefs.putInt (key + "X", frame.getX ());
|
||||
prefs.putInt (key + "Y", frame.getY ());
|
||||
@ -26,7 +32,9 @@ public class WindowSaver
|
||||
prefs.putInt (key + "Width", frame.getWidth ());
|
||||
}
|
||||
|
||||
public boolean restoreWindow ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
boolean restoreWindow ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int x = prefs.getInt (key + "X", -1);
|
||||
int y = prefs.getInt (key + "Y", -1);
|
||||
|
@ -6,7 +6,9 @@ import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
class WindowState
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private static final String PREF_WINDOW_WIDTH = "WindowWidth";
|
||||
private static final String PREF_WINDOW_HEIGHT = "WindowHeight";
|
||||
@ -14,12 +16,16 @@ class WindowState
|
||||
|
||||
public Preferences preferences;
|
||||
|
||||
public WindowState (Preferences preferences)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
WindowState (Preferences preferences)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
public void clear ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void clear ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -32,19 +38,25 @@ class WindowState
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getWindowSize (int defaultWidth, int defaultHeight)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
Dimension getWindowSize (int defaultWidth, int defaultHeight)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int width = preferences.getInt (PREF_WINDOW_WIDTH, defaultWidth);
|
||||
int height = preferences.getInt (PREF_WINDOW_HEIGHT, defaultHeight);
|
||||
return new Dimension (width, height);
|
||||
}
|
||||
|
||||
public int getExtendedState (int defaultState)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
int getExtendedState (int defaultState)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
return preferences.getInt (PREF_WINDOW_STATE, defaultState);
|
||||
}
|
||||
|
||||
public void save (JFrame window)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void save (JFrame window)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
preferences.putInt (PREF_WINDOW_WIDTH, window.getWidth ());
|
||||
preferences.putInt (PREF_WINDOW_HEIGHT, window.getHeight ());
|
||||
|
Loading…
Reference in New Issue
Block a user