180 lines
5.4 KiB
Java
180 lines
5.4 KiB
Java
package app;
|
|
|
|
// Java imports
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import java.util.*;
|
|
import javax.swing.*;
|
|
|
|
// Project imports
|
|
import util.*;
|
|
import vue.*;
|
|
|
|
// CPU window
|
|
class CPUWindow extends ChildWindow {
|
|
|
|
// Instance fields
|
|
private int expandWidth; // Width of expand buttons
|
|
private boolean shown; // Window has been shown
|
|
private int systemHeight; // Initial height of system register list
|
|
|
|
// UI components
|
|
private JPanel dasm; // Disassembler
|
|
private RegisterList lstProgram; // Program register list
|
|
private RegisterList lstSystem; // System register list
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Global Settings //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
static int regExpandWidth; // Width of register list expand button
|
|
static Font regHexFont; // Register list hex font
|
|
static Dimension regHexFontSize; // Max dimensions
|
|
static HashSet<CPUWindow> instances; // Spawned instances
|
|
|
|
// Static initializer
|
|
static {
|
|
setDefaults();
|
|
instances = new HashSet<CPUWindow>();
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Static Methods //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Apply configuration settings to all instances
|
|
static void configureAll() {
|
|
for (var inst : instances)
|
|
inst.configure();
|
|
}
|
|
|
|
// Reset all settings to their default values
|
|
static void setDefaults() {
|
|
|
|
// Register list hex font
|
|
setRegHexFont(new Font(Util.fontFamily(new String[]
|
|
{ "Consolas", Font.MONOSPACED } ), Font.PLAIN, 14));
|
|
|
|
// Width of register list expand button
|
|
var label = new JLabel("+");
|
|
regExpandWidth = label.getPreferredSize().width;
|
|
label.setText("-");
|
|
regExpandWidth = Math.max(regExpandWidth,
|
|
label.getPreferredSize().width);
|
|
}
|
|
|
|
// Specify a font to use as the register list hex font
|
|
static void setRegHexFont(Font font) {
|
|
regHexFont = font;
|
|
regHexFontSize = measureHex(font);
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Constructors //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Default constructor
|
|
CPUWindow(MainWindow parent) {
|
|
super(parent, "cpu.title");
|
|
instances.add(this);
|
|
|
|
var client = getContentPane();
|
|
|
|
dasm = new JPanel(null);
|
|
dasm.setBackground(SystemColor.window);
|
|
dasm.setFocusable(true);
|
|
|
|
lstSystem = new RegisterList(this, true);
|
|
lstProgram = new RegisterList(this, false);
|
|
var inner = Util.splitPane(JSplitPane.VERTICAL_SPLIT);
|
|
inner.setTopComponent(lstSystem);
|
|
inner.setBottomComponent(lstProgram);
|
|
|
|
var outer = Util.splitPane(JSplitPane.HORIZONTAL_SPLIT);
|
|
outer.setLeftComponent(new JScrollPane(dasm,
|
|
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
|
|
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
|
outer.setRightComponent(inner);
|
|
outer.setResizeWeight(1);
|
|
|
|
client.add(outer);
|
|
client.setPreferredSize(new Dimension(480, 300));
|
|
configure();
|
|
pack();
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Public Methods //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// The window is closing
|
|
public void dispose() {
|
|
instances.remove(this);
|
|
super.dispose();
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Package Methods //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Apply configuration settings
|
|
void configure() {
|
|
lstProgram.configure();
|
|
lstSystem .configure();
|
|
}
|
|
|
|
// Update the display
|
|
void refresh() {
|
|
lstSystem.refresh();
|
|
lstProgram.refresh();
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Event Handlers //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Client resize
|
|
private void onResize() {
|
|
//refreshDasm();
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// Private Methods //
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Determine the maximum character width of a hex character in a font
|
|
private static Dimension measureHex(Font font) {
|
|
int ret = 0;
|
|
Dimension size = null;
|
|
|
|
// Process all digits
|
|
var label = new JLabel();
|
|
label.setFont(font);
|
|
for (int x = 0; x < 16; x++) {
|
|
label.setText(String.format(
|
|
"%" + (Disassembler.hexCaps ? "X" : "x"
|
|
), x));
|
|
size = label.getPreferredSize();
|
|
ret = Math.max(ret, size.width);
|
|
}
|
|
|
|
return new Dimension(ret, size.height);
|
|
}
|
|
|
|
|
|
|
|
}
|