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