mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-01 09:50:32 +00:00
more PropertyChangeListeners
This commit is contained in:
parent
ea0a827331
commit
83d5be3f9f
@ -8,6 +8,8 @@ import java.awt.Graphics;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -20,11 +22,10 @@ import javax.swing.JFrame;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
import com.bytezone.diskbrowser.gui.DuplicateAction.DiskTableSelectionListener;
|
||||||
import com.bytezone.diskbrowser.gui.RootDirectoryChangeListener;
|
|
||||||
import com.bytezone.diskbrowser.utilities.Utility;
|
import com.bytezone.diskbrowser.utilities.Utility;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
public class RootFolderData implements RootDirectoryChangeListener
|
public class RootFolderData implements PropertyChangeListener
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static final String header =
|
private static final String header =
|
||||||
@ -274,8 +275,7 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
private void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
rootFolder = newRootFolder;
|
rootFolder = newRootFolder;
|
||||||
@ -283,6 +283,15 @@ public class RootFolderData implements RootDirectoryChangeListener
|
|||||||
disksWindow = null; // force a recount
|
disksWindow = null; // force a recount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@Override
|
||||||
|
public void propertyChange (PropertyChangeEvent evt)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
if (evt.getPropertyName ().equals ("RootDirectory"))
|
||||||
|
rootDirectoryChanged ((File) evt.getOldValue (), (File) evt.getNewValue ());
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString ()
|
||||||
|
@ -10,6 +10,8 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
@ -36,9 +38,8 @@ import com.bytezone.diskbrowser.gui.RedoHandler.RedoListener;
|
|||||||
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
import com.bytezone.diskbrowser.gui.TreeBuilder.FileNode;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
class CatalogPanel extends JTabbedPane
|
class CatalogPanel extends JTabbedPane implements RedoListener, SectorSelectionListener,
|
||||||
implements RedoListener, SectorSelectionListener, QuitListener, FontChangeListener,
|
QuitListener, FontChangeListener, DiskTableSelectionListener, PropertyChangeListener
|
||||||
RootDirectoryChangeListener, DiskTableSelectionListener
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static final String prefsLastDiskUsed = "Last disk used";
|
private static final String prefsLastDiskUsed = "Last disk used";
|
||||||
@ -66,8 +67,7 @@ class CatalogPanel extends JTabbedPane
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
private void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
rootFolder = newRootFolder;
|
rootFolder = newRootFolder;
|
||||||
@ -82,6 +82,15 @@ class CatalogPanel extends JTabbedPane
|
|||||||
setSelectedIndex (0);
|
setSelectedIndex (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------//
|
||||||
|
@Override
|
||||||
|
public void propertyChange (PropertyChangeEvent evt)
|
||||||
|
// -------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
if (evt.getPropertyName ().equals ("RootDirectory"))
|
||||||
|
rootDirectoryChanged ((File) evt.getOldValue (), (File) evt.getNewValue ());
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
private void insertFileSystemTab (DiskSelectedEvent diskEvent)
|
private void insertFileSystemTab (DiskSelectedEvent diskEvent)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -43,8 +43,8 @@ public class DiskBrowser extends JFrame
|
|||||||
private final JPanel catalogBorderPanel;
|
private final JPanel catalogBorderPanel;
|
||||||
private final JPanel layoutBorderPanel;
|
private final JPanel layoutBorderPanel;
|
||||||
|
|
||||||
HideCatalogAction hideCatalogAction = new HideCatalogAction ();
|
private final HideCatalogAction hideCatalogAction = new HideCatalogAction ();
|
||||||
HideLayoutAction hideLayoutAction = new HideLayoutAction ();
|
private final HideLayoutAction hideLayoutAction = new HideLayoutAction ();
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
public DiskBrowser ()
|
public DiskBrowser ()
|
||||||
@ -104,7 +104,9 @@ public class DiskBrowser extends JFrame
|
|||||||
// toolBar.add (aboutAction);
|
// toolBar.add (aboutAction);
|
||||||
|
|
||||||
// set the listeners
|
// set the listeners
|
||||||
rootDirectoryAction.addListener (rootFolderData, catalogPanel, duplicateAction);
|
rootDirectoryAction.addPropertyChangeListener (rootFolderData);
|
||||||
|
rootDirectoryAction.addPropertyChangeListener (catalogPanel);
|
||||||
|
rootDirectoryAction.addPropertyChangeListener (duplicateAction);
|
||||||
|
|
||||||
catalogPanel.addDiskSelectionListener (this, dataPanel, diskLayoutPanel, redoHandler,
|
catalogPanel.addDiskSelectionListener (this, dataPanel, diskLayoutPanel, redoHandler,
|
||||||
menuHandler, menuHandler.saveDiskAction);
|
menuHandler, menuHandler.saveDiskAction);
|
||||||
|
@ -3,6 +3,8 @@ package com.bytezone.diskbrowser.gui;
|
|||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
@ -14,7 +16,7 @@ import com.bytezone.diskbrowser.duplicates.RootFolderData;
|
|||||||
import com.bytezone.diskbrowser.utilities.DefaultAction;
|
import com.bytezone.diskbrowser.utilities.DefaultAction;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
public class DuplicateAction extends DefaultAction implements RootDirectoryChangeListener
|
public class DuplicateAction extends DefaultAction implements PropertyChangeListener
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
RootFolderData rootFolderData;
|
RootFolderData rootFolderData;
|
||||||
@ -36,14 +38,22 @@ public class DuplicateAction extends DefaultAction implements RootDirectoryChang
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
private void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
||||||
public void rootDirectoryChanged (File oldRootFolder, File newRootFolder)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
assert rootFolderData.getRootFolder () == newRootFolder;
|
assert rootFolderData.getRootFolder () == newRootFolder;
|
||||||
setEnabled (rootFolderData.getRootFolder () != null);
|
setEnabled (rootFolderData.getRootFolder () != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@Override
|
||||||
|
public void propertyChange (PropertyChangeEvent evt)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
if (evt.getPropertyName ().equals ("RootDirectory"))
|
||||||
|
rootDirectoryChanged ((File) evt.getOldValue (), (File) evt.getNewValue ());
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed (ActionEvent arg0)
|
public void actionPerformed (ActionEvent arg0)
|
||||||
|
@ -3,8 +3,6 @@ package com.bytezone.diskbrowser.gui;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
@ -18,7 +16,7 @@ class RootDirectoryAction extends DefaultAction implements QuitListener
|
|||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static final String prefsRootDirectory = "Root directory";
|
private static final String prefsRootDirectory = "Root directory";
|
||||||
private final List<RootDirectoryChangeListener> listeners = new ArrayList<> ();
|
|
||||||
private File rootFolder;
|
private File rootFolder;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@ -27,6 +25,7 @@ class RootDirectoryAction extends DefaultAction implements QuitListener
|
|||||||
{
|
{
|
||||||
super ("Set HOME folder...", "Defines root folder where the disk images are kept",
|
super ("Set HOME folder...", "Defines root folder where the disk images are kept",
|
||||||
"/com/bytezone/diskbrowser/icons/");
|
"/com/bytezone/diskbrowser/icons/");
|
||||||
|
|
||||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt H"));
|
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt H"));
|
||||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_H);
|
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_H);
|
||||||
|
|
||||||
@ -56,23 +55,6 @@ class RootDirectoryAction extends DefaultAction implements QuitListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public void addListener (RootDirectoryChangeListener listener)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
if (!listeners.contains (listener))
|
|
||||||
listeners.add (listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public void addListener (RootDirectoryChangeListener... listenerList)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
for (RootDirectoryChangeListener rootDirectoryChangeListener : listenerList)
|
|
||||||
if (!listeners.contains (rootDirectoryChangeListener))
|
|
||||||
listeners.add (rootDirectoryChangeListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
@Override
|
||||||
public void quit (Preferences prefs)
|
public void quit (Preferences prefs)
|
||||||
@ -87,9 +69,7 @@ class RootDirectoryAction extends DefaultAction implements QuitListener
|
|||||||
public void restore (Preferences prefs)
|
public void restore (Preferences prefs)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
String rootDirectory = prefs.get (prefsRootDirectory, "");
|
File rootDirectoryFile = new File (prefs.get (prefsRootDirectory, ""));
|
||||||
|
|
||||||
File rootDirectoryFile = new File (rootDirectory);
|
|
||||||
|
|
||||||
if (!rootDirectoryFile.exists () || !rootDirectoryFile.isDirectory ())
|
if (!rootDirectoryFile.exists () || !rootDirectoryFile.isDirectory ())
|
||||||
{
|
{
|
||||||
@ -105,7 +85,7 @@ class RootDirectoryAction extends DefaultAction implements QuitListener
|
|||||||
{
|
{
|
||||||
File oldRootFolder = rootFolder;
|
File oldRootFolder = rootFolder;
|
||||||
rootFolder = newRootFolder;
|
rootFolder = newRootFolder;
|
||||||
for (RootDirectoryChangeListener listener : listeners)
|
|
||||||
listener.rootDirectoryChanged (oldRootFolder, newRootFolder);
|
firePropertyChange ("RootDirectory", oldRootFolder, newRootFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user