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.*;
|
|
|
|
|
|
|
|
import com.bytezone.common.Platform;
|
|
|
|
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);
|
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
|
|
|
|
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);
|
|
|
|
|
2018-07-26 03:43:07 +00:00
|
|
|
// final QuitAction quitAction = Platform.setQuit (this, prefs, menuHandler.fileMenu);
|
2015-06-01 09:35:51 +00:00
|
|
|
|
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 (false)
|
|
|
|
{
|
|
|
|
System.out.println ("Enums:");
|
|
|
|
for (Desktop.Action a : Desktop.Action.values ())
|
|
|
|
System.out.printf ("%s is%s supported%n", a.toString (),
|
|
|
|
(desktop.isSupported (a) ? "" : " not"));
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
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 ());
|
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);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-07-26 03:43:07 +00:00
|
|
|
|
|
|
|
List<QuitListener> quitListeners = new ArrayList<> ();
|
|
|
|
|
|
|
|
public void addQuitListener (QuitListener listener)
|
|
|
|
{
|
|
|
|
quitListeners.add (listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeQuitListener (QuitListener listener)
|
|
|
|
{
|
|
|
|
quitListeners.remove (listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireQuitEvent ()
|
|
|
|
{
|
|
|
|
for (QuitListener listener : quitListeners)
|
|
|
|
listener.quit (prefs);
|
|
|
|
|
|
|
|
System.exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireRestoreEvent ()
|
|
|
|
{
|
|
|
|
for (QuitListener listener : quitListeners)
|
|
|
|
listener.restore (prefs);
|
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|