allow monochrome toggle

This commit is contained in:
Denis Molony 2016-02-22 21:58:15 +11:00
parent 13df8d1894
commit 0b304d52c6
4 changed files with 69 additions and 5 deletions

View File

@ -21,7 +21,7 @@ public class HiResImage extends AbstractFile
private static boolean colourQuirks;
private static boolean matchColourBits = true;
private static boolean drawColour = true;
private static boolean monochrome;
private final int[] line = new int[280];
private final int[] colourBits = new int[280];
@ -39,10 +39,10 @@ public class HiResImage extends AbstractFile
if (isGif (buffer))
makeGif ();
else if (drawColour)
drawColour (buffer);
else
else if (monochrome)
drawMonochrome (buffer);
else
drawColour (buffer);
}
public HiResImage (String name, byte[] buffer, int fileType, int auxType)
@ -66,15 +66,32 @@ public class HiResImage extends AbstractFile
colourQuirks = value;
}
public static void setDefaultMonochrome (boolean value)
{
monochrome = value;
}
public void setColourQuirks (boolean value)
{
if (colourQuirks == value || !drawColour)
if (colourQuirks == value || monochrome)
return;
colourQuirks = value;
drawColour (buffer);
}
public void setMonochrome (boolean value)
{
if (monochrome == value)
return;
monochrome = value;
if (monochrome)
drawMonochrome (buffer);
else
drawColour (buffer);
}
private void drawMonochrome (byte[] buffer)
{
int rows = buffer.length <= 8192 ? 192 : 384;

View File

@ -125,6 +125,7 @@ class DataPanel extends JTabbedPane
mh.lineWrapItem.setAction (new LineWrapAction (formattedText));
mh.colourQuirksItem.setAction (new ColourQuirksAction (this));
mh.monochromeItem.setAction (new MonochromeAction (this));
}
public void setColourQuirks (boolean value)
@ -137,6 +138,16 @@ class DataPanel extends JTabbedPane
}
}
public void setMonochrome (boolean value)
{
if (currentDataSource instanceof HiResImage)
{
HiResImage image = (HiResImage) currentDataSource;
image.setMonochrome (value);
imagePanel.setImage (image.getImage ());
}
}
private void setTabsFont (Font font)
{
formattedText.setFont (font);

View File

@ -24,6 +24,7 @@ public class MenuHandler
private static final String PREFS_SHOW_LAYOUT = "show layout";
private static final String PREFS_SHOW_FREE_SECTORS = "show free sectors";
private static final String PREFS_COLOUR_QUIRKS = "colour quirks";
private static final String PREFS_MONOCHROME = "monochrome";
FormattedDisk currentDisk;
@ -59,6 +60,7 @@ public class MenuHandler
JMenuItem interleave3Item = new JRadioButtonMenuItem (new InterleaveAction (3));
JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks");
JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome");
public MenuHandler (Preferences prefs)
{
@ -107,6 +109,7 @@ public class MenuHandler
formatMenu.add (sector512Item);
formatMenu.addSeparator ();
formatMenu.add (colourQuirksItem);
formatMenu.add (monochromeItem);
helpMenu.add (new JMenuItem (new EnvironmentAction ()));
@ -133,7 +136,10 @@ public class MenuHandler
showCatalogItem.setSelected (prefs.getBoolean (PREFS_SHOW_CATALOG, true));
showFreeSectorsItem.setSelected (prefs.getBoolean (PREFS_SHOW_FREE_SECTORS, false));
colourQuirksItem.setSelected (prefs.getBoolean (PREFS_COLOUR_QUIRKS, false));
monochromeItem.setSelected (prefs.getBoolean (PREFS_MONOCHROME, false));
HiResImage.setDefaultColourQuirks (colourQuirksItem.isSelected ());
HiResImage.setDefaultMonochrome (monochromeItem.isSelected ());
}
void addHelpMenuAction (Action action, String functionName)
@ -188,6 +194,7 @@ public class MenuHandler
prefs.putBoolean (PREFS_SHOW_CATALOG, showCatalogItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_FREE_SECTORS, showFreeSectorsItem.isSelected ());
prefs.putBoolean (PREFS_COLOUR_QUIRKS, colourQuirksItem.isSelected ());
prefs.putBoolean (PREFS_MONOCHROME, monochromeItem.isSelected ());
}
@Override

View File

@ -0,0 +1,29 @@
package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
public class MonochromeAction extends AbstractAction
{
private final DataPanel owner;
public MonochromeAction (DataPanel owner)
{
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);
this.owner = owner;
}
@Override
public void actionPerformed (ActionEvent e)
{
owner.setMonochrome (((JMenuItem) e.getSource ()).isSelected ());
}
}