From 66c52c8826dfcf8a6ba395fe9a672bdb1be4ed65 Mon Sep 17 00:00:00 2001 From: Seth Morabito Date: Fri, 8 Jan 2016 19:11:42 -0800 Subject: [PATCH] Revert Java 1.8 changes. Buildable with Java 1.7 There are still active users on Java 1.7, so building with Java 8 was a no-no. This change reverts the recent migration to Java 8, allowing JDK 1.7 to compile the code. This means, at least for the time being, no more Lambda expressions (Boooooooooooooooo!!) --- pom.xml | 6 +- src/main/java/com/loomcom/symon/Bus.java | 6 +- src/main/java/com/loomcom/symon/Main.java | 17 ++- .../java/com/loomcom/symon/Simulator.java | 130 +++++++++++------- .../com/loomcom/symon/devices/Device.java | 8 +- .../loomcom/symon/ui/BreakpointsWindow.java | 78 ++++++----- .../loomcom/symon/ui/PreferencesDialog.java | 28 ++-- .../com/loomcom/symon/ui/StatusPanel.java | 97 +++++++------ .../com/loomcom/symon/ui/VideoWindow.java | 11 +- 9 files changed, 232 insertions(+), 149 deletions(-) diff --git a/pom.xml b/pom.xml index 2b358be..edb5b5b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.loomcom.symon symon jar - 1.2.0 + 1.2.1 symon http://www.loomcom.com/symon @@ -91,8 +91,8 @@ 3.1 -Xlint:unchecked - 1.8 - 1.8 + 1.7 + 1.7 diff --git a/src/main/java/com/loomcom/symon/Bus.java b/src/main/java/com/loomcom/symon/Bus.java index 8fa2c89..bc922b6 100644 --- a/src/main/java/com/loomcom/symon/Bus.java +++ b/src/main/java/com/loomcom/symon/Bus.java @@ -222,9 +222,11 @@ public class Bus { List priorities = new ArrayList<>(deviceMap.keySet()); Collections.sort(priorities); - for(int priority : priorities) { + for (int priority : priorities) { SortedSet deviceSet = deviceMap.get(priority); - devices.addAll(deviceSet.stream().collect(Collectors.toList())); + for (Device device : deviceSet) { + devices.add(device); + } } return devices; diff --git a/src/main/java/com/loomcom/symon/Main.java b/src/main/java/com/loomcom/symon/Main.java index 5e4d8ff..253f887 100644 --- a/src/main/java/com/loomcom/symon/Main.java +++ b/src/main/java/com/loomcom/symon/Main.java @@ -86,13 +86,16 @@ public class Main { final Simulator simulator = new Simulator(machineClass); - SwingUtilities.invokeLater(() -> { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - // Create the main UI window - simulator.createAndShowUi(); - } catch (Exception e) { - e.printStackTrace(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + // Create the main UI window + simulator.createAndShowUi(); + } catch (Exception e) { + e.printStackTrace(); + } } }); diff --git a/src/main/java/com/loomcom/symon/Simulator.java b/src/main/java/com/loomcom/symon/Simulator.java index 5366577..2e1f6d3 100644 --- a/src/main/java/com/loomcom/symon/Simulator.java +++ b/src/main/java/com/loomcom/symon/Simulator.java @@ -185,13 +185,16 @@ public class Simulator { JButton hardResetButton = new JButton("Hard Reset"); stepCountBox = new JComboBox<>(STEPS); - stepCountBox.addActionListener(actionEvent -> { - try { - JComboBox cb = (JComboBox) actionEvent.getSource(); - stepsPerClick = Integer.parseInt((String) cb.getSelectedItem()); - } catch (NumberFormatException ex) { - stepsPerClick = 1; - stepCountBox.setSelectedIndex(0); + stepCountBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + try { + JComboBox cb = (JComboBox) actionEvent.getSource(); + stepsPerClick = Integer.parseInt((String) cb.getSelectedItem()); + } catch (NumberFormatException ex) { + stepsPerClick = 1; + stepCountBox.setSelectedIndex(0); + } } }); @@ -211,24 +214,38 @@ public class Simulator { // Bottom - buttons. mainWindow.getContentPane().add(buttonContainer, BorderLayout.PAGE_END); - runStopButton.addActionListener(actionEvent -> { - if (runLoop != null && runLoop.isRunning()) { - handleStop(); - } else { - handleStart(); + runStopButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (runLoop != null && runLoop.isRunning()) { + Simulator.this.handleStop(); + } else { + Simulator.this.handleStart(); + } } }); - stepButton.addActionListener(actionEvent -> handleStep(stepsPerClick)); - - softResetButton.addActionListener(actionEvent -> { - // If this was a CTRL-click, do a hard reset. - handleReset(false); + stepButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + Simulator.this.handleStep(stepsPerClick); + } }); - hardResetButton.addActionListener(actionEvent -> { - // If this was a CTRL-click, do a hard reset. - handleReset(true); + softResetButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + // If this was a CTRL-click, do a hard reset. + Simulator.this.handleReset(false); + } + }); + + hardResetButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + // If this was a CTRL-click, do a hard reset. + Simulator.this.handleReset(true); + } }); mainWindow.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); @@ -400,13 +417,16 @@ public class Simulator { logger.debug("Starting main run loop."); isRunning = true; - SwingUtilities.invokeLater(() -> { - // Don't allow step while the simulator is running - stepButton.setEnabled(false); - stepCountBox.setEnabled(false); - menuBar.simulatorDidStart(); - // Toggle the state of the run button - runStopButton.setText("Stop"); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + // Don't allow step while the simulator is running + stepButton.setEnabled(false); + stepCountBox.setEnabled(false); + menuBar.simulatorDidStart(); + // Toggle the state of the run button + runStopButton.setText("Stop"); + } }); try { @@ -417,17 +437,20 @@ public class Simulator { logger.error("Exception in main simulator run thread. Exiting run.", ex); } - SwingUtilities.invokeLater(() -> { - statusPane.updateState(); - memoryWindow.updateState(); - runStopButton.setText("Run"); - stepButton.setEnabled(true); - stepCountBox.setEnabled(true); - if (traceLog.isVisible()) { - traceLog.refresh(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + statusPane.updateState(); + memoryWindow.updateState(); + runStopButton.setText("Run"); + stepButton.setEnabled(true); + stepCountBox.setEnabled(true); + if (traceLog.isVisible()) { + traceLog.refresh(); + } + menuBar.simulatorDidStop(); + traceLog.simulatorDidStop(); } - menuBar.simulatorDidStop(); - traceLog.simulatorDidStop(); }); isRunning = false; @@ -480,9 +503,12 @@ public class Simulator { // Now load the program at the starting address. loadProgram(program, preferences.getProgramStartAddress()); - SwingUtilities.invokeLater(() -> { - console.reset(); - breakpoints.refresh(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + console.reset(); + breakpoints.refresh(); + } }); // TODO: "Don't Show Again" checkbox @@ -623,9 +649,12 @@ public class Simulator { } public void actionPerformed(ActionEvent actionEvent) { - SwingUtilities.invokeLater(() -> { - console.setFont(new Font("Monospaced", Font.PLAIN, size)); - mainWindow.pack(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + console.setFont(new Font("Monospaced", Font.PLAIN, size)); + mainWindow.pack(); + } }); } } @@ -889,12 +918,15 @@ public class Simulator { private void updateVisibleState() { // Immediately update the UI. - SwingUtilities.invokeLater(() -> { - // Now update the state - statusPane.updateState(); - memoryWindow.updateState(); - if (traceLog.shouldUpdate()) { - traceLog.refresh(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + // Now update the state + statusPane.updateState(); + memoryWindow.updateState(); + if (traceLog.shouldUpdate()) { + traceLog.refresh(); + } } }); } diff --git a/src/main/java/com/loomcom/symon/devices/Device.java b/src/main/java/com/loomcom/symon/devices/Device.java index 30aff56..fb5b33d 100644 --- a/src/main/java/com/loomcom/symon/devices/Device.java +++ b/src/main/java/com/loomcom/symon/devices/Device.java @@ -30,6 +30,7 @@ import com.loomcom.symon.exceptions.MemoryRangeException; import java.util.HashSet; import java.util.Set; +import java.util.function.Consumer; /** * A memory-mapped IO Device. @@ -115,7 +116,12 @@ public abstract class Device implements Comparable { } public void notifyListeners() { - deviceChangeListeners.forEach(DeviceChangeListener::deviceStateChanged); + deviceChangeListeners.forEach(new Consumer() { + @Override + public void accept(DeviceChangeListener deviceChangeListener) { + deviceChangeListener.deviceStateChanged(); + } + }); } /** diff --git a/src/main/java/com/loomcom/symon/ui/BreakpointsWindow.java b/src/main/java/com/loomcom/symon/ui/BreakpointsWindow.java index 7bbab76..3f7bf1c 100644 --- a/src/main/java/com/loomcom/symon/ui/BreakpointsWindow.java +++ b/src/main/java/com/loomcom/symon/ui/BreakpointsWindow.java @@ -30,7 +30,10 @@ 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; /** @@ -62,21 +65,24 @@ public class BreakpointsWindow extends JFrame { breakpointsPanel.setLayout(new BorderLayout()); breakpointsPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); - JButton addButton = new JButton("Add"); - JButton removeButton = new JButton("Del"); + final JButton addButton = new JButton("Add"); + final JButton removeButton = new JButton("Del"); removeButton.setEnabled(false); - JTextField addTextField = new JTextField(4); + final JTextField addTextField = new JTextField(4); - JTable breakpointsTable = new JTable(breakpoints); + final JTable breakpointsTable = new JTable(breakpoints); breakpointsTable.setShowGrid(true); breakpointsTable.setGridColor(Color.LIGHT_GRAY); breakpointsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - breakpointsTable.getSelectionModel().addListSelectionListener(e -> { - if (e.getFirstIndex() > -1) { - removeButton.setEnabled(true); - } else { - removeButton.setEnabled(false); + breakpointsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (e.getFirstIndex() > -1) { + removeButton.setEnabled(true); + } else { + removeButton.setEnabled(false); + } } }); @@ -86,37 +92,45 @@ public class BreakpointsWindow extends JFrame { breakpointsPanel.add(scrollPane, BorderLayout.CENTER); - ActionListener addBreakpointListener = e -> { - int value = -1; + ActionListener addBreakpointListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int value; - String newBreakpoint = addTextField.getText(); + String newBreakpoint = addTextField.getText(); - if (newBreakpoint == null || newBreakpoint.isEmpty()) { - return; + 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); } - - 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); }; addButton.addActionListener(addBreakpointListener); addTextField.addActionListener(addBreakpointListener); - removeButton.addActionListener(e -> breakpoints.removeBreakpointAtIndex(breakpointsTable.getSelectedRow())); + removeButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + breakpoints.removeBreakpointAtIndex(breakpointsTable.getSelectedRow()); + } + }); controlPanel.add(addTextField); controlPanel.add(addButton); diff --git a/src/main/java/com/loomcom/symon/ui/PreferencesDialog.java b/src/main/java/com/loomcom/symon/ui/PreferencesDialog.java index 454bc1e..1b188a4 100644 --- a/src/main/java/com/loomcom/symon/ui/PreferencesDialog.java +++ b/src/main/java/com/loomcom/symon/ui/PreferencesDialog.java @@ -97,19 +97,25 @@ public class PreferencesDialog extends Observable implements Preferences { JButton applyButton = new JButton("Apply"); JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(actionEvent -> { - updateUi(); - dialog.setVisible(false); + cancelButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + PreferencesDialog.this.updateUi(); + 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); + applyButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + haltOnBreak = haltOnBreakCheckBox.isSelected(); + programLoadAddress = PreferencesDialog.this.hexToInt(programLoadAddressField.getText()); + PreferencesDialog.this.updateUi(); + // TODO: Actually check to see if values have changed, don't assume. + PreferencesDialog.this.setChanged(); + PreferencesDialog.this.notifyObservers(); + dialog.setVisible(false); + } }); buttonsContainer.add(applyButton); diff --git a/src/main/java/com/loomcom/symon/ui/StatusPanel.java b/src/main/java/com/loomcom/symon/ui/StatusPanel.java index a3cd793..cd4b75f 100644 --- a/src/main/java/com/loomcom/symon/ui/StatusPanel.java +++ b/src/main/java/com/loomcom/symon/ui/StatusPanel.java @@ -31,6 +31,8 @@ import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** * UI component that displays the current state of the simulated CPU. @@ -162,59 +164,74 @@ public class StatusPanel extends JPanel { yField = makeTextField(SMALL_TEXT_FIELD_SIZE, true); // Make fields editable - pcField.addActionListener(e -> { - try { - int newVal = getHexVal(pcField) & 0xffff; - machine.getCpu().setProgramCounter(newVal); - } catch (Exception ex) { - // Swallow exception - } + pcField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + int newVal = StatusPanel.this.getHexVal(pcField) & 0xffff; + machine.getCpu().setProgramCounter(newVal); + } catch (Exception ex) { + // Swallow exception + } - updateState(); + StatusPanel.this.updateState(); + } }); - spField.addActionListener(e -> { - try { - int newVal = getHexVal(spField) & 0xff; - machine.getCpu().setStackPointer(newVal); - } catch (Exception ex) { - // Swallow exception - } + spField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + int newVal = StatusPanel.this.getHexVal(spField) & 0xff; + machine.getCpu().setStackPointer(newVal); + } catch (Exception ex) { + // Swallow exception + } - updateState(); + StatusPanel.this.updateState(); + } }); - aField.addActionListener(e -> { - try { - int newVal = getHexVal(aField) & 0xff; - machine.getCpu().setAccumulator(newVal); - } catch (Exception ex) { - // Swallow exception - } + aField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + int newVal = StatusPanel.this.getHexVal(aField) & 0xff; + machine.getCpu().setAccumulator(newVal); + } catch (Exception ex) { + // Swallow exception + } - updateState(); + StatusPanel.this.updateState(); + } }); - xField.addActionListener(e -> { - try { - int newVal = getHexVal(xField) & 0xff; - machine.getCpu().setXRegister(newVal); - } catch (Exception ex) { - // Swallow exception - } + xField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + int newVal = StatusPanel.this.getHexVal(xField) & 0xff; + machine.getCpu().setXRegister(newVal); + } catch (Exception ex) { + // Swallow exception + } - updateState(); + StatusPanel.this.updateState(); + } }); - yField.addActionListener(e -> { - try { - int newVal = getHexVal(yField) & 0xff; - machine.getCpu().setYRegister(newVal); - } catch (Exception ex) { - // Swallow exception - } + yField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + int newVal = StatusPanel.this.getHexVal(yField) & 0xff; + machine.getCpu().setYRegister(newVal); + } catch (Exception ex) { + // Swallow exception + } - updateState(); + StatusPanel.this.updateState(); + } }); constraints.anchor = GridBagConstraints.LINE_START; diff --git a/src/main/java/com/loomcom/symon/ui/VideoWindow.java b/src/main/java/com/loomcom/symon/ui/VideoWindow.java index 0a6a2f5..1610539 100644 --- a/src/main/java/com/loomcom/symon/ui/VideoWindow.java +++ b/src/main/java/com/loomcom/symon/ui/VideoWindow.java @@ -122,10 +122,13 @@ public class VideoWindow extends JFrame implements DeviceChangeListener { */ private class CursorBlinker implements Runnable { public void run() { - SwingUtilities.invokeLater(() -> { - if (cursorBlinkRate > 0) { - hideCursor = !hideCursor; - repaint(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (cursorBlinkRate > 0) { + hideCursor = !hideCursor; + VideoWindow.this.repaint(); + } } }); }