mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-25 16:34:00 +00:00
Applesoft preferences menu
This commit is contained in:
parent
d4ae96aef1
commit
630cbab86f
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.bytezone.diskbrowser.gui.BasicPreferences;
|
||||
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
||||
|
||||
public class BasicProgram extends AbstractFile
|
||||
@ -32,13 +33,7 @@ public class BasicProgram extends AbstractFile
|
||||
private final Set<Integer> gotoLines = new HashSet<Integer> ();
|
||||
private final Set<Integer> gosubLines = new HashSet<Integer> ();
|
||||
|
||||
private final boolean splitRem = false; // should be a user preference
|
||||
private final boolean alignAssign = true; // should be a user preference
|
||||
private final boolean showTargets = true; // should be a user preference
|
||||
private final boolean showHeader = true; // should be a user preference
|
||||
private final boolean onlyShowTargetLineNumbers = false; // should be a user preference
|
||||
private final int wrapPrintAt = 40;
|
||||
private final int wrapRemAt = 60;
|
||||
private static BasicPreferences basicPreferences;
|
||||
|
||||
public BasicProgram (String name, byte[] buffer)
|
||||
{
|
||||
@ -62,16 +57,21 @@ public class BasicProgram extends AbstractFile
|
||||
endPtr = ptr;
|
||||
}
|
||||
|
||||
public static void setBasicPreferences (BasicPreferences basicPreferences)
|
||||
{
|
||||
BasicProgram.basicPreferences = basicPreferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
StringBuilder fullText = new StringBuilder ();
|
||||
Stack<String> loopVariables = new Stack<String> ();
|
||||
if (showHeader)
|
||||
if (basicPreferences.showHeader)
|
||||
addHeader (fullText);
|
||||
int alignPos = 0;
|
||||
StringBuilder text;
|
||||
int baseOffset = showTargets ? 12 : 8;
|
||||
int baseOffset = basicPreferences.showTargets ? 12 : 8;
|
||||
|
||||
for (SourceLine line : sourceLines)
|
||||
{
|
||||
@ -107,7 +107,7 @@ public class BasicProgram extends AbstractFile
|
||||
}
|
||||
|
||||
// Are we joining REM lines with the previous subline?
|
||||
if (!splitRem && subline.isJoinableRem ())
|
||||
if (!basicPreferences.splitRem && subline.isJoinableRem ())
|
||||
{
|
||||
// Join this REM statement to the previous line, so no indenting
|
||||
fullText.deleteCharAt (fullText.length () - 1); // remove newline
|
||||
@ -116,14 +116,14 @@ public class BasicProgram extends AbstractFile
|
||||
else // ... otherwise do all the indenting and showing of targets etc.
|
||||
{
|
||||
// Prepare target indicators for subsequent sublines (ie no line number)
|
||||
if (showTargets && !subline.isFirst ())
|
||||
if (basicPreferences.showTargets && !subline.isFirst ())
|
||||
if (subline.is (TOKEN_GOSUB))
|
||||
text.append ("<<--");
|
||||
else if (subline.is (TOKEN_GOTO) || subline.isImpliedGoto ())
|
||||
text.append (" <--");
|
||||
|
||||
// Align assign statements if required
|
||||
if (alignAssign)
|
||||
if (basicPreferences.alignAssign)
|
||||
alignPos = alignEqualsPosition (subline, alignPos);
|
||||
|
||||
int column = indent * 2 + baseOffset;
|
||||
@ -137,13 +137,13 @@ public class BasicProgram extends AbstractFile
|
||||
|
||||
// Check for a wrappable REM statement
|
||||
// (see SEA BATTLE on DISK283.DSK)
|
||||
if (subline.is (TOKEN_REM) && lineText.length () > wrapRemAt + 4)
|
||||
if (subline.is (TOKEN_REM) && lineText.length () > basicPreferences.wrapRemAt + 4)
|
||||
{
|
||||
// System.out.println (lineText.length ());
|
||||
String copy = lineText.substring (4);
|
||||
text.append ("REM ");
|
||||
int inset = text.length () + 1;
|
||||
List<String> remarks = splitRemark (copy, wrapRemAt);
|
||||
List<String> remarks = splitRemark (copy, basicPreferences.wrapRemAt);
|
||||
boolean first = true;
|
||||
for (String remark : remarks)
|
||||
{
|
||||
@ -161,7 +161,8 @@ public class BasicProgram extends AbstractFile
|
||||
|
||||
// Check for a wrappable PRINT statement
|
||||
// (see FROM MACHINE LANGUAGE TO BASIC on DOSToolkit2eB.dsk)
|
||||
if (wrapPrintAt > 0 && (subline.is (TOKEN_PRINT) || subline.is (TOKEN_INPUT))
|
||||
if (basicPreferences.wrapPrintAt > 0 //
|
||||
&& (subline.is (TOKEN_PRINT) || subline.is (TOKEN_INPUT))
|
||||
&& countChars (text, ASCII_QUOTE) == 2 // just start and end quotes
|
||||
&& countChars (text, ASCII_CARET) == 0) // no control characters
|
||||
// && countChars (text, ASCII_SEMI_COLON) == 0)
|
||||
@ -189,16 +190,16 @@ public class BasicProgram extends AbstractFile
|
||||
{
|
||||
int first = text.indexOf ("\"") + 1;
|
||||
int last = text.indexOf ("\"", first + 1) - 1;
|
||||
if ((last - first) > wrapPrintAt)
|
||||
if ((last - first) > basicPreferences.wrapPrintAt)
|
||||
{
|
||||
int ptr = first + wrapPrintAt;
|
||||
int ptr = first + basicPreferences.wrapPrintAt;
|
||||
do
|
||||
{
|
||||
fullText.append (text.substring (0, ptr)
|
||||
+ "\n ".substring (0, first + 1));
|
||||
text.delete (0, ptr);
|
||||
ptr = wrapPrintAt;
|
||||
} while (text.length () > wrapPrintAt);
|
||||
ptr = basicPreferences.wrapPrintAt;
|
||||
} while (text.length () > basicPreferences.wrapPrintAt);
|
||||
}
|
||||
fullText.append (text + "\n");
|
||||
}
|
||||
@ -232,7 +233,7 @@ public class BasicProgram extends AbstractFile
|
||||
int first = line.indexOf ("\"") + 1;
|
||||
int last = line.indexOf ("\"", first + 1) - 1;
|
||||
|
||||
if (first != 7 || (last - first) <= wrapPrintAt)
|
||||
if (first != 7 || (last - first) <= basicPreferences.wrapPrintAt)
|
||||
return null;
|
||||
|
||||
int charsLeft = last - first + 1;
|
||||
@ -243,10 +244,10 @@ public class BasicProgram extends AbstractFile
|
||||
String sub;
|
||||
while (true)
|
||||
{
|
||||
if (line.length () >= wrapPrintAt)
|
||||
if (line.length () >= basicPreferences.wrapPrintAt)
|
||||
{
|
||||
sub = line.substring (0, wrapPrintAt);
|
||||
line = line.substring (wrapPrintAt);
|
||||
sub = line.substring (0, basicPreferences.wrapPrintAt);
|
||||
line = line.substring (basicPreferences.wrapPrintAt);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -255,7 +256,7 @@ public class BasicProgram extends AbstractFile
|
||||
}
|
||||
|
||||
String subline = padding + sub;
|
||||
charsLeft -= wrapPrintAt;
|
||||
charsLeft -= basicPreferences.wrapPrintAt;
|
||||
|
||||
if (charsLeft > 0)
|
||||
lines.add (subline);
|
||||
@ -298,7 +299,7 @@ public class BasicProgram extends AbstractFile
|
||||
|
||||
private String getBase (SourceLine line)
|
||||
{
|
||||
if (!showTargets)
|
||||
if (!basicPreferences.showTargets)
|
||||
return String.format (" %5d", line.lineNumber);
|
||||
|
||||
String lineNumberText = String.format ("%5d", line.lineNumber);
|
||||
@ -316,7 +317,7 @@ public class BasicProgram extends AbstractFile
|
||||
c1 = "--";
|
||||
if (!c1.equals (" ") && c2.equals (" "))
|
||||
c2 = "--";
|
||||
if (onlyShowTargetLineNumbers && !c2.startsWith (">"))
|
||||
if (basicPreferences.onlyShowTargetLineNumbers && !c2.startsWith (">"))
|
||||
lineNumberText = "";
|
||||
return String.format ("%s%s %s", c1, c2, lineNumberText);
|
||||
}
|
||||
@ -351,7 +352,7 @@ public class BasicProgram extends AbstractFile
|
||||
// Lines that start with a REM always break.
|
||||
if (subline.assignEqualPos == 0
|
||||
// && (splitRem || !subline.is (TOKEN_REM) || subline.isFirst ()))
|
||||
&& (splitRem || !subline.isJoinableRem ()))
|
||||
&& (basicPreferences.splitRem || !subline.isJoinableRem ()))
|
||||
break fast; // of champions
|
||||
|
||||
if (subline.assignEqualPos > highestAssign)
|
||||
@ -375,7 +376,7 @@ public class BasicProgram extends AbstractFile
|
||||
return super.getHexDump ();
|
||||
|
||||
StringBuilder pgm = new StringBuilder ();
|
||||
if (showHeader)
|
||||
if (basicPreferences.showHeader)
|
||||
addHeader (pgm);
|
||||
|
||||
int ptr = 0;
|
||||
@ -566,7 +567,7 @@ public class BasicProgram extends AbstractFile
|
||||
this.length = length;
|
||||
|
||||
byte b = buffer[startPtr];
|
||||
if ((b & 0x80) > 0) // token
|
||||
if (isToken (b))
|
||||
{
|
||||
switch (b)
|
||||
{
|
||||
@ -620,7 +621,7 @@ public class BasicProgram extends AbstractFile
|
||||
}
|
||||
else
|
||||
{
|
||||
if (b >= 48 && b <= 57) // numeric, so must be a line number
|
||||
if (isDigit (b)) // numeric, so must be a line number
|
||||
{
|
||||
String target = new String (buffer, startPtr, length - 1);
|
||||
try
|
||||
@ -638,7 +639,8 @@ public class BasicProgram extends AbstractFile
|
||||
// assert false;
|
||||
}
|
||||
}
|
||||
else if (alignAssign)
|
||||
// else if (basicPreferences.alignAssign)
|
||||
else
|
||||
recordEqualsPosition ();
|
||||
}
|
||||
}
|
||||
@ -646,9 +648,9 @@ public class BasicProgram extends AbstractFile
|
||||
private boolean isImpliedGoto ()
|
||||
{
|
||||
byte b = buffer[startPtr];
|
||||
if ((b & 0x80) > 0) // token
|
||||
if (isToken (b))
|
||||
return false;
|
||||
return (b >= 48 && b <= 57);
|
||||
return (isDigit (b));
|
||||
}
|
||||
|
||||
// Record the position of the equals sign so it can be aligned with adjacent lines.
|
||||
@ -686,11 +688,26 @@ public class BasicProgram extends AbstractFile
|
||||
{
|
||||
// ignore first byte, check the rest for tokens
|
||||
for (int p = startPtr + 1, max = startPtr + length; p < max; p++)
|
||||
if ((buffer[p] & 0x80) > 0)
|
||||
if (isToken (buffer[p]))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isToken (byte value)
|
||||
{
|
||||
return (value & 0x80) > 0;
|
||||
}
|
||||
|
||||
private boolean isControlCharacter (byte value)
|
||||
{
|
||||
return value < 32;
|
||||
}
|
||||
|
||||
private boolean isDigit (byte value)
|
||||
{
|
||||
return value >= 48 && value <= 57;
|
||||
}
|
||||
|
||||
public int getAddress ()
|
||||
{
|
||||
return getLoadAddress () + startPtr;
|
||||
@ -734,7 +751,7 @@ public class BasicProgram extends AbstractFile
|
||||
for (int p = startPtr; p <= max; p++)
|
||||
{
|
||||
byte b = buffer[p];
|
||||
if ((b & 0x80) > 0) // token
|
||||
if (isToken (b))
|
||||
{
|
||||
if (line.length () > 0 && line.charAt (line.length () - 1) != ' ')
|
||||
line.append (' ');
|
||||
@ -742,8 +759,8 @@ public class BasicProgram extends AbstractFile
|
||||
if (val < ApplesoftConstants.tokens.length)
|
||||
line.append (ApplesoftConstants.tokens[b & 0x7F]);
|
||||
}
|
||||
else if (b < 32) // CTRL character
|
||||
line.append ("^" + (char) (b + 64)); // would be better in inverse text
|
||||
else if (isControlCharacter (b))
|
||||
line.append (basicPreferences.showCaret ? "^" + (char) (b + 64) : "");
|
||||
else
|
||||
line.append ((char) b);
|
||||
}
|
||||
|
@ -47,11 +47,12 @@ public class IntegerBasicProgram extends AbstractFile
|
||||
pgm.append ("\nPossible assembler code follows\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (lineLength <= 0)
|
||||
break;
|
||||
|
||||
if (looksLikeSCAssembler)
|
||||
appendSCAssembler (pgm, ptr, lineLength);
|
||||
appendSCAssembler (pgm, ptr);
|
||||
else if (looksLikeAssembler)
|
||||
appendAssembler (pgm, ptr, lineLength);
|
||||
else
|
||||
@ -128,10 +129,10 @@ public class IntegerBasicProgram extends AbstractFile
|
||||
return buffer[lineLength - 1] == 0;
|
||||
}
|
||||
|
||||
private void appendSCAssembler (StringBuilder pgm, int ptr, int lineLength)
|
||||
private void appendSCAssembler (StringBuilder text, int ptr)
|
||||
{
|
||||
int lineNumber = (buffer[ptr + 2] & 0xFF) * 256 + (buffer[ptr + 1] & 0xFF);
|
||||
pgm.append (String.format ("%4d: ", lineNumber));
|
||||
text.append (String.format ("%4d: ", lineNumber));
|
||||
int p2 = ptr + 3;
|
||||
while (buffer[p2] != 0)
|
||||
{
|
||||
@ -139,22 +140,22 @@ public class IntegerBasicProgram extends AbstractFile
|
||||
{
|
||||
int repeat = buffer[p2 + 1];
|
||||
for (int i = 0; i < repeat; i++)
|
||||
pgm.append ((char) buffer[p2 + 2]);
|
||||
text.append ((char) buffer[p2 + 2]);
|
||||
p2 += 2;
|
||||
}
|
||||
else if ((buffer[p2] & 0x80) != 0)
|
||||
{
|
||||
int spaces = buffer[p2] & 0x7F;
|
||||
for (int i = 0; i < spaces; i++)
|
||||
pgm.append (' ');
|
||||
text.append (' ');
|
||||
}
|
||||
else
|
||||
pgm.append ((char) buffer[p2]);
|
||||
text.append ((char) buffer[p2]);
|
||||
p2++;
|
||||
}
|
||||
}
|
||||
|
||||
private void appendInteger (StringBuilder pgm, int ptr, int lineLength)
|
||||
private void appendInteger (StringBuilder text, int ptr, int lineLength)
|
||||
{
|
||||
int lineNumber = HexFormatter.intValue (buffer[ptr + 1], buffer[ptr + 2]);
|
||||
|
||||
@ -163,7 +164,7 @@ public class IntegerBasicProgram extends AbstractFile
|
||||
|
||||
String lineText = String.format ("%5d ", lineNumber);
|
||||
int lineTab = lineText.length ();
|
||||
pgm.append (lineText);
|
||||
text.append (lineText);
|
||||
|
||||
for (int p = ptr + 3; p < ptr + lineLength - 1; p++)
|
||||
{
|
||||
@ -172,7 +173,7 @@ public class IntegerBasicProgram extends AbstractFile
|
||||
if (b == 0x03 // token for colon (:)
|
||||
&& !inString && !inRemark && buffer[p + 1] != 1) // not end of line
|
||||
{
|
||||
pgm.append (":\n" + " ".substring (0, lineTab));
|
||||
text.append (":\n" + " ".substring (0, lineTab));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -180,7 +181,7 @@ public class IntegerBasicProgram extends AbstractFile
|
||||
&& (buffer[p - 1] & 0x80) == 0 // not a variable name
|
||||
&& !inString && !inRemark)
|
||||
{
|
||||
pgm.append (HexFormatter.intValue (buffer[p + 1], buffer[p + 2]));
|
||||
text.append (HexFormatter.intValue (buffer[p + 1], buffer[p + 2]));
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
@ -189,20 +190,20 @@ public class IntegerBasicProgram extends AbstractFile
|
||||
{
|
||||
b -= 128;
|
||||
if (b >= 32)
|
||||
pgm.append ((char) b);
|
||||
text.append ((char) b);
|
||||
else
|
||||
pgm.append ("<ctrl-" + (char) (b + 64) + ">");
|
||||
text.append ("<ctrl-" + (char) (b + 64) + ">");
|
||||
}
|
||||
else if (!tokens[b].equals ("?"))
|
||||
{
|
||||
pgm.append (tokens[b]);
|
||||
text.append (tokens[b]);
|
||||
if ((b == 40 || b == 41) && !inRemark) // double quotes
|
||||
inString = !inString;
|
||||
if (b == 0x5D)
|
||||
inRemark = true;
|
||||
}
|
||||
else
|
||||
pgm.append (" ." + HexFormatter.format2 (b) + ". ");
|
||||
text.append (" ." + HexFormatter.format2 (b) + ". ");
|
||||
}
|
||||
}
|
||||
|
||||
|
27
src/com/bytezone/diskbrowser/gui/BasicPreferences.java
Normal file
27
src/com/bytezone/diskbrowser/gui/BasicPreferences.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
public class BasicPreferences
|
||||
{
|
||||
public boolean splitRem = false;
|
||||
public boolean alignAssign = true;
|
||||
public boolean showTargets = true;
|
||||
public boolean showHeader = true;
|
||||
public boolean onlyShowTargetLineNumbers = false;
|
||||
public boolean showCaret = false;
|
||||
public int wrapPrintAt = 40;
|
||||
public int wrapRemAt = 60;
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
text.append (String.format ("Split remark ...... %s%n", splitRem));
|
||||
text.append (String.format ("Align assign ...... %s%n", alignAssign));
|
||||
text.append (String.format ("Show targets ...... %s%n", showTargets));
|
||||
text.append (String.format ("Show header ....... %s%n", showHeader));
|
||||
text.append (String.format ("Show caret ........ %s", showCaret));
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
public interface BasicPreferencesListener
|
||||
{
|
||||
public void setBasicPreferences (BasicPreferences basicPreferences);
|
||||
}
|
@ -13,6 +13,7 @@ import javax.swing.event.ChangeListener;
|
||||
|
||||
import com.bytezone.common.FontAction.FontChangeEvent;
|
||||
import com.bytezone.common.FontAction.FontChangeListener;
|
||||
import com.bytezone.diskbrowser.applefile.BasicProgram;
|
||||
import com.bytezone.diskbrowser.applefile.HiResImage;
|
||||
import com.bytezone.diskbrowser.applefile.Palette;
|
||||
import com.bytezone.diskbrowser.applefile.PaletteFactory.CycleDirection;
|
||||
@ -23,7 +24,7 @@ import com.bytezone.diskbrowser.disk.SectorList;
|
||||
|
||||
class DataPanel extends JTabbedPane
|
||||
implements DiskSelectionListener, FileSelectionListener, SectorSelectionListener,
|
||||
FileNodeSelectionListener, FontChangeListener
|
||||
FileNodeSelectionListener, FontChangeListener, BasicPreferencesListener
|
||||
{
|
||||
private static final int TEXT_WIDTH = 65;
|
||||
|
||||
@ -118,7 +119,10 @@ class DataPanel extends JTabbedPane
|
||||
}
|
||||
});
|
||||
|
||||
menuHandler.lineWrapItem.setAction (new LineWrapAction (formattedText));
|
||||
LineWrapAction lineWrapAction = new LineWrapAction ();
|
||||
menuHandler.lineWrapItem.setAction (lineWrapAction);
|
||||
lineWrapAction.addListener (formattedText);
|
||||
|
||||
menuHandler.colourQuirksItem.setAction (new ColourQuirksAction (this));
|
||||
menuHandler.monochromeItem.setAction (new MonochromeAction (this));
|
||||
menuHandler.debuggingItem.setAction (new DebuggingAction (this));
|
||||
@ -229,6 +233,7 @@ class DataPanel extends JTabbedPane
|
||||
private void setDataSource (DataSource dataSource)
|
||||
{
|
||||
currentDataSource = dataSource;
|
||||
|
||||
if (dataSource == null)
|
||||
{
|
||||
formattedText.setText ("");
|
||||
@ -381,7 +386,8 @@ class DataPanel extends JTabbedPane
|
||||
@Override
|
||||
public void fileSelected (FileSelectedEvent event)
|
||||
{
|
||||
setDataSource (event.file.getDataSource ());
|
||||
DataSource dataSource = event.file.getDataSource ();
|
||||
setDataSource (dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -414,4 +420,11 @@ class DataPanel extends JTabbedPane
|
||||
{
|
||||
setTabsFont (fontChangeEvent.font);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBasicPreferences (BasicPreferences basicPreferences)
|
||||
{
|
||||
if (currentDataSource instanceof BasicProgram)
|
||||
setDataSource (currentDataSource);
|
||||
}
|
||||
}
|
@ -167,6 +167,8 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi
|
||||
if (!menuHandler.showCatalogItem.isSelected ())
|
||||
hideCatalogAction.set (false);
|
||||
|
||||
menuHandler.addBasicPreferencesListener (dataPanel);
|
||||
|
||||
// activate the highest panel now that the listeners are ready
|
||||
catalogPanel.activate ();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ 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;
|
||||
@ -11,19 +13,26 @@ import javax.swing.KeyStroke;
|
||||
|
||||
class LineWrapAction extends AbstractAction
|
||||
{
|
||||
JTextArea owner;
|
||||
List<JTextArea> listeners = new ArrayList<> ();
|
||||
|
||||
public LineWrapAction (JTextArea owner)
|
||||
public LineWrapAction ()
|
||||
{
|
||||
super ("Line wrap");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Print the contents of the output panel");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt W"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_W);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public void addListener (JTextArea listener)
|
||||
{
|
||||
if (!listeners.contains (listener))
|
||||
listeners.add (listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
owner.setLineWrap (((JMenuItem) e.getSource ()).isSelected ());
|
||||
for (JTextArea listener : listeners)
|
||||
listener.setLineWrap (((JMenuItem) e.getSource ()).isSelected ());
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.bytezone.diskbrowser.gui;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.prefs.Preferences;
|
||||
@ -11,6 +12,7 @@ import javax.swing.*;
|
||||
|
||||
import com.bytezone.common.EnvironmentAction;
|
||||
import com.bytezone.common.FontAction;
|
||||
import com.bytezone.diskbrowser.applefile.BasicProgram;
|
||||
import com.bytezone.diskbrowser.applefile.HiResImage;
|
||||
import com.bytezone.diskbrowser.applefile.Palette;
|
||||
import com.bytezone.diskbrowser.applefile.PaletteFactory;
|
||||
@ -27,16 +29,27 @@ public class MenuHandler
|
||||
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";
|
||||
|
||||
private static final String PREFS_SPLIT_REMARKS = "splitRemarks";
|
||||
private static final String PREFS_ALIGN_ASSIGN = "alignAssign";
|
||||
private static final String PREFS_SHOW_TARGETS = "showTargets";
|
||||
private static final String PREFS_SHOW_HEADER = "showHeader";
|
||||
private static final String PREFS_SHOW_CARET = "showCaret";
|
||||
|
||||
// private static final String PREFS_DEBUGGING = "debugging";
|
||||
private static final String PREFS_PALETTE = "palette";
|
||||
|
||||
FormattedDisk currentDisk;
|
||||
private final SaveTempFileAction saveTempFileAction = new SaveTempFileAction ();
|
||||
private final BasicPreferences basicPreferences = new BasicPreferences ();
|
||||
private final List<BasicPreferencesListener> basicPreferencesListeners =
|
||||
new ArrayList<> ();
|
||||
|
||||
JMenuBar menuBar = new JMenuBar ();
|
||||
JMenu fileMenu = new JMenu ("File");
|
||||
JMenu formatMenu = new JMenu ("Format");
|
||||
JMenu colourMenu = new JMenu ("Colours");
|
||||
JMenu applesoftMenu = new JMenu ("Applesoft");
|
||||
JMenu helpMenu = new JMenu ("Help");
|
||||
|
||||
// File menu items
|
||||
@ -68,6 +81,12 @@ public class MenuHandler
|
||||
final JMenuItem nextPaletteItem = new JMenuItem ("Next Palette");
|
||||
final JMenuItem prevPaletteItem = new JMenuItem ("Previous Palette");
|
||||
|
||||
final JMenuItem splitRemarkItem = new JCheckBoxMenuItem ("Split remarks");
|
||||
final JMenuItem alignAssignItem = new JCheckBoxMenuItem ("Align assign");
|
||||
final JMenuItem showTargetsItem = new JCheckBoxMenuItem ("Show targets");
|
||||
final JMenuItem showHeaderItem = new JCheckBoxMenuItem ("Show header");
|
||||
final JMenuItem showCaretItem = new JCheckBoxMenuItem ("Show caret");
|
||||
|
||||
ButtonGroup paletteGroup = new ButtonGroup ();
|
||||
|
||||
public MenuHandler (Preferences prefs)
|
||||
@ -75,6 +94,7 @@ public class MenuHandler
|
||||
menuBar.add (fileMenu);
|
||||
menuBar.add (formatMenu);
|
||||
menuBar.add (colourMenu);
|
||||
menuBar.add (applesoftMenu);
|
||||
menuBar.add (helpMenu);
|
||||
|
||||
fileMenu.add (rootItem);
|
||||
@ -131,6 +151,28 @@ public class MenuHandler
|
||||
colourMenu.add (nextPaletteItem);
|
||||
colourMenu.add (prevPaletteItem);
|
||||
|
||||
applesoftMenu.add (splitRemarkItem);
|
||||
applesoftMenu.add (alignAssignItem);
|
||||
applesoftMenu.add (showTargetsItem);
|
||||
applesoftMenu.add (showHeaderItem);
|
||||
applesoftMenu.add (showCaretItem);
|
||||
|
||||
ActionListener basicPreferencesAction = new ActionListener ()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
setBasicPreferences ();
|
||||
notifyBasicPreferencesListeners ();
|
||||
}
|
||||
};
|
||||
|
||||
splitRemarkItem.addActionListener (basicPreferencesAction);
|
||||
alignAssignItem.addActionListener (basicPreferencesAction);
|
||||
showTargetsItem.addActionListener (basicPreferencesAction);
|
||||
showHeaderItem.addActionListener (basicPreferencesAction);
|
||||
showCaretItem.addActionListener (basicPreferencesAction);
|
||||
|
||||
helpMenu.add (new JMenuItem (new EnvironmentAction ()));
|
||||
|
||||
sector256Item.setActionCommand ("256");
|
||||
@ -151,6 +193,31 @@ public class MenuHandler
|
||||
saveDiskItem.setAction (saveTempFileAction);
|
||||
}
|
||||
|
||||
private void setBasicPreferences ()
|
||||
{
|
||||
basicPreferences.splitRem = splitRemarkItem.isSelected ();
|
||||
basicPreferences.alignAssign = alignAssignItem.isSelected ();
|
||||
basicPreferences.showCaret = showCaretItem.isSelected ();
|
||||
basicPreferences.showHeader = showHeaderItem.isSelected ();
|
||||
basicPreferences.showTargets = showTargetsItem.isSelected ();
|
||||
BasicProgram.setBasicPreferences (basicPreferences);
|
||||
}
|
||||
|
||||
void addBasicPreferencesListener (BasicPreferencesListener listener)
|
||||
{
|
||||
if (!basicPreferencesListeners.contains (listener))
|
||||
{
|
||||
basicPreferencesListeners.add (listener);
|
||||
listener.setBasicPreferences (basicPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
void notifyBasicPreferencesListeners ()
|
||||
{
|
||||
for (BasicPreferencesListener listener : basicPreferencesListeners)
|
||||
listener.setBasicPreferences (basicPreferences);
|
||||
}
|
||||
|
||||
void addHelpMenuAction (Action action, String functionName)
|
||||
{
|
||||
helpMenu.add (new JMenuItem (action));
|
||||
@ -189,6 +256,12 @@ public class MenuHandler
|
||||
prefs.putInt (PREFS_PALETTE,
|
||||
HiResImage.getPaletteFactory ().getCurrentPaletteIndex ());
|
||||
fontAction.quit (prefs);
|
||||
|
||||
prefs.putBoolean (PREFS_SPLIT_REMARKS, splitRemarkItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_ALIGN_ASSIGN, alignAssignItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_CARET, showCaretItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_HEADER, showHeaderItem.isSelected ());
|
||||
prefs.putBoolean (PREFS_SHOW_TARGETS, showTargetsItem.isSelected ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -202,6 +275,14 @@ public class MenuHandler
|
||||
monochromeItem.setSelected (prefs.getBoolean (PREFS_MONOCHROME, false));
|
||||
// debuggingItem.setSelected (prefs.getBoolean (PREFS_DEBUGGING, false));
|
||||
|
||||
splitRemarkItem.setSelected (prefs.getBoolean (PREFS_SPLIT_REMARKS, false));
|
||||
alignAssignItem.setSelected (prefs.getBoolean (PREFS_ALIGN_ASSIGN, true));
|
||||
showCaretItem.setSelected (prefs.getBoolean (PREFS_SHOW_CARET, false));
|
||||
showHeaderItem.setSelected (prefs.getBoolean (PREFS_SHOW_HEADER, true));
|
||||
showTargetsItem.setSelected (prefs.getBoolean (PREFS_SHOW_TARGETS, false));
|
||||
|
||||
setBasicPreferences ();
|
||||
|
||||
int paletteIndex = prefs.getInt (PREFS_PALETTE, 0);
|
||||
PaletteFactory paletteFactory = HiResImage.getPaletteFactory ();
|
||||
paletteFactory.setCurrentPalette (paletteIndex);
|
||||
|
Loading…
Reference in New Issue
Block a user