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