2015-06-01 09:35:51 +00:00
|
|
|
package com.bytezone.diskbrowser.gui;
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.Color;
|
2018-07-26 03:43:07 +00:00
|
|
|
import java.awt.Desktop;
|
2015-06-01 09:35:51 +00:00
|
|
|
import java.awt.EventQueue;
|
2018-08-15 02:32:11 +00:00
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowEvent;
|
2018-07-26 03:43:07 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2015-06-01 09:35:51 +00:00
|
|
|
import java.util.prefs.Preferences;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
2016-12-12 23:46:09 +00:00
|
|
|
import com.bytezone.diskbrowser.duplicates.RootFolderData;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitListener
|
2019-11-03 05:49:01 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2019-11-04 08:30:13 +00:00
|
|
|
// static long start;
|
|
|
|
// static
|
|
|
|
// {
|
|
|
|
// start = System.currentTimeMillis ();
|
|
|
|
// }
|
2019-04-08 08:25:52 +00:00
|
|
|
private static String[] args;
|
2015-06-01 09:35:51 +00:00
|
|
|
private static final String windowTitle = "Apple ][ Disk Browser";
|
2016-03-15 04:40:57 +00:00
|
|
|
private final Preferences prefs = Preferences.userNodeForPackage (this.getClass ());
|
|
|
|
private WindowSaver windowSaver;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2019-10-12 02:47:21 +00:00
|
|
|
private static final String OS = System.getProperty ("os.name").toLowerCase ();
|
|
|
|
private static final boolean MAC = OS.startsWith ("mac os");
|
|
|
|
|
2019-10-24 03:13:01 +00:00
|
|
|
private final RootFolderData rootFolderData = new RootFolderData ();
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
public DiskBrowser ()
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
|
|
|
super (windowTitle);
|
2019-11-04 08:30:13 +00:00
|
|
|
// System.out.printf ("Start Init: %,5d%n", System.currentTimeMillis () - start);
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2019-04-08 08:25:52 +00:00
|
|
|
if (args.length > 0 && "-reset".equals (args[0]))
|
2019-10-12 07:30:08 +00:00
|
|
|
new WindowState (prefs).clear ();
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
JToolBar toolBar = new JToolBar ("Toolbar", JToolBar.HORIZONTAL);
|
2019-10-12 02:47:21 +00:00
|
|
|
MenuHandler menuHandler = new MenuHandler ();
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
setJMenuBar (menuHandler.menuBar);
|
|
|
|
setLayout (new BorderLayout ());
|
|
|
|
add (toolBar, BorderLayout.NORTH);
|
|
|
|
|
2016-07-19 01:24:36 +00:00
|
|
|
// add navigation buttons
|
|
|
|
RedoHandler redoHandler = new RedoHandler (getRootPane (), toolBar);
|
2015-06-01 09:35:51 +00:00
|
|
|
toolBar.addSeparator ();
|
|
|
|
|
|
|
|
// create and add the left-hand catalog panel
|
2019-10-12 02:47:21 +00:00
|
|
|
CatalogPanel catalogPanel = new CatalogPanel (redoHandler);
|
2015-06-01 09:35:51 +00:00
|
|
|
JPanel catalogBorderPanel = addPanel (catalogPanel, "Catalog", BorderLayout.WEST);
|
|
|
|
|
|
|
|
// create and add the centre output panel
|
2019-10-12 02:47:21 +00:00
|
|
|
DataPanel dataPanel = new DataPanel (menuHandler);
|
2015-06-01 09:35:51 +00:00
|
|
|
addPanel (dataPanel, "Output", BorderLayout.CENTER);
|
|
|
|
|
|
|
|
// create and add the right-hand disk layout panel
|
2019-08-01 13:39:45 +00:00
|
|
|
DiskLayoutPanel diskLayoutPanel = new DiskLayoutPanel ();
|
2016-02-21 00:00:57 +00:00
|
|
|
JPanel layoutBorderPanel =
|
|
|
|
addPanel (diskLayoutPanel, "Disk layout", BorderLayout.EAST);
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
// create actions
|
2016-12-12 23:46:09 +00:00
|
|
|
DuplicateAction duplicateAction = new DuplicateAction (rootFolderData);
|
2019-10-24 03:13:01 +00:00
|
|
|
RootDirectoryAction rootDirectoryAction = new RootDirectoryAction ();
|
2016-12-07 10:42:01 +00:00
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
RefreshTreeAction refreshTreeAction = new RefreshTreeAction (catalogPanel);
|
|
|
|
// PreferencesAction preferencesAction = new PreferencesAction (this, prefs);
|
|
|
|
AbstractAction print = new PrintAction (dataPanel);
|
2018-07-26 03:43:07 +00:00
|
|
|
// AboutAction aboutAction = new AboutAction ();
|
2016-02-21 00:00:57 +00:00
|
|
|
HideCatalogAction hideCatalogAction =
|
|
|
|
new HideCatalogAction (this, catalogBorderPanel);
|
2015-06-01 09:35:51 +00:00
|
|
|
HideLayoutAction hideLayoutAction = new HideLayoutAction (this, layoutBorderPanel);
|
|
|
|
ShowFreeSectorsAction showFreeAction =
|
2016-02-21 00:00:57 +00:00
|
|
|
new ShowFreeSectorsAction (menuHandler, diskLayoutPanel);
|
2015-06-01 09:35:51 +00:00
|
|
|
CloseTabAction closeTabAction = new CloseTabAction (catalogPanel);
|
|
|
|
|
|
|
|
// add action buttons to toolbar
|
|
|
|
toolBar.add (rootDirectoryAction);
|
|
|
|
toolBar.add (refreshTreeAction);
|
|
|
|
// toolBar.add (preferencesAction);
|
|
|
|
toolBar.add (duplicateAction);
|
|
|
|
toolBar.add (print);
|
2018-07-26 03:43:07 +00:00
|
|
|
// toolBar.add (aboutAction);
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
// set the listeners
|
2019-10-24 03:13:01 +00:00
|
|
|
rootDirectoryAction.addListener (rootFolderData);
|
|
|
|
rootDirectoryAction.addListener (catalogPanel);
|
|
|
|
rootDirectoryAction.addListener (duplicateAction);
|
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
catalogPanel.addDiskSelectionListener (this);
|
|
|
|
catalogPanel.addDiskSelectionListener (dataPanel);
|
|
|
|
catalogPanel.addDiskSelectionListener (diskLayoutPanel);
|
|
|
|
catalogPanel.addDiskSelectionListener (redoHandler);
|
|
|
|
catalogPanel.addDiskSelectionListener (menuHandler);
|
|
|
|
|
|
|
|
catalogPanel.addFileSelectionListener (dataPanel);
|
|
|
|
catalogPanel.addFileSelectionListener (diskLayoutPanel);
|
|
|
|
catalogPanel.addFileSelectionListener (redoHandler);
|
|
|
|
catalogPanel.addFileSelectionListener (menuHandler);
|
|
|
|
|
|
|
|
catalogPanel.addFileNodeSelectionListener (dataPanel);
|
|
|
|
catalogPanel.addFileNodeSelectionListener (redoHandler);
|
|
|
|
|
|
|
|
diskLayoutPanel.addSectorSelectionListener (dataPanel);
|
|
|
|
diskLayoutPanel.addSectorSelectionListener (redoHandler);
|
|
|
|
diskLayoutPanel.addSectorSelectionListener (catalogPanel);
|
|
|
|
|
2016-12-10 07:36:44 +00:00
|
|
|
duplicateAction.addTableSelectionListener (catalogPanel);
|
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
redoHandler.addRedoListener (catalogPanel);
|
|
|
|
redoHandler.addRedoListener (diskLayoutPanel);
|
|
|
|
|
|
|
|
menuHandler.fontAction.addFontChangeListener (dataPanel);
|
|
|
|
menuHandler.fontAction.addFontChangeListener (catalogPanel);
|
2016-07-29 12:28:11 +00:00
|
|
|
// menuHandler.fontAction.addFontChangeListener (diskLayoutPanel);
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
// set the MenuItem Actions
|
|
|
|
menuHandler.printItem.setAction (print);
|
|
|
|
// menuHandler.addHelpMenuAction (preferencesAction, "prefs");
|
2018-07-26 03:43:07 +00:00
|
|
|
// menuHandler.addHelpMenuAction (aboutAction, "about");
|
2015-06-01 09:35:51 +00:00
|
|
|
menuHandler.refreshTreeItem.setAction (refreshTreeAction);
|
|
|
|
menuHandler.rootItem.setAction (rootDirectoryAction);
|
|
|
|
menuHandler.showCatalogItem.setAction (hideCatalogAction);
|
|
|
|
menuHandler.showLayoutItem.setAction (hideLayoutAction);
|
|
|
|
menuHandler.showFreeSectorsItem.setAction (showFreeAction);
|
|
|
|
menuHandler.duplicateItem.setAction (duplicateAction);
|
|
|
|
menuHandler.closeTabItem.setAction (closeTabAction);
|
|
|
|
|
2019-10-24 03:13:01 +00:00
|
|
|
addQuitListener (rootDirectoryAction);
|
2018-07-26 03:43:07 +00:00
|
|
|
addQuitListener (menuHandler);
|
|
|
|
addQuitListener (catalogPanel);
|
|
|
|
addQuitListener (this);
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2018-08-15 02:32:11 +00:00
|
|
|
if (Desktop.isDesktopSupported ())
|
|
|
|
{
|
|
|
|
Desktop desktop = Desktop.getDesktop ();
|
|
|
|
|
|
|
|
if (desktop.isSupported (Desktop.Action.APP_ABOUT))
|
|
|
|
desktop.setAboutHandler (e -> JOptionPane.showMessageDialog (null,
|
|
|
|
"Author - Denis Molony\nGitHub - https://github.com/dmolony/DiskBrowser",
|
|
|
|
"About DiskBrowser", JOptionPane.INFORMATION_MESSAGE));
|
2018-08-16 00:09:26 +00:00
|
|
|
|
2018-08-15 02:32:11 +00:00
|
|
|
if (desktop.isSupported (Desktop.Action.APP_QUIT_HANDLER))
|
|
|
|
desktop.setQuitHandler ( (e, r) -> fireQuitEvent ());
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addWindowListener (new WindowAdapter ()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void windowClosing (WindowEvent e)
|
|
|
|
{
|
|
|
|
fireQuitEvent ();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
System.out.println ("Desktop not supported");
|
2018-04-25 22:21:51 +00:00
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
catalogPanel.setCloseTabAction (closeTabAction);
|
|
|
|
|
|
|
|
pack ();
|
|
|
|
|
2016-03-01 08:51:15 +00:00
|
|
|
// restore the menuHandler items before they are referenced
|
2018-07-26 03:43:07 +00:00
|
|
|
fireRestoreEvent ();
|
2017-04-22 06:31:25 +00:00
|
|
|
diskLayoutPanel.setFree (menuHandler.showFreeSectorsItem.isSelected ());
|
2019-10-12 02:47:21 +00:00
|
|
|
dataPanel.setLineWrap (menuHandler.lineWrapItem.isSelected ());
|
2016-03-01 08:51:15 +00:00
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
// Remove the two optional panels if they were previously hidden
|
|
|
|
if (!menuHandler.showLayoutItem.isSelected ())
|
|
|
|
hideLayoutAction.set (false);
|
|
|
|
if (!menuHandler.showCatalogItem.isSelected ())
|
|
|
|
hideCatalogAction.set (false);
|
|
|
|
|
2019-08-08 10:01:56 +00:00
|
|
|
menuHandler.addBasicPreferencesListener (dataPanel);
|
2019-08-15 07:02:40 +00:00
|
|
|
menuHandler.addAssemblerPreferencesListener (dataPanel);
|
2019-08-08 10:01:56 +00:00
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
// activate the highest panel now that the listeners are ready
|
|
|
|
catalogPanel.activate ();
|
2019-11-04 08:30:13 +00:00
|
|
|
// System.out.printf ("End Init : %,5d%n", System.currentTimeMillis () - start);
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
private JPanel addPanel (JComponent pane, String title, String location)
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
|
|
|
JPanel panel = new JPanel (new BorderLayout ());
|
|
|
|
panel.setBackground (Color.WHITE);
|
|
|
|
panel.setBorder (BorderFactory.createTitledBorder (title));
|
|
|
|
panel.add (pane);
|
|
|
|
add (panel, location);
|
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
@Override
|
|
|
|
public void diskSelected (DiskSelectedEvent e)
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-02-21 00:00:57 +00:00
|
|
|
setTitle (windowTitle + e.getFormattedDisk () == null ? ""
|
|
|
|
: e.getFormattedDisk ().getName ());
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
@Override
|
|
|
|
public void quit (Preferences preferences)
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
{
|
|
|
|
windowSaver.saveWindow ();
|
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
@Override
|
|
|
|
public void restore (Preferences preferences)
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2016-03-15 04:40:57 +00:00
|
|
|
{
|
|
|
|
windowSaver = new WindowSaver (prefs, this, "DiskBrowser");
|
|
|
|
windowSaver.restoreWindow ();
|
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
public static void main (String[] args)
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2019-04-08 08:25:52 +00:00
|
|
|
DiskBrowser.args = args;
|
2015-06-01 09:35:51 +00:00
|
|
|
EventQueue.invokeLater (new Runnable ()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run ()
|
|
|
|
{
|
2019-10-12 02:47:21 +00:00
|
|
|
setLookAndFeel ();
|
2015-06-01 09:35:51 +00:00
|
|
|
new DiskBrowser ().setVisible (true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-07-26 03:43:07 +00:00
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2019-10-12 02:47:21 +00:00
|
|
|
private static void setLookAndFeel ()
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2019-10-12 02:47:21 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-11-03 05:49:01 +00:00
|
|
|
UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ());
|
2019-10-12 02:47:21 +00:00
|
|
|
if (MAC)
|
|
|
|
System.setProperty ("apple.laf.useScreenMenuBar", "true");
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:43:07 +00:00
|
|
|
List<QuitListener> quitListeners = new ArrayList<> ();
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
public void addQuitListener (QuitListener listener)
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
{
|
|
|
|
quitListeners.add (listener);
|
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
public void removeQuitListener (QuitListener listener)
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
{
|
|
|
|
quitListeners.remove (listener);
|
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
private void fireQuitEvent ()
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
{
|
|
|
|
for (QuitListener listener : quitListeners)
|
|
|
|
listener.quit (prefs);
|
|
|
|
|
|
|
|
System.exit (0);
|
|
|
|
}
|
|
|
|
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
private void fireRestoreEvent ()
|
2019-11-03 05:49:01 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2018-07-26 03:43:07 +00:00
|
|
|
{
|
|
|
|
for (QuitListener listener : quitListeners)
|
|
|
|
listener.restore (prefs);
|
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|