Refactor for Java 1.8
- Clean up and refactor code - Add 1.8 features - Clean up IntelliJ inspector warnings
This commit is contained in:
1 parent
a4a110dcef
commit
6e8fd40014
28 files changed
+366
-503
No files matched your search
@@ -44,21 +44,20 @@ import java.awt.event.MouseListener;
|
||||
|
||||
public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
|
||||
private static final int DEFAULT_COLUMNS = 80;
|
||||
private static final int DEFAULT_ROWS = 24;
|
||||
private static final int DEFAULT_BORDER_WIDTH = 10;
|
||||
// If true, swap CR and LF characters.
|
||||
private static final boolean SWAP_CR_AND_LF = true;
|
||||
// If true, send CRLF (0x0d 0x0a) whenever CR is typed
|
||||
private static final boolean SEND_CR_LF_FOR_CR = false;
|
||||
|
||||
// If true, send CRLF (0x0d 0x0a) whenever CR is typed
|
||||
private boolean sendCrForLf = false;
|
||||
private FifoRingBuffer<Character> typeAheadBuffer;
|
||||
|
||||
public Console(int columns, int rows, Font font) {
|
||||
public Console(int columns, int rows, Font font, boolean sendCrForLf) {
|
||||
super(new Vt100TerminalModel(columns, rows), font);
|
||||
// A small type-ahead buffer, as might be found in any real
|
||||
// VT100-style serial terminal.
|
||||
this.typeAheadBuffer = new FifoRingBuffer<Character>(128);
|
||||
this.typeAheadBuffer = new FifoRingBuffer<>(128);
|
||||
this.sendCrForLf = sendCrForLf;
|
||||
setBorderWidth(DEFAULT_BORDER_WIDTH);
|
||||
addKeyListener(this);
|
||||
addMouseListener(this);
|
||||
@@ -83,7 +82,7 @@ public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
/**
|
||||
* Returns true if a key has been pressed since the last time input was read.
|
||||
*
|
||||
* @return
|
||||
* @return true if the type-ahead buffer has data
|
||||
*/
|
||||
public boolean hasInput() {
|
||||
return !typeAheadBuffer.isEmpty();
|
||||
@@ -105,7 +104,7 @@ public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
}
|
||||
}
|
||||
|
||||
if (SEND_CR_LF_FOR_CR && keyTyped == 0x0d) {
|
||||
if (sendCrForLf && keyTyped == 0x0d) {
|
||||
typeAheadBuffer.push((char) 0x0d);
|
||||
typeAheadBuffer.push((char) 0x0a);
|
||||
} else {
|
||||
|
||||
@@ -346,12 +346,8 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
int fullAddress = fullAddress(row, column);
|
||||
int newValue = Integer.parseInt(hexValue, 16) & 0xff;
|
||||
bus.write(fullAddress, newValue);
|
||||
} catch (MemoryAccessException ex) {
|
||||
;
|
||||
} catch (NumberFormatException ex) {
|
||||
;
|
||||
} catch (ClassCastException ex) {
|
||||
;
|
||||
} catch (MemoryAccessException | NumberFormatException | ClassCastException ex) {
|
||||
// Intentionally swallow exception
|
||||
}
|
||||
fireTableCellUpdated(row, column);
|
||||
}
|
||||
|
||||
@@ -97,23 +97,19 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
JButton applyButton = new JButton("Apply");
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
updateUi();
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
cancelButton.addActionListener(actionEvent -> {
|
||||
updateUi();
|
||||
dialog.setVisible(false);
|
||||
});
|
||||
|
||||
applyButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
haltOnBreak = haltOnBreakCheckBox.isSelected();
|
||||
programLoadAddress = hexToInt(programLoadAddressField.getText());
|
||||
updateUi();
|
||||
// TODO: Actually check to see if values have changed, don't assume.
|
||||
setChanged();
|
||||
PreferencesDialog.this.notifyObservers();
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
applyButton.addActionListener(actionEvent -> {
|
||||
haltOnBreak = haltOnBreakCheckBox.isSelected();
|
||||
programLoadAddress = hexToInt(programLoadAddressField.getText());
|
||||
updateUi();
|
||||
// TODO: Actually check to see if values have changed, don't assume.
|
||||
setChanged();
|
||||
PreferencesDialog.this.notifyObservers();
|
||||
dialog.setVisible(false);
|
||||
});
|
||||
|
||||
buttonsContainer.add(applyButton);
|
||||
|
||||
@@ -53,7 +53,6 @@ public class StatusPanel extends JPanel {
|
||||
private ImageIcon negativeOn;
|
||||
private ImageIcon negativeOff;
|
||||
|
||||
private JLabel statusFlagsLabel;
|
||||
private JLabel carryFlagLabel;
|
||||
private JLabel zeroFlagLabel;
|
||||
private JLabel irqDisableFlagLabel;
|
||||
@@ -69,13 +68,6 @@ public class StatusPanel extends JPanel {
|
||||
private JTextField xField;
|
||||
private JTextField yField;
|
||||
|
||||
private JLabel opcodeLabel;
|
||||
private JLabel pcLabel;
|
||||
private JLabel spLabel;
|
||||
private JLabel aLabel;
|
||||
private JLabel xLabel;
|
||||
private JLabel yLabel;
|
||||
|
||||
private Machine machine;
|
||||
|
||||
private static final int EMPTY_BORDER = 10;
|
||||
@@ -150,13 +142,13 @@ public class StatusPanel extends JPanel {
|
||||
statusFlagsPanel.add(carryFlagLabel);
|
||||
|
||||
// Create and add register and address labels
|
||||
statusFlagsLabel = makeLabel("Flags");
|
||||
opcodeLabel = makeLabel("Next IR");
|
||||
pcLabel = makeLabel("PC");
|
||||
spLabel = makeLabel("SP");
|
||||
aLabel = makeLabel("A");
|
||||
xLabel = makeLabel("X");
|
||||
yLabel = makeLabel("Y");
|
||||
JLabel statusFlagsLabel = makeLabel("Flags");
|
||||
JLabel opcodeLabel = makeLabel("Next IR");
|
||||
JLabel pcLabel = makeLabel("PC");
|
||||
JLabel spLabel = makeLabel("SP");
|
||||
JLabel aLabel = makeLabel("A");
|
||||
JLabel xLabel = makeLabel("X");
|
||||
JLabel yLabel = makeLabel("Y");
|
||||
|
||||
statusFlagsLabel.setToolTipText("6502 Processor Status Flags");
|
||||
opcodeLabel.setToolTipText("Instruction Register");
|
||||
@@ -171,74 +163,59 @@ public class StatusPanel extends JPanel {
|
||||
yField = makeTextField(SMALL_TEXT_FIELD_SIZE, true);
|
||||
|
||||
// Make fields editable
|
||||
pcField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = getHexVal(pcField) & 0xffff;
|
||||
machine.getCpu().setProgramCounter(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
pcField.addActionListener(e -> {
|
||||
try {
|
||||
int newVal = getHexVal(pcField) & 0xffff;
|
||||
machine.getCpu().setProgramCounter(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
});
|
||||
|
||||
spField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = getHexVal(spField) & 0xff;
|
||||
machine.getCpu().setStackPointer(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
spField.addActionListener(e -> {
|
||||
try {
|
||||
int newVal = getHexVal(spField) & 0xff;
|
||||
machine.getCpu().setStackPointer(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
});
|
||||
|
||||
aField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = getHexVal(aField) & 0xff;
|
||||
machine.getCpu().setAccumulator(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
aField.addActionListener(e -> {
|
||||
try {
|
||||
int newVal = getHexVal(aField) & 0xff;
|
||||
machine.getCpu().setAccumulator(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
});
|
||||
|
||||
xField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = getHexVal(xField) & 0xff;
|
||||
machine.getCpu().setXRegister(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
xField.addActionListener(e -> {
|
||||
try {
|
||||
int newVal = getHexVal(xField) & 0xff;
|
||||
machine.getCpu().setXRegister(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
});
|
||||
|
||||
yField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = getHexVal(yField) & 0xff;
|
||||
machine.getCpu().setYRegister(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
yField.addActionListener(e -> {
|
||||
try {
|
||||
int newVal = getHexVal(yField) & 0xff;
|
||||
machine.getCpu().setYRegister(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
updateState();
|
||||
});
|
||||
|
||||
constraints.anchor = GridBagConstraints.LINE_START;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TraceLog extends JFrame {
|
||||
private static final int MAX_LOG_LENGTH = 50000;
|
||||
|
||||
public TraceLog() {
|
||||
traceLog = new FifoRingBuffer<Cpu.CpuState>(MAX_LOG_LENGTH);
|
||||
traceLog = new FifoRingBuffer<>(MAX_LOG_LENGTH);
|
||||
setMinimumSize(MIN_SIZE);
|
||||
setPreferredSize(PREFERRED_SIZE);
|
||||
setResizable(true);
|
||||
|
||||
@@ -122,12 +122,10 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
*/
|
||||
private class CursorBlinker implements Runnable {
|
||||
public void run() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (cursorBlinkRate > 0) {
|
||||
hideCursor = !hideCursor;
|
||||
repaint();
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (cursorBlinkRate > 0) {
|
||||
hideCursor = !hideCursor;
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user