mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-02-27 03:29:26 +00:00
using PropertyChangeListeners
This commit is contained in:
parent
beb0830c25
commit
63fc59accc
@ -2,8 +2,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.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
@ -14,13 +12,12 @@ import javax.swing.KeyStroke;
|
|||||||
public class ColourQuirksAction extends AbstractAction
|
public class ColourQuirksAction extends AbstractAction
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
List<ColourQuirksListener> listeners = new ArrayList<> ();
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
public ColourQuirksAction ()
|
public ColourQuirksAction ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super ("Smear HGR");
|
super ("Smear HGR");
|
||||||
|
|
||||||
putValue (Action.SHORT_DESCRIPTION, "Display pixels like a TV screen");
|
putValue (Action.SHORT_DESCRIPTION, "Display pixels like a TV screen");
|
||||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt Q"));
|
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt Q"));
|
||||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_Q);
|
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_Q);
|
||||||
@ -31,22 +28,7 @@ public class ColourQuirksAction extends AbstractAction
|
|||||||
public void actionPerformed (ActionEvent e)
|
public void actionPerformed (ActionEvent e)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
for (ColourQuirksListener listener : listeners)
|
firePropertyChange (e.getActionCommand (), null,
|
||||||
listener.setColourQuirks (((JMenuItem) e.getSource ()).isSelected ());
|
((JMenuItem) e.getSource ()).isSelected ());
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public void addColourQuirksListener (ColourQuirksListener listener)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
if (!listeners.contains (listener))
|
|
||||||
listeners.add (listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public interface ColourQuirksListener
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
public void setColourQuirks (boolean value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,8 @@ import java.awt.Insets;
|
|||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -37,17 +39,14 @@ import com.bytezone.diskbrowser.applefile.QuickDrawFont;
|
|||||||
import com.bytezone.diskbrowser.applefile.SHRPictureFile2;
|
import com.bytezone.diskbrowser.applefile.SHRPictureFile2;
|
||||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||||
import com.bytezone.diskbrowser.disk.SectorList;
|
import com.bytezone.diskbrowser.disk.SectorList;
|
||||||
import com.bytezone.diskbrowser.gui.ColourQuirksAction.ColourQuirksListener;
|
|
||||||
import com.bytezone.diskbrowser.gui.DebuggingAction.DebugListener;
|
|
||||||
import com.bytezone.diskbrowser.gui.FontAction.FontChangeEvent;
|
import com.bytezone.diskbrowser.gui.FontAction.FontChangeEvent;
|
||||||
import com.bytezone.diskbrowser.gui.FontAction.FontChangeListener;
|
import com.bytezone.diskbrowser.gui.FontAction.FontChangeListener;
|
||||||
import com.bytezone.diskbrowser.gui.MonochromeAction.MonochromeListener;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
public class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
public class DataPanel extends JTabbedPane
|
||||||
FileSelectionListener, SectorSelectionListener, FileNodeSelectionListener,
|
implements DiskSelectionListener, FileSelectionListener, SectorSelectionListener,
|
||||||
FontChangeListener, BasicPreferencesListener, AssemblerPreferencesListener,
|
FileNodeSelectionListener, FontChangeListener, BasicPreferencesListener,
|
||||||
TextPreferencesListener, DebugListener, ColourQuirksListener, MonochromeListener
|
AssemblerPreferencesListener, TextPreferencesListener, PropertyChangeListener
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static final int TEXT_WIDTH = 65;
|
private static final int TEXT_WIDTH = 65;
|
||||||
@ -75,6 +74,10 @@ public class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
|||||||
|
|
||||||
final MenuHandler menuHandler;
|
final MenuHandler menuHandler;
|
||||||
|
|
||||||
|
DebuggingAction debuggingAction = new DebuggingAction ();
|
||||||
|
MonochromeAction monochromeAction = new MonochromeAction ();
|
||||||
|
ColourQuirksAction colourQuirksAction = new ColourQuirksAction ();
|
||||||
|
|
||||||
enum TabType
|
enum TabType
|
||||||
{
|
{
|
||||||
FORMATTED, HEX, DISASSEMBLED
|
FORMATTED, HEX, DISASSEMBLED
|
||||||
@ -159,16 +162,13 @@ public class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
|||||||
menuHandler.lineWrapItem.setAction (lineWrapAction);
|
menuHandler.lineWrapItem.setAction (lineWrapAction);
|
||||||
lineWrapAction.addListener (formattedText);
|
lineWrapAction.addListener (formattedText);
|
||||||
|
|
||||||
ColourQuirksAction colourQuirksAction = new ColourQuirksAction ();
|
colourQuirksAction.addPropertyChangeListener (this);
|
||||||
colourQuirksAction.addColourQuirksListener (this);
|
|
||||||
menuHandler.colourQuirksItem.setAction (colourQuirksAction);
|
menuHandler.colourQuirksItem.setAction (colourQuirksAction);
|
||||||
|
|
||||||
MonochromeAction monochromeAction = new MonochromeAction ();
|
monochromeAction.addPropertyChangeListener (this);
|
||||||
monochromeAction.addMonochromeListener (this);
|
|
||||||
menuHandler.monochromeItem.setAction (monochromeAction);
|
menuHandler.monochromeItem.setAction (monochromeAction);
|
||||||
|
|
||||||
DebuggingAction debuggingAction = new DebuggingAction ();
|
debuggingAction.addPropertyChangeListener (this);
|
||||||
debuggingAction.addDebugListener (this);
|
|
||||||
menuHandler.debuggingItem.setAction (debuggingAction);
|
menuHandler.debuggingItem.setAction (debuggingAction);
|
||||||
|
|
||||||
// fill in the placeholders created by the MenuHandler
|
// fill in the placeholders created by the MenuHandler
|
||||||
@ -212,6 +212,19 @@ public class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
|||||||
return palette;
|
return palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@Override
|
||||||
|
public void propertyChange (PropertyChangeEvent evt)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
if (evt.getSource () == debuggingAction)
|
||||||
|
setDebug ((Boolean) evt.getNewValue ());
|
||||||
|
else if (evt.getSource () == monochromeAction)
|
||||||
|
setMonochrome ((Boolean) evt.getNewValue ());
|
||||||
|
else if (evt.getSource () == colourQuirksAction)
|
||||||
|
setColourQuirks ((Boolean) evt.getNewValue ());
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
void setLineWrap (boolean lineWrap)
|
void setLineWrap (boolean lineWrap)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@ -220,7 +233,6 @@ public class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
|
||||||
public void setColourQuirks (boolean value)
|
public void setColourQuirks (boolean value)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
@ -268,7 +280,6 @@ public class DataPanel extends JTabbedPane implements DiskSelectionListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
@Override
|
|
||||||
public void setDebug (boolean value)
|
public void setDebug (boolean value)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.bytezone.diskbrowser.gui;
|
package com.bytezone.diskbrowser.gui;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
@ -13,13 +11,12 @@ import javax.swing.KeyStroke;
|
|||||||
public class DebuggingAction extends AbstractAction
|
public class DebuggingAction extends AbstractAction
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
List<DebugListener> listeners = new ArrayList<> ();
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
public DebuggingAction ()
|
public DebuggingAction ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super ("Debugging");
|
super ("Debugging");
|
||||||
|
|
||||||
putValue (Action.SHORT_DESCRIPTION, "Show debugging information");
|
putValue (Action.SHORT_DESCRIPTION, "Show debugging information");
|
||||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("meta D"));
|
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("meta D"));
|
||||||
}
|
}
|
||||||
@ -29,22 +26,7 @@ public class DebuggingAction extends AbstractAction
|
|||||||
public void actionPerformed (ActionEvent e)
|
public void actionPerformed (ActionEvent e)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
for (DebugListener listener : listeners)
|
firePropertyChange (e.getActionCommand (), null,
|
||||||
listener.setDebug (((JMenuItem) e.getSource ()).isSelected ());
|
((JMenuItem) e.getSource ()).isSelected ());
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public void addDebugListener (DebugListener listener)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
if (!listeners.contains (listener))
|
|
||||||
listeners.add (listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public interface DebugListener
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
public void setDebug (boolean value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,8 +2,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.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
@ -14,13 +12,12 @@ import javax.swing.KeyStroke;
|
|||||||
class MonochromeAction extends AbstractAction
|
class MonochromeAction extends AbstractAction
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
List<MonochromeListener> listeners = new ArrayList<> ();
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
MonochromeAction ()
|
MonochromeAction ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super ("Monochrome");
|
super ("Monochrome");
|
||||||
|
|
||||||
putValue (Action.SHORT_DESCRIPTION, "Display image in monochrome or color");
|
putValue (Action.SHORT_DESCRIPTION, "Display image in monochrome or color");
|
||||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt M"));
|
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt M"));
|
||||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_M);
|
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_M);
|
||||||
@ -31,22 +28,7 @@ class MonochromeAction extends AbstractAction
|
|||||||
public void actionPerformed (ActionEvent e)
|
public void actionPerformed (ActionEvent e)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
for (MonochromeListener listener : listeners)
|
firePropertyChange (e.getActionCommand (), null,
|
||||||
listener.setMonochrome (((JMenuItem) e.getSource ()).isSelected ());
|
((JMenuItem) e.getSource ()).isSelected ());
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public void addMonochromeListener (MonochromeListener listener)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
if (!listeners.contains (listener))
|
|
||||||
listeners.add (listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
public interface MonochromeListener
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
public void setMonochrome (boolean value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user