2015-06-01 09:35:51 +00:00
|
|
|
package com.bytezone.diskbrowser.gui;
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.EventQueue;
|
|
|
|
import java.util.prefs.Preferences;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
|
|
import com.bytezone.common.Platform;
|
|
|
|
import com.bytezone.common.QuitAction;
|
|
|
|
import com.bytezone.common.QuitAction.QuitListener;
|
|
|
|
import com.bytezone.common.State;
|
2016-12-12 23:46:09 +00:00
|
|
|
import com.bytezone.diskbrowser.duplicates.RootFolderData;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitListener
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
public DiskBrowser ()
|
|
|
|
{
|
|
|
|
super (windowTitle);
|
|
|
|
|
|
|
|
if (false)
|
2016-03-23 23:37:59 +00:00
|
|
|
{
|
|
|
|
State state = new State (prefs);
|
2015-06-01 09:35:51 +00:00
|
|
|
state.clear ();
|
2016-03-23 23:37:59 +00:00
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
JToolBar toolBar = new JToolBar ("Toolbar", JToolBar.HORIZONTAL);
|
|
|
|
MenuHandler menuHandler = new MenuHandler (prefs);
|
|
|
|
|
|
|
|
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
|
|
|
|
CatalogPanel catalogPanel = new CatalogPanel (menuHandler, redoHandler, prefs);
|
|
|
|
JPanel catalogBorderPanel = addPanel (catalogPanel, "Catalog", BorderLayout.WEST);
|
|
|
|
|
|
|
|
// create and add the centre output panel
|
|
|
|
DataPanel dataPanel = new DataPanel (menuHandler, prefs);
|
|
|
|
addPanel (dataPanel, "Output", BorderLayout.CENTER);
|
|
|
|
|
|
|
|
// create and add the right-hand disk layout panel
|
2016-07-29 12:28:11 +00:00
|
|
|
DiskLayoutPanel diskLayoutPanel = new DiskLayoutPanel (menuHandler, prefs);
|
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-13 22:26:47 +00:00
|
|
|
RootFolderData rootFolderData = catalogPanel.getRootFolderData ();
|
2016-12-12 23:46:09 +00:00
|
|
|
DuplicateAction duplicateAction = new DuplicateAction (rootFolderData);
|
2016-12-13 22:26:47 +00:00
|
|
|
RootDirectoryAction rootDirectoryAction = new RootDirectoryAction (rootFolderData);
|
2016-12-07 10:42:01 +00:00
|
|
|
rootDirectoryAction.addListener (catalogPanel);
|
|
|
|
rootDirectoryAction.addListener (duplicateAction);
|
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
RefreshTreeAction refreshTreeAction = new RefreshTreeAction (catalogPanel);
|
|
|
|
// PreferencesAction preferencesAction = new PreferencesAction (this, prefs);
|
|
|
|
AbstractAction print = new PrintAction (dataPanel);
|
|
|
|
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);
|
|
|
|
toolBar.add (aboutAction);
|
|
|
|
|
|
|
|
// set the listeners
|
|
|
|
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");
|
|
|
|
menuHandler.addHelpMenuAction (aboutAction, "about");
|
|
|
|
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);
|
|
|
|
|
|
|
|
final QuitAction quitAction = Platform.setQuit (this, prefs, menuHandler.fileMenu);
|
|
|
|
|
|
|
|
quitAction.addQuitListener (menuHandler);
|
|
|
|
quitAction.addQuitListener (menuHandler.fontAction);
|
|
|
|
quitAction.addQuitListener (catalogPanel);
|
2016-07-29 12:28:11 +00:00
|
|
|
quitAction.addQuitListener (diskLayoutPanel);
|
2015-06-01 09:35:51 +00:00
|
|
|
quitAction.addQuitListener (this);
|
|
|
|
|
|
|
|
catalogPanel.setCloseTabAction (closeTabAction);
|
|
|
|
|
|
|
|
pack ();
|
|
|
|
|
2016-03-01 08:51:15 +00:00
|
|
|
// restore the menuHandler items before they are referenced
|
|
|
|
quitAction.restore ();
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// activate the highest panel now that the listeners are ready
|
|
|
|
catalogPanel.activate ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private JPanel addPanel (JComponent pane, String title, String location)
|
|
|
|
{
|
|
|
|
JPanel panel = new JPanel (new BorderLayout ());
|
|
|
|
panel.setBackground (Color.WHITE);
|
|
|
|
// panel.setOpaque (true);
|
|
|
|
panel.setBorder (BorderFactory.createTitledBorder (title));
|
|
|
|
panel.add (pane);
|
|
|
|
add (panel, location);
|
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void diskSelected (DiskSelectedEvent e)
|
|
|
|
{
|
2016-02-21 00:00:57 +00:00
|
|
|
setTitle (windowTitle + e.getFormattedDisk () == null ? ""
|
|
|
|
: e.getFormattedDisk ().getName ());
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 04:40:57 +00:00
|
|
|
@Override
|
|
|
|
public void quit (Preferences preferences)
|
|
|
|
{
|
2016-08-03 11:32:47 +00:00
|
|
|
// windowSaver = new WindowSaver (prefs, this, "DiskBrowser");
|
2016-03-15 04:40:57 +00:00
|
|
|
windowSaver.saveWindow ();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restore (Preferences preferences)
|
|
|
|
{
|
|
|
|
windowSaver = new WindowSaver (prefs, this, "DiskBrowser");
|
|
|
|
windowSaver.restoreWindow ();
|
|
|
|
}
|
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
public static void main (String[] args)
|
|
|
|
{
|
|
|
|
EventQueue.invokeLater (new Runnable ()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run ()
|
|
|
|
{
|
|
|
|
Platform.setLookAndFeel ();
|
|
|
|
new DiskBrowser ().setVisible (true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|