dmolony-DiskBrowser/src/com/bytezone/diskbrowser/gui/MenuHandler.java

503 lines
19 KiB
Java
Raw Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.gui;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
2019-08-08 10:01:56 +00:00
import java.util.ArrayList;
2017-01-14 01:40:58 +00:00
import java.util.Enumeration;
import java.util.List;
2015-06-01 09:35:51 +00:00
import java.util.prefs.Preferences;
import javax.swing.*;
2016-02-21 00:00:57 +00:00
import com.bytezone.common.FontAction;
2019-08-15 07:02:40 +00:00
import com.bytezone.diskbrowser.applefile.*;
2015-06-01 09:35:51 +00:00
import com.bytezone.diskbrowser.disk.DataDisk;
import com.bytezone.diskbrowser.disk.FormattedDisk;
2019-09-13 10:07:01 +00:00
import com.bytezone.diskbrowser.prodos.ProdosDisk;
2015-06-01 09:35:51 +00:00
2016-02-21 00:00:57 +00:00
public class MenuHandler
implements DiskSelectionListener, FileSelectionListener, QuitListener
2015-06-01 09:35:51 +00:00
{
2017-01-27 07:11:00 +00:00
static final String PREFS_LINE_WRAP = "line wrap";
2015-06-01 09:35:51 +00:00
private static final String PREFS_SHOW_CATALOG = "show catalog";
private static final String PREFS_SHOW_LAYOUT = "show layout";
private static final String PREFS_SHOW_FREE_SECTORS = "show free sectors";
2016-02-21 00:00:57 +00:00
private static final String PREFS_COLOUR_QUIRKS = "colour quirks";
2016-02-22 10:58:15 +00:00
private static final String PREFS_MONOCHROME = "monochrome";
2019-08-08 10:01:56 +00:00
private static final String PREFS_SPLIT_REMARKS = "splitRemarks";
private static final String PREFS_ALIGN_ASSIGN = "alignAssign";
private static final String PREFS_SHOW_TARGETS = "showTargets";
2019-08-08 10:12:34 +00:00
private static final String PREFS_ONLY_SHOW_TARGETS = "onlyShowTargets";
2019-08-08 10:01:56 +00:00
private static final String PREFS_SHOW_HEADER = "showHeader";
private static final String PREFS_SHOW_CARET = "showCaret";
2019-08-15 07:02:40 +00:00
private static final String PREFS_SHOW_ASSEMBLER_TARGETS = "showAssemblerTargets";
private static final String PREFS_SHOW_ASSEMBLER_STRINGS = "showAssemblerStrings";
2019-09-04 20:44:43 +00:00
private static final String PREFS_SHOW_ASSEMBLER_HEADER = "showAssemblerHeader";
2019-08-15 07:02:40 +00:00
2019-09-13 10:07:01 +00:00
private static final String PREFS_PRODOS_SORT_DIRECTORIES = "prodosSortDirectories";
2017-01-27 07:11:00 +00:00
// private static final String PREFS_DEBUGGING = "debugging";
2017-01-14 01:40:58 +00:00
private static final String PREFS_PALETTE = "palette";
2015-06-01 09:35:51 +00:00
FormattedDisk currentDisk;
2019-03-05 07:08:34 +00:00
private final SaveTempFileAction saveTempFileAction = new SaveTempFileAction ();
2019-08-15 07:02:40 +00:00
2019-08-08 10:01:56 +00:00
private final BasicPreferences basicPreferences = new BasicPreferences ();
private final List<BasicPreferencesListener> basicPreferencesListeners =
new ArrayList<> ();
2015-06-01 09:35:51 +00:00
2019-08-15 07:02:40 +00:00
private final AssemblerPreferences assemblerPreferences = new AssemblerPreferences ();
private final List<AssemblerPreferencesListener> assemblerPreferencesListeners =
new ArrayList<> ();
2019-09-13 10:07:01 +00:00
private final ProdosPreferences prodosPreferences = new ProdosPreferences ();
private final List<ProdosPreferencesListener> prodosPreferencesListeners =
new ArrayList<> ();
2015-06-01 09:35:51 +00:00
JMenuBar menuBar = new JMenuBar ();
JMenu fileMenu = new JMenu ("File");
JMenu formatMenu = new JMenu ("Format");
2017-01-14 01:40:58 +00:00
JMenu colourMenu = new JMenu ("Colours");
2019-08-08 10:01:56 +00:00
JMenu applesoftMenu = new JMenu ("Applesoft");
2019-08-15 07:02:40 +00:00
JMenu assemblerMenu = new JMenu ("Assembler");
2019-09-13 10:07:01 +00:00
JMenu prodosMenu = new JMenu ("Prodos");
2019-10-12 02:47:21 +00:00
// JMenu helpMenu = new JMenu ("Help");
2015-06-01 09:35:51 +00:00
// File menu items
2018-07-28 12:00:02 +00:00
final JMenuItem rootItem = new JMenuItem ("Set root folder...");
final JMenuItem refreshTreeItem = new JMenuItem ("Refresh current tree");
2015-06-01 09:35:51 +00:00
JMenuItem executeDiskItem;
2019-03-05 07:08:34 +00:00
final JMenuItem saveDiskItem = new JMenuItem ("Save converted disk as...");
2018-07-28 12:00:02 +00:00
final JMenuItem printItem = new JMenuItem ("Print output panel...");
final JMenuItem closeTabItem = new JMenuItem ();
final JMenuItem duplicateItem = new JMenuItem ();
2018-07-30 08:44:29 +00:00
final FontAction fontAction = new FontAction ();
2015-06-01 09:35:51 +00:00
// Format menu items
2016-02-21 00:00:57 +00:00
final JMenuItem lineWrapItem = new JCheckBoxMenuItem ("Line wrap");
final JMenuItem showLayoutItem = new JCheckBoxMenuItem ("Show layout panel");
2018-07-28 12:00:02 +00:00
final JMenuItem showCatalogItem = new JCheckBoxMenuItem ("Show catalog panel");
final JMenuItem showFreeSectorsItem = new JCheckBoxMenuItem ("Show free sectors");
2015-06-01 09:35:51 +00:00
2018-07-28 12:00:02 +00:00
final JMenuItem sector256Item = new JRadioButtonMenuItem ("256 byte sectors");
final JMenuItem sector512Item = new JRadioButtonMenuItem ("512 byte blocks");
final JMenuItem interleave0Item = new JRadioButtonMenuItem (new InterleaveAction (0));
final JMenuItem interleave1Item = new JRadioButtonMenuItem (new InterleaveAction (1));
final JMenuItem interleave2Item = new JRadioButtonMenuItem (new InterleaveAction (2));
final JMenuItem interleave3Item = new JRadioButtonMenuItem (new InterleaveAction (3));
2015-06-01 09:35:51 +00:00
2018-07-28 12:00:02 +00:00
final JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks");
final JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome");
final JMenuItem debuggingItem = new JCheckBoxMenuItem ("Debugging");
final JMenuItem nextPaletteItem = new JMenuItem ("Next Palette");
final JMenuItem prevPaletteItem = new JMenuItem ("Previous Palette");
2017-01-14 01:40:58 +00:00
2019-08-15 07:02:40 +00:00
// Applesoft menu items
2019-08-08 10:01:56 +00:00
final JMenuItem splitRemarkItem = new JCheckBoxMenuItem ("Split remarks");
final JMenuItem alignAssignItem = new JCheckBoxMenuItem ("Align assign");
2019-08-15 07:02:40 +00:00
final JMenuItem showBasicTargetsItem = new JCheckBoxMenuItem ("Show targets");
2019-08-08 10:12:34 +00:00
final JMenuItem onlyShowTargetLinesItem =
new JCheckBoxMenuItem ("Only show target lines");
2019-08-08 10:01:56 +00:00
final JMenuItem showHeaderItem = new JCheckBoxMenuItem ("Show header");
final JMenuItem showCaretItem = new JCheckBoxMenuItem ("Show caret");
2019-08-15 07:02:40 +00:00
// Assembler menu items
final JMenuItem showAssemblerTargetsItem = new JCheckBoxMenuItem ("Show targets");
final JMenuItem showAssemblerStringsItem = new JCheckBoxMenuItem ("Show strings");
2019-09-04 20:44:43 +00:00
final JMenuItem showAssemblerHeaderItem = new JCheckBoxMenuItem ("Show header");
2019-08-15 07:02:40 +00:00
2019-09-13 10:07:01 +00:00
// Prodos menu items
final JMenuItem prodosSortDirectoriesItem = new JCheckBoxMenuItem ("Sort directories");
2017-01-14 01:40:58 +00:00
ButtonGroup paletteGroup = new ButtonGroup ();
2016-02-21 00:00:57 +00:00
2019-10-12 02:47:21 +00:00
public MenuHandler ()
2015-06-01 09:35:51 +00:00
{
menuBar.add (fileMenu);
menuBar.add (formatMenu);
2017-01-14 01:40:58 +00:00
menuBar.add (colourMenu);
2019-08-08 10:01:56 +00:00
menuBar.add (applesoftMenu);
2019-08-15 07:02:40 +00:00
menuBar.add (assemblerMenu);
2019-09-13 10:07:01 +00:00
menuBar.add (prodosMenu);
2019-10-12 02:47:21 +00:00
// menuBar.add (helpMenu);
2015-06-01 09:35:51 +00:00
fileMenu.add (rootItem);
fileMenu.addSeparator ();
fileMenu.add (refreshTreeItem);
2019-03-05 07:08:34 +00:00
fileMenu.add (saveDiskItem);
2016-03-01 08:51:15 +00:00
2015-06-01 09:35:51 +00:00
addLauncherMenu ();
2016-03-01 08:51:15 +00:00
2015-06-01 09:35:51 +00:00
fileMenu.add (printItem);
fileMenu.addSeparator ();
fileMenu.add (closeTabItem);
JMenuItem fontItem = new JMenuItem (fontAction);
fileMenu.add (fontItem);
2018-07-30 08:44:29 +00:00
fontAction.setSampleText ("120 FOR Z = 14 TO 24:\n VTAB 5:\n HTAB Z:\n"
+ " PRINT AB$:\n FOR TI = 1 TO 50:\n NEXT :\n POKE 0,Z + 40:\n"
+ " POKE 1,9:\n CALL MU:\n VTAB 5:\n HTAB Z:\n"
+ " PRINT SPC(12):\nNEXT :\nVTAB 5:\nHTAB 24:\nPRINT AB$\n");
2015-06-01 09:35:51 +00:00
fileMenu.add (duplicateItem);
2017-01-14 01:40:58 +00:00
fileMenu.add (debuggingItem);
2015-06-01 09:35:51 +00:00
formatMenu.add (lineWrapItem);
formatMenu.add (showCatalogItem);
formatMenu.add (showLayoutItem);
formatMenu.add (showFreeSectorsItem);
2016-03-01 08:51:15 +00:00
2015-06-01 09:35:51 +00:00
formatMenu.addSeparator ();
2016-03-01 08:51:15 +00:00
2015-06-01 09:35:51 +00:00
formatMenu.add (interleave0Item);
formatMenu.add (interleave1Item);
formatMenu.add (interleave2Item);
formatMenu.add (interleave3Item);
2016-03-01 08:51:15 +00:00
2015-06-01 09:35:51 +00:00
formatMenu.addSeparator ();
2016-03-01 08:51:15 +00:00
2015-06-01 09:35:51 +00:00
formatMenu.add (sector256Item);
formatMenu.add (sector512Item);
2016-03-01 08:51:15 +00:00
2017-01-14 01:40:58 +00:00
// set placeholders for the palettes
List<Palette> palettes = HiResImage.getPalettes ();
for (int i = 0; i < palettes.size (); i++)
{
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem ("x");
paletteGroup.add (menuItem);
colourMenu.add (menuItem);
}
2016-03-01 08:51:15 +00:00
2017-01-14 01:40:58 +00:00
colourMenu.addSeparator ();
colourMenu.add (colourQuirksItem);
colourMenu.add (monochromeItem);
colourMenu.addSeparator ();
colourMenu.add (nextPaletteItem);
colourMenu.add (prevPaletteItem);
2015-06-01 09:35:51 +00:00
2019-08-08 10:01:56 +00:00
applesoftMenu.add (splitRemarkItem);
applesoftMenu.add (alignAssignItem);
2019-08-15 07:02:40 +00:00
applesoftMenu.add (showBasicTargetsItem);
2019-08-08 10:12:34 +00:00
applesoftMenu.add (onlyShowTargetLinesItem);
2019-08-08 10:01:56 +00:00
applesoftMenu.add (showHeaderItem);
applesoftMenu.add (showCaretItem);
2019-08-15 07:02:40 +00:00
assemblerMenu.add (showAssemblerTargetsItem);
assemblerMenu.add (showAssemblerStringsItem);
2019-09-04 20:44:43 +00:00
assemblerMenu.add (showAssemblerHeaderItem);
2019-08-15 07:02:40 +00:00
2019-09-13 10:07:01 +00:00
prodosMenu.add (prodosSortDirectoriesItem);
2019-08-08 10:01:56 +00:00
ActionListener basicPreferencesAction = new ActionListener ()
{
@Override
public void actionPerformed (ActionEvent e)
{
setBasicPreferences ();
notifyBasicPreferencesListeners ();
}
};
2019-08-15 07:02:40 +00:00
ActionListener assemblerPreferencesAction = new ActionListener ()
{
@Override
public void actionPerformed (ActionEvent e)
{
setAssemblerPreferences ();
notifyAssemblerPreferencesListeners ();
}
};
2019-09-13 10:07:01 +00:00
ActionListener prodosPreferencesAction = new ActionListener ()
{
@Override
public void actionPerformed (ActionEvent e)
{
setProdosPreferences ();
notifyProdosPreferencesListeners ();
}
};
2019-08-08 10:01:56 +00:00
splitRemarkItem.addActionListener (basicPreferencesAction);
alignAssignItem.addActionListener (basicPreferencesAction);
2019-08-15 07:02:40 +00:00
showBasicTargetsItem.addActionListener (basicPreferencesAction);
2019-08-08 10:12:34 +00:00
onlyShowTargetLinesItem.addActionListener (basicPreferencesAction);
2019-08-08 10:01:56 +00:00
showHeaderItem.addActionListener (basicPreferencesAction);
showCaretItem.addActionListener (basicPreferencesAction);
2019-08-15 07:02:40 +00:00
showAssemblerTargetsItem.addActionListener (assemblerPreferencesAction);
showAssemblerStringsItem.addActionListener (assemblerPreferencesAction);
2019-09-04 20:44:43 +00:00
showAssemblerHeaderItem.addActionListener (assemblerPreferencesAction);
2019-08-15 07:02:40 +00:00
2019-09-13 10:07:01 +00:00
prodosSortDirectoriesItem.addActionListener (prodosPreferencesAction);
2019-10-12 02:47:21 +00:00
// helpMenu.add (new JMenuItem (new EnvironmentAction ()));
2015-06-01 09:35:51 +00:00
sector256Item.setActionCommand ("256");
sector256Item.setAccelerator (KeyStroke.getKeyStroke ("alt 4"));
sector512Item.setActionCommand ("512");
sector512Item.setAccelerator (KeyStroke.getKeyStroke ("alt 5"));
ButtonGroup sectorGroup = new ButtonGroup ();
ButtonGroup interleaveGroup = new ButtonGroup ();
sectorGroup.add (sector256Item);
sectorGroup.add (sector512Item);
interleaveGroup.add (interleave0Item);
interleaveGroup.add (interleave1Item);
interleaveGroup.add (interleave2Item);
interleaveGroup.add (interleave3Item);
2019-03-05 07:08:34 +00:00
saveDiskItem.setAction (saveTempFileAction);
2015-06-01 09:35:51 +00:00
}
2019-08-08 10:01:56 +00:00
private void setBasicPreferences ()
{
basicPreferences.splitRem = splitRemarkItem.isSelected ();
basicPreferences.alignAssign = alignAssignItem.isSelected ();
basicPreferences.showCaret = showCaretItem.isSelected ();
basicPreferences.showHeader = showHeaderItem.isSelected ();
2019-08-15 07:02:40 +00:00
basicPreferences.showTargets = showBasicTargetsItem.isSelected ();
2019-08-08 10:12:34 +00:00
basicPreferences.onlyShowTargetLineNumbers = onlyShowTargetLinesItem.isSelected ();
2019-08-08 10:01:56 +00:00
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);
}
2019-08-15 07:02:40 +00:00
private void setAssemblerPreferences ()
{
assemblerPreferences.showTargets = showAssemblerTargetsItem.isSelected ();
assemblerPreferences.showStrings = showAssemblerStringsItem.isSelected ();
2019-09-04 20:44:43 +00:00
assemblerPreferences.showHeader = showAssemblerHeaderItem.isSelected ();
2019-08-15 07:02:40 +00:00
AssemblerProgram.setAssemblerPreferences (assemblerPreferences);
}
void addAssemblerPreferencesListener (AssemblerPreferencesListener listener)
{
if (!assemblerPreferencesListeners.contains (listener))
{
assemblerPreferencesListeners.add (listener);
listener.setAssemblerPreferences (assemblerPreferences);
}
}
void notifyAssemblerPreferencesListeners ()
{
for (AssemblerPreferencesListener listener : assemblerPreferencesListeners)
listener.setAssemblerPreferences (assemblerPreferences);
}
2019-09-13 10:07:01 +00:00
private void setProdosPreferences ()
{
prodosPreferences.sortDirectories = prodosSortDirectoriesItem.isSelected ();
ProdosDisk.setProdosPreferences (prodosPreferences);
}
void addProdosPreferencesListener (ProdosPreferencesListener listener)
{
if (!prodosPreferencesListeners.contains (listener))
{
prodosPreferencesListeners.add (listener);
listener.setProdosPreferences (prodosPreferences);
}
}
void notifyProdosPreferencesListeners ()
{
for (ProdosPreferencesListener listener : prodosPreferencesListeners)
listener.setProdosPreferences (prodosPreferences);
}
2019-10-12 02:47:21 +00:00
// void addHelpMenuAction (Action action, String functionName)
// {
// helpMenu.add (new JMenuItem (action));
// }
2015-06-01 09:35:51 +00:00
private void addLauncherMenu ()
{
if (!Desktop.isDesktopSupported ())
return;
boolean openSupported = false;
for (Desktop.Action action : Desktop.Action.values ())
if (action.toString ().equals ("OPEN"))
{
openSupported = true;
break;
}
if (!openSupported)
return;
executeDiskItem = new JMenuItem (new ExecuteDiskAction (this));
fileMenu.add (executeDiskItem);
fileMenu.addSeparator ();
}
@Override
public void quit (Preferences prefs)
{
prefs.putBoolean (PREFS_LINE_WRAP, lineWrapItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_LAYOUT, showLayoutItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_CATALOG, showCatalogItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_FREE_SECTORS, showFreeSectorsItem.isSelected ());
2016-02-21 00:00:57 +00:00
prefs.putBoolean (PREFS_COLOUR_QUIRKS, colourQuirksItem.isSelected ());
2016-02-22 10:58:15 +00:00
prefs.putBoolean (PREFS_MONOCHROME, monochromeItem.isSelected ());
2017-01-25 01:38:00 +00:00
// prefs.putBoolean (PREFS_DEBUGGING, debuggingItem.isSelected ());
2017-01-14 01:40:58 +00:00
prefs.putInt (PREFS_PALETTE,
HiResImage.getPaletteFactory ().getCurrentPaletteIndex ());
2018-07-26 03:43:07 +00:00
fontAction.quit (prefs);
2019-08-08 10:01:56 +00:00
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 ());
2019-08-15 07:02:40 +00:00
prefs.putBoolean (PREFS_SHOW_TARGETS, showBasicTargetsItem.isSelected ());
2019-08-08 10:12:34 +00:00
prefs.putBoolean (PREFS_ONLY_SHOW_TARGETS, onlyShowTargetLinesItem.isSelected ());
2019-08-15 07:02:40 +00:00
prefs.putBoolean (PREFS_SHOW_ASSEMBLER_TARGETS,
showAssemblerTargetsItem.isSelected ());
prefs.putBoolean (PREFS_SHOW_ASSEMBLER_STRINGS,
showAssemblerStringsItem.isSelected ());
2019-09-04 20:44:43 +00:00
prefs.putBoolean (PREFS_SHOW_ASSEMBLER_HEADER, showAssemblerHeaderItem.isSelected ());
2019-09-13 10:07:01 +00:00
prefs.putBoolean (PREFS_PRODOS_SORT_DIRECTORIES,
prodosSortDirectoriesItem.isSelected ());
2015-06-01 09:35:51 +00:00
}
2016-03-01 08:51:15 +00:00
@Override
public void restore (Preferences prefs)
{
lineWrapItem.setSelected (prefs.getBoolean (PREFS_LINE_WRAP, true));
showLayoutItem.setSelected (prefs.getBoolean (PREFS_SHOW_LAYOUT, true));
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));
2019-09-04 20:44:43 +00:00
2017-01-25 01:38:00 +00:00
// debuggingItem.setSelected (prefs.getBoolean (PREFS_DEBUGGING, false));
2016-03-14 22:35:22 +00:00
2019-08-08 10:01:56 +00:00
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));
2019-08-15 07:02:40 +00:00
showBasicTargetsItem.setSelected (prefs.getBoolean (PREFS_SHOW_TARGETS, false));
2019-08-08 10:12:34 +00:00
onlyShowTargetLinesItem
.setSelected (prefs.getBoolean (PREFS_ONLY_SHOW_TARGETS, false));
2019-08-08 10:01:56 +00:00
2019-08-15 07:02:40 +00:00
showAssemblerTargetsItem
.setSelected (prefs.getBoolean (PREFS_SHOW_ASSEMBLER_TARGETS, true));
showAssemblerStringsItem
.setSelected (prefs.getBoolean (PREFS_SHOW_ASSEMBLER_STRINGS, true));
2019-09-04 20:44:43 +00:00
showAssemblerHeaderItem
.setSelected (prefs.getBoolean (PREFS_SHOW_ASSEMBLER_HEADER, true));
2019-08-15 07:02:40 +00:00
2019-10-12 02:47:21 +00:00
prodosSortDirectoriesItem
.setSelected (prefs.getBoolean (PREFS_PRODOS_SORT_DIRECTORIES, true));
2019-09-13 10:07:01 +00:00
2019-10-12 02:47:21 +00:00
setBasicPreferences ();
setAssemblerPreferences ();
setProdosPreferences ();
2019-08-08 10:01:56 +00:00
2017-01-14 01:40:58 +00:00
int paletteIndex = prefs.getInt (PREFS_PALETTE, 0);
PaletteFactory paletteFactory = HiResImage.getPaletteFactory ();
paletteFactory.setCurrentPalette (paletteIndex);
Palette palette = paletteFactory.getCurrentPalette ();
Enumeration<AbstractButton> enumeration = paletteGroup.getElements ();
while (enumeration.hasMoreElements ())
{
JCheckBoxMenuItem item = (JCheckBoxMenuItem) enumeration.nextElement ();
if (item.getText ().equals (palette.getName ()))
{
item.setSelected (true);
break;
}
}
2016-03-14 22:35:22 +00:00
HiResImage.setDefaultColourQuirks (colourQuirksItem.isSelected ());
HiResImage.setDefaultMonochrome (monochromeItem.isSelected ());
VisicalcFile.setDefaultDebug (debuggingItem.isSelected ());
2018-07-26 03:43:07 +00:00
fontAction.restore (prefs);
2016-03-01 08:51:15 +00:00
}
2015-06-01 09:35:51 +00:00
@Override
public void diskSelected (DiskSelectedEvent event)
{
currentDisk = event.getFormattedDisk ();
adjustMenus (currentDisk);
}
@Override
public void fileSelected (FileSelectedEvent event)
{
// This can happen if a file is selected from a dual-dos disk
2019-11-14 11:55:30 +00:00
if (event.appleFileSource.getFormattedDisk () != currentDisk)
2015-06-01 09:35:51 +00:00
{
2019-11-14 11:55:30 +00:00
currentDisk = event.appleFileSource.getFormattedDisk ();
2015-06-01 09:35:51 +00:00
adjustMenus (currentDisk);
}
}
private void adjustMenus (final FormattedDisk disk)
{
if (disk != null)
{
sector256Item.setSelected (disk.getDisk ().getBlockSize () == 256);
sector512Item.setSelected (disk.getDisk ().getBlockSize () == 512);
interleave0Item.setSelected (disk.getDisk ().getInterleave () == 0);
interleave1Item.setSelected (disk.getDisk ().getInterleave () == 1);
interleave2Item.setSelected (disk.getDisk ().getInterleave () == 2);
interleave3Item.setSelected (disk.getDisk ().getInterleave () == 3);
}
boolean isDataDisk = (disk instanceof DataDisk);
sector256Item.setEnabled (isDataDisk);
sector512Item.setEnabled (isDataDisk);
interleave0Item.setEnabled (isDataDisk);
interleave1Item.setEnabled (isDataDisk);
interleave2Item.setEnabled (isDataDisk);
interleave3Item.setEnabled (isDataDisk);
if (isDataDisk)
{
// make this an action too
ActionListener sectorListener = new ActionListener ()
{
@Override
public void actionPerformed (ActionEvent e)
{
int size = Integer.parseInt (e.getActionCommand ());
disk.getDisk ().setBlockSize (size);
}
};
sector256Item.addActionListener (sectorListener);
sector512Item.addActionListener (sectorListener);
((InterleaveAction) interleave0Item.getAction ()).setDisk (currentDisk);
((InterleaveAction) interleave1Item.getAction ()).setDisk (currentDisk);
((InterleaveAction) interleave2Item.getAction ()).setDisk (currentDisk);
((InterleaveAction) interleave3Item.getAction ()).setDisk (currentDisk);
}
2019-03-05 07:08:34 +00:00
saveDiskItem.setEnabled (disk.isTempDisk ());
saveTempFileAction.setDisk (disk);
2015-06-01 09:35:51 +00:00
}
}