mirror of
https://codeberg.org/sethm/symon.git
synced 2026-11-09 03:22:24 +00:00
Make PC editable
This commit is contained in:
1 parent
eac387e472
commit
1a1d503abe
1 file changed
+25
-2
@@ -32,6 +32,7 @@ import javax.swing.border.EtchedBorder;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UI component that displays the current state of the simulated CPU.
|
* UI component that displays the current state of the simulated CPU.
|
||||||
@@ -164,12 +165,30 @@ public class StatusPanel extends JPanel {
|
|||||||
spLabel.setToolTipText("Stack Pointer");
|
spLabel.setToolTipText("Stack Pointer");
|
||||||
|
|
||||||
opcodeField = makeTextField(LARGE_TEXT_FIELD_SIZE);
|
opcodeField = makeTextField(LARGE_TEXT_FIELD_SIZE);
|
||||||
pcField = makeTextField(LARGE_TEXT_FIELD_SIZE);
|
pcField = makeTextField(LARGE_TEXT_FIELD_SIZE, true);
|
||||||
spField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
spField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||||
aField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
aField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||||
xField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
xField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||||
yField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
yField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||||
|
|
||||||
|
// Make fields editable
|
||||||
|
pcField.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (e.getSource() == pcField) {
|
||||||
|
try {
|
||||||
|
String newPcString = pcField.getText().replaceAll("[^0-9a-fA-F]", "");
|
||||||
|
int newPc = Integer.parseInt(newPcString, 16);
|
||||||
|
machine.getCpu().setProgramCounter(newPc);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// Swallow exception, we don't care.
|
||||||
|
}
|
||||||
|
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
constraints.anchor = GridBagConstraints.LINE_START;
|
constraints.anchor = GridBagConstraints.LINE_START;
|
||||||
constraints.gridwidth = 2;
|
constraints.gridwidth = 2;
|
||||||
constraints.gridx = 0;
|
constraints.gridx = 0;
|
||||||
@@ -319,9 +338,13 @@ public class StatusPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JTextField makeTextField(Dimension size) {
|
private JTextField makeTextField(Dimension size) {
|
||||||
|
return makeTextField(size, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JTextField makeTextField(Dimension size, boolean editable) {
|
||||||
JTextField textField = new JTextField("");
|
JTextField textField = new JTextField("");
|
||||||
textField.setAlignmentX(LEFT_ALIGNMENT);
|
textField.setAlignmentX(LEFT_ALIGNMENT);
|
||||||
textField.setEditable(false);
|
textField.setEditable(editable);
|
||||||
textField.setMinimumSize(size);
|
textField.setMinimumSize(size);
|
||||||
textField.setMaximumSize(size);
|
textField.setMaximumSize(size);
|
||||||
textField.setPreferredSize(size);
|
textField.setPreferredSize(size);
|
||||||
|
|||||||
Reference in new issue
Block a user