Cleanup and Bug Fixes
- Fixed a bug that left View menu items checked after the associated windows closed. - Cleaned up UI init code for several components.
This commit is contained in:
1 parent
933b09827a
commit
3636e78435
5 files changed
+67
-69
No files matched your search
@@ -36,9 +36,7 @@ import com.loomcom.symon.ui.Console;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
@@ -170,10 +168,6 @@ public class Simulator implements Observer {
|
|||||||
mainWindow.setResizable(false);
|
mainWindow.setResizable(false);
|
||||||
mainWindow.getContentPane().setLayout(new BorderLayout());
|
mainWindow.getContentPane().setLayout(new BorderLayout());
|
||||||
|
|
||||||
// The Menu
|
|
||||||
menuBar = new SimulatorMenu();
|
|
||||||
mainWindow.setJMenuBar(menuBar);
|
|
||||||
|
|
||||||
// UI components used for I/O.
|
// UI components used for I/O.
|
||||||
this.console = new com.loomcom.symon.ui.Console(80, 25, DEFAULT_FONT);
|
this.console = new com.loomcom.symon.ui.Console(80, 25, DEFAULT_FONT);
|
||||||
this.statusPane = new StatusPanel();
|
this.statusPane = new StatusPanel();
|
||||||
@@ -239,6 +233,11 @@ public class Simulator implements Observer {
|
|||||||
|
|
||||||
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
// The Menu. This comes last, because it relies on other components having
|
||||||
|
// already been initialized.
|
||||||
|
menuBar = new SimulatorMenu();
|
||||||
|
mainWindow.setJMenuBar(menuBar);
|
||||||
|
|
||||||
console.requestFocus();
|
console.requestFocus();
|
||||||
|
|
||||||
mainWindow.pack();
|
mainWindow.pack();
|
||||||
@@ -719,10 +718,24 @@ public class Simulator implements Observer {
|
|||||||
makeFontSizeMenuItem(20, fontSubMenu, fontSizeGroup);
|
makeFontSizeMenuItem(20, fontSubMenu, fontSizeGroup);
|
||||||
viewMenu.add(fontSubMenu);
|
viewMenu.add(fontSubMenu);
|
||||||
|
|
||||||
JRadioButtonMenuItem showTraceLog = new JRadioButtonMenuItem(new ToggleTraceWindowAction());
|
final JCheckBoxMenuItem showTraceLog = new JCheckBoxMenuItem(new ToggleTraceWindowAction());
|
||||||
|
// Un-check the menu item if the user closes the window directly
|
||||||
|
traceLog.addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
showTraceLog.setSelected(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
viewMenu.add(showTraceLog);
|
viewMenu.add(showTraceLog);
|
||||||
|
|
||||||
JRadioButtonMenuItem showMemoryTable = new JRadioButtonMenuItem(new ToggleMemoryWindowAction());
|
final JCheckBoxMenuItem showMemoryTable = new JCheckBoxMenuItem(new ToggleMemoryWindowAction());
|
||||||
|
// Un-check the menu item if the user closes the window directly
|
||||||
|
memoryWindow.addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
showMemoryTable.setSelected(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
viewMenu.add(showMemoryTable);
|
viewMenu.add(showMemoryTable);
|
||||||
|
|
||||||
add(viewMenu);
|
add(viewMenu);
|
||||||
@@ -731,7 +744,7 @@ public class Simulator implements Observer {
|
|||||||
private void makeFontSizeMenuItem(int size, JMenu fontSubMenu, ButtonGroup group) {
|
private void makeFontSizeMenuItem(int size, JMenu fontSubMenu, ButtonGroup group) {
|
||||||
Action action = new SetFontAction(size);
|
Action action = new SetFontAction(size);
|
||||||
|
|
||||||
JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
|
JCheckBoxMenuItem item = new JCheckBoxMenuItem(action);
|
||||||
item.setSelected(size == DEFAULT_FONT_SIZE);
|
item.setSelected(size == DEFAULT_FONT_SIZE);
|
||||||
fontSubMenu.add(item);
|
fontSubMenu.add(item);
|
||||||
group.add(item);
|
group.add(item);
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
|||||||
private JTable memoryTable;
|
private JTable memoryTable;
|
||||||
private JTextField pageNumberTextField;
|
private JTextField pageNumberTextField;
|
||||||
|
|
||||||
private static final Dimension MINIMUM_SIZE = new Dimension(400, 450);
|
private static final Dimension MINIMUM_SIZE = new Dimension(380, 580);
|
||||||
|
|
||||||
public MemoryWindow(Bus bus) {
|
public MemoryWindow(Bus bus) {
|
||||||
this.memoryTableModel = new MemoryTableModel(bus);
|
this.memoryTableModel = new MemoryTableModel(bus);
|
||||||
this.createUi();
|
createUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ public class PreferencesDialog extends Observable implements Preferences {
|
|||||||
|
|
||||||
public PreferencesDialog(Frame parent, boolean modal) {
|
public PreferencesDialog(Frame parent, boolean modal) {
|
||||||
this.dialog = new JDialog(parent, modal);
|
this.dialog = new JDialog(parent, modal);
|
||||||
initComponents();
|
|
||||||
|
createUi();
|
||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ public class PreferencesDialog extends Observable implements Preferences {
|
|||||||
/**
|
/**
|
||||||
* TODO: Validation of input.
|
* TODO: Validation of input.
|
||||||
*/
|
*/
|
||||||
private void initComponents() {
|
private void createUi() {
|
||||||
dialog.setTitle("Preferences");
|
dialog.setTitle("Preferences");
|
||||||
Container contents = dialog.getContentPane();
|
Container contents = dialog.getContentPane();
|
||||||
|
|
||||||
|
|||||||
@@ -34,29 +34,29 @@ import java.awt.*;
|
|||||||
*/
|
*/
|
||||||
public class StatusPanel extends JPanel {
|
public class StatusPanel extends JPanel {
|
||||||
|
|
||||||
private final ImageIcon carryOn;
|
private ImageIcon carryOn;
|
||||||
private final ImageIcon carryOff;
|
private ImageIcon carryOff;
|
||||||
private final ImageIcon zeroOn;
|
private ImageIcon zeroOn;
|
||||||
private final ImageIcon zeroOff;
|
private ImageIcon zeroOff;
|
||||||
private final ImageIcon irqOn;
|
private ImageIcon irqOn;
|
||||||
private final ImageIcon irqOff;
|
private ImageIcon irqOff;
|
||||||
private final ImageIcon decimalOn;
|
private ImageIcon decimalOn;
|
||||||
private final ImageIcon decimalOff;
|
private ImageIcon decimalOff;
|
||||||
private final ImageIcon breakOn;
|
private ImageIcon breakOn;
|
||||||
private final ImageIcon breakOff;
|
private ImageIcon breakOff;
|
||||||
private final ImageIcon overflowOn;
|
private ImageIcon overflowOn;
|
||||||
private final ImageIcon overflowOff;
|
private ImageIcon overflowOff;
|
||||||
private final ImageIcon negativeOn;
|
private ImageIcon negativeOn;
|
||||||
private final ImageIcon negativeOff;
|
private ImageIcon negativeOff;
|
||||||
|
|
||||||
private final JLabel statusFlagsLabel;
|
private JLabel statusFlagsLabel;
|
||||||
private final JLabel carryFlagLabel;
|
private JLabel carryFlagLabel;
|
||||||
private final JLabel zeroFlagLabel;
|
private JLabel zeroFlagLabel;
|
||||||
private final JLabel irqDisableFlagLabel;
|
private JLabel irqDisableFlagLabel;
|
||||||
private final JLabel decimalModeFlagLabel;
|
private JLabel decimalModeFlagLabel;
|
||||||
private final JLabel breakFlagLabel;
|
private JLabel breakFlagLabel;
|
||||||
private final JLabel overflowFlagLabel;
|
private JLabel overflowFlagLabel;
|
||||||
private final JLabel negativeFlagLabel;
|
private JLabel negativeFlagLabel;
|
||||||
|
|
||||||
private JTextField opcodeField;
|
private JTextField opcodeField;
|
||||||
private JTextField pcField;
|
private JTextField pcField;
|
||||||
@@ -65,12 +65,12 @@ public class StatusPanel extends JPanel {
|
|||||||
private JTextField xField;
|
private JTextField xField;
|
||||||
private JTextField yField;
|
private JTextField yField;
|
||||||
|
|
||||||
private final JLabel opcodeLabel;
|
private JLabel opcodeLabel;
|
||||||
private final JLabel pcLabel;
|
private JLabel pcLabel;
|
||||||
private final JLabel spLabel;
|
private JLabel spLabel;
|
||||||
private final JLabel aLabel;
|
private JLabel aLabel;
|
||||||
private final JLabel xLabel;
|
private JLabel xLabel;
|
||||||
private final JLabel yLabel;
|
private JLabel yLabel;
|
||||||
|
|
||||||
private static final int EMPTY_BORDER = 10;
|
private static final int EMPTY_BORDER = 10;
|
||||||
private static final Border LABEL_BORDER = BorderFactory.createEmptyBorder(0, 5, 0, 0);
|
private static final Border LABEL_BORDER = BorderFactory.createEmptyBorder(0, 5, 0, 0);
|
||||||
@@ -80,7 +80,10 @@ public class StatusPanel extends JPanel {
|
|||||||
|
|
||||||
public StatusPanel() {
|
public StatusPanel() {
|
||||||
super();
|
super();
|
||||||
|
createUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUi() {
|
||||||
Border emptyBorder = BorderFactory.createEmptyBorder(EMPTY_BORDER, EMPTY_BORDER,
|
Border emptyBorder = BorderFactory.createEmptyBorder(EMPTY_BORDER, EMPTY_BORDER,
|
||||||
EMPTY_BORDER, EMPTY_BORDER);
|
EMPTY_BORDER, EMPTY_BORDER);
|
||||||
Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
|
Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
|
||||||
|
|||||||
@@ -34,10 +34,9 @@ import java.awt.*;
|
|||||||
* This frame displays a trace of CPU execution. The most recent <code>TRACE_LENGTH</code> lines
|
* This frame displays a trace of CPU execution. The most recent <code>TRACE_LENGTH</code> lines
|
||||||
* are captured in a buffer and rendered to the JFrame's main text area upon request.
|
* are captured in a buffer and rendered to the JFrame's main text area upon request.
|
||||||
*/
|
*/
|
||||||
public class TraceLog {
|
public class TraceLog extends JFrame {
|
||||||
|
|
||||||
private FifoRingBuffer<Cpu.CpuState> traceLog;
|
private FifoRingBuffer<Cpu.CpuState> traceLog;
|
||||||
private JFrame traceLogFrame;
|
|
||||||
private JTextArea traceLogTextArea;
|
private JTextArea traceLogTextArea;
|
||||||
|
|
||||||
private static final Dimension MIN_SIZE = new Dimension(320, 200);
|
private static final Dimension MIN_SIZE = new Dimension(320, 200);
|
||||||
@@ -46,13 +45,12 @@ public class TraceLog {
|
|||||||
|
|
||||||
public TraceLog() {
|
public TraceLog() {
|
||||||
traceLog = new FifoRingBuffer<Cpu.CpuState>(MAX_LOG_LENGTH);
|
traceLog = new FifoRingBuffer<Cpu.CpuState>(MAX_LOG_LENGTH);
|
||||||
traceLogFrame = new JFrame();
|
setMinimumSize(MIN_SIZE);
|
||||||
traceLogFrame.setMinimumSize(MIN_SIZE);
|
setPreferredSize(PREFERRED_SIZE);
|
||||||
traceLogFrame.setPreferredSize(PREFERRED_SIZE);
|
setResizable(true);
|
||||||
traceLogFrame.setResizable(true);
|
setTitle("Trace Log");
|
||||||
traceLogFrame.setTitle("Trace Log");
|
|
||||||
|
|
||||||
traceLogFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||||
|
|
||||||
traceLogTextArea = new JTextArea();
|
traceLogTextArea = new JTextArea();
|
||||||
traceLogTextArea.setFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
|
traceLogTextArea.setFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
|
||||||
@@ -60,9 +58,8 @@ public class TraceLog {
|
|||||||
|
|
||||||
JScrollPane scrollableView = new JScrollPane(traceLogTextArea);
|
JScrollPane scrollableView = new JScrollPane(traceLogTextArea);
|
||||||
|
|
||||||
traceLogFrame.getContentPane().add(scrollableView);
|
getContentPane().add(scrollableView);
|
||||||
traceLogFrame.pack();
|
pack();
|
||||||
// Don't show the frame. That action is controlled by the Simulator.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,20 +107,4 @@ public class TraceLog {
|
|||||||
traceLogTextArea.setEnabled(true);
|
traceLogTextArea.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the Trace Log window is currently visible.
|
|
||||||
* @return ture if the Trace Log window is currently visible.
|
|
||||||
*/
|
|
||||||
public boolean isVisible() {
|
|
||||||
return traceLogFrame.isVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the visibility of the Trace Log window.
|
|
||||||
*
|
|
||||||
* @param b True to make the Trace Log window visible, false to hide it.
|
|
||||||
*/
|
|
||||||
public void setVisible(boolean b) {
|
|
||||||
traceLogFrame.setVisible(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user