Address IntelliJ warnings

This commit addresses a large number of IntelliJ warnings
that have been left hanging around for far too long.
This commit is contained in:
Seth Morabito committed 2025-02-13 16:05:42 -08:00
1 parent ecd4bbbd9a
commit c317544e7b
28 files changed
+222 -408

No files matched your search

@@ -30,10 +30,7 @@ import org.slf4j.LoggerFactory;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
@@ -46,8 +43,8 @@ public class BreakpointsWindow extends JFrame {
private static final Dimension FRAME_SIZE = new Dimension(240, 280);
private static final String EMPTY_STRING = "";
private JFrame mainWindow;
private Breakpoints breakpoints;
private final JFrame mainWindow;
private final Breakpoints breakpoints;
public BreakpointsWindow(Breakpoints breakpoints,
JFrame mainWindow) {
@@ -75,16 +72,7 @@ public class BreakpointsWindow extends JFrame {
breakpointsTable.setShowGrid(true);
breakpointsTable.setGridColor(Color.LIGHT_GRAY);
breakpointsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
breakpointsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getFirstIndex() > -1) {
removeButton.setEnabled(true);
} else {
removeButton.setEnabled(false);
}
}
});
breakpointsTable.getSelectionModel().addListSelectionListener(e -> removeButton.setEnabled(e.getFirstIndex() > -1));
JScrollPane scrollPane = new JScrollPane(breakpointsTable);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
@@ -92,45 +80,33 @@ public class BreakpointsWindow extends JFrame {
breakpointsPanel.add(scrollPane, BorderLayout.CENTER);
ActionListener addBreakpointListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int value;
ActionListener addBreakpointListener = e -> {
int value;
String newBreakpoint = addTextField.getText();
String newBreakpoint = addTextField.getText();
if (newBreakpoint == null || newBreakpoint.isEmpty()) {
return;
}
try {
value = (Integer.parseInt(addTextField.getText(), 16) & 0xffff);
} catch (NumberFormatException ex) {
logger.warn("Can't parse page number {}", newBreakpoint);
return;
}
if (value < 0) {
return;
}
breakpoints.addBreakpoint(value);
logger.debug("Added breakpoint ${}", Utils.wordToHex(value));
addTextField.setText(EMPTY_STRING);
if (newBreakpoint == null || newBreakpoint.isEmpty()) {
return;
}
try {
value = (Integer.parseInt(addTextField.getText(), 16) & 0xffff);
} catch (NumberFormatException ex) {
logger.warn("Can't parse page number {}", newBreakpoint);
return;
}
breakpoints.addBreakpoint(value);
logger.debug("Added breakpoint ${}", Utils.wordToHex(value));
addTextField.setText(EMPTY_STRING);
};
addButton.addActionListener(addBreakpointListener);
addTextField.addActionListener(addBreakpointListener);
removeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
breakpoints.removeBreakpointAtIndex(breakpointsTable.getSelectedRow());
}
});
removeButton.addActionListener(e -> breakpoints.removeBreakpointAtIndex(breakpointsTable.getSelectedRow()));
controlPanel.add(addTextField);
controlPanel.add(addButton);
@@ -51,8 +51,8 @@ public class Console extends JTerminal implements KeyListener, MouseListener {
private static final boolean SWAP_CR_AND_LF = true;
// If true, send CRLF (0x0d 0x0a) whenever CR is typed
private boolean sendCrForLf;
private FifoRingBuffer<Character> typeAheadBuffer;
private final boolean sendCrForLf;
private final FifoRingBuffer<Character> typeAheadBuffer;
public Console(int columns, int rows, Font font, boolean sendCrForLf) {
super(new Vt100TerminalModel(columns, rows), font);
@@ -49,7 +49,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
private static final Logger logger = LoggerFactory.getLogger(MemoryWindow.class);
private MemoryTableModel memoryTableModel;
private final MemoryTableModel memoryTableModel;
private JTable memoryTable;
private JTextField pageNumberTextField;
private JButton previousPageButton;
@@ -111,7 +111,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
}
/**
* Set-up the UI.
* Set up the UI.
*/
private void createUi() {
setTitle("Memory Contents");
@@ -230,7 +230,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
* A JTable that will automatically select all text in a cell
* being edited.
*/
private class MemoryTable extends JTable {
private static class MemoryTable extends JTable {
public MemoryTable(TableModel tableModel) {
super(tableModel);
@@ -242,7 +242,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
final Component editor = getEditorComponent();
if (editor != null && editor instanceof JTextComponent) {
if (editor instanceof JTextComponent) {
((JTextComponent) editor).selectAll();
}
@@ -250,7 +250,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
}
}
private class MemoryTableCellRenderer extends DefaultTableCellRenderer {
private static class MemoryTableCellRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
@@ -272,9 +272,9 @@ public class MemoryWindow extends JFrame implements ActionListener {
/**
* The model that backs the Memory Table.
*/
private class MemoryTableModel extends AbstractTableModel {
private static class MemoryTableModel extends AbstractTableModel {
private Bus bus;
private final Bus bus;
private int pageNumber;
private static final int COLUMN_COUNT = 17;
@@ -64,12 +64,13 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
private static final long WINDOW_REPAINT_INTERVAL = 66; // 30fps rate
private static final int CHAR_WIDTH = 8;
private static final int CHAR_HEIGHT = 8;
private static final String ASCII_ROM = "/ascii.rom";
private final int scaleX, scaleY;
private final boolean shouldScale;
private BufferedImage image;
private int[] charRom;
private final int[] charRom;
private int horizontalDisplayed;
private int verticalDisplayed;
@@ -78,9 +79,9 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
private boolean hideCursor;
private Dimension dimensions;
private Crtc crtc;
private final Crtc crtc;
private ScheduledExecutorService scheduler;
private final ScheduledExecutorService scheduler;
private ScheduledFuture<?> cursorBlinker;
/**
@@ -123,12 +124,9 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
*/
private class CursorBlinker implements Runnable {
public void run() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (cursorBlinkRate > 0) {
hideCursor = !hideCursor;
}
SwingUtilities.invokeLater(() -> {
if (cursorBlinkRate > 0) {
hideCursor = !hideCursor;
}
});
}
@@ -136,12 +134,9 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
private class WindowPainter implements Runnable {
public void run() {
SwingUtilities.invokeLater(new Runnable () {
@Override
public void run() {
if (VideoWindow.this.isVisible()) {
VideoWindow.this.repaint();
}
SwingUtilities.invokeLater(() -> {
if (VideoWindow.this.isVisible()) {
VideoWindow.this.repaint();
}
});
}
@@ -152,7 +147,7 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
this.scheduler = Executors.newSingleThreadScheduledExecutor();
this.crtc = crtc;
this.charRom = loadCharRom("/ascii.rom");
this.charRom = loadCharRom();
this.scaleX = scaleX;
this.scaleY = scaleY;
this.shouldScale = (scaleX > 1 || scaleY > 1);
@@ -292,14 +287,17 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
* Since the BufferedImage is a TYPE_BYTE_BINARY, the data must be converted
* into a single byte per pixel, 0 for black and 255 for white.
* @param resource The ROM file resource to load.
* @return An array of glyphs, each ready for insertion.
* @throws IOException
* @throws IOException Failure to load character ROM.
*/
private int[] loadCharRom(String resource) throws IOException {
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(this.getClass().getResourceAsStream(resource));
private int[] loadCharRom() throws IOException {
var resource = this.getClass().getResourceAsStream(ASCII_ROM);
if (resource == null) {
throw new IOException("Resource " + ASCII_ROM + " not found");
}
try (BufferedInputStream bis = new BufferedInputStream(resource)) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while (bis.available() > 0) {
bos.write(bis.read());
@@ -314,7 +312,7 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
int[] converted = new int[raw.length * CHAR_WIDTH];
int romIndex = 0;
for (int i = 0; i < converted.length;) {
for (int i = 0; i < converted.length; ) {
byte charRow = raw[romIndex++];
for (int j = 7; j >= 0; j--) {
@@ -322,10 +320,6 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
}
}
return converted;
} finally {
if (bis != null) {
bis.close();
}
}
}
}