Skip to content

Commit e3f129a

Browse files
Pieter12345cmaglie
authored andcommitted
Fix compiler/IDE warnings in monitor classes + Code cleanup
No functional changes: - Fix compiler/IDE warnings in monitor classes. - Replace listeners to use lambda classes where convenient in monitor classes. - Code cleanup.
1 parent 1a6d554 commit e3f129a

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed

app/src/processing/app/AbstractMonitor.java

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public AbstractMonitor(BoardPort boardPort) {
2727
this.boardPort = boardPort;
2828

2929
addWindowListener(new WindowAdapter() {
30+
@Override
3031
public void windowClosing(WindowEvent event) {
3132
try {
3233
closed = true;
@@ -41,6 +42,7 @@ public void windowClosing(WindowEvent event) {
4142
KeyStroke wc = Editor.WINDOW_CLOSE_KEYSTROKE;
4243
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(wc, "close");
4344
getRootPane().getActionMap().put("close", (new AbstractAction() {
45+
@Override
4446
public void actionPerformed(ActionEvent event) {
4547
try {
4648
close();
@@ -165,6 +167,7 @@ private synchronized String consumeUpdateBuffer() {
165167
return s;
166168
}
167169

170+
@Override
168171
public void actionPerformed(ActionEvent e) {
169172
String s = consumeUpdateBuffer();
170173
if (s.isEmpty()) {

app/src/processing/app/AbstractTextMonitor.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
4545
protected JButton clearButton;
4646
protected JCheckBox autoscrollBox;
4747
protected JCheckBox addTimeStampBox;
48-
protected JComboBox lineEndings;
49-
protected JComboBox serialRates;
48+
protected JComboBox<String> lineEndings;
49+
protected JComboBox<String> serialRates;
5050

5151
public AbstractTextMonitor(Base base, BoardPort boardPort) {
5252
super(boardPort);
5353
this.base = base;
5454
}
5555

56+
@Override
5657
protected void onCreateWindow(Container mainPane) {
5758

5859
mainPane.setLayout(new BorderLayout());
@@ -111,6 +112,7 @@ public void keyPressed(KeyEvent e) {
111112
textField = new JTextField(40);
112113
// textField is selected every time the window is focused
113114
addWindowFocusListener(new WindowAdapter() {
115+
@Override
114116
public void windowGainedFocus(WindowEvent e) {
115117
textField.requestFocusInWindow();
116118
}
@@ -139,22 +141,17 @@ public void windowGainedFocus(WindowEvent e) {
139141
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
140142
noLineEndingAlert.setMinimumSize(minimumSize);
141143

142-
lineEndings = new JComboBox(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
143-
lineEndings.addActionListener(new ActionListener() {
144-
public void actionPerformed(ActionEvent event) {
145-
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
146-
noLineEndingAlert.setForeground(pane.getBackground());
147-
}
148-
});
149-
addTimeStampBox.addActionListener(new ActionListener() {
150-
public void actionPerformed(ActionEvent e) {
151-
PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected());
152-
}
144+
lineEndings = new JComboBox<String>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
145+
lineEndings.addActionListener((ActionEvent event) -> {
146+
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
147+
noLineEndingAlert.setForeground(pane.getBackground());
153148
});
149+
addTimeStampBox.addActionListener((ActionEvent event) ->
150+
PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected()));
154151

155152
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
156153

157-
serialRates = new JComboBox();
154+
serialRates = new JComboBox<String>();
158155
for (String rate : serialRateStrings) {
159156
serialRates.addItem(rate + " " + tr("baud"));
160157
}
@@ -177,6 +174,7 @@ public void actionPerformed(ActionEvent e) {
177174
mainPane.add(pane, BorderLayout.SOUTH);
178175
}
179176

177+
@Override
180178
protected void onEnableWindow(boolean enable)
181179
{
182180
textArea.setEnabled(enable);
@@ -203,6 +201,7 @@ public void onSerialRateChange(ActionListener listener) {
203201
serialRates.addActionListener(listener);
204202
}
205203

204+
@Override
206205
public void message(String msg) {
207206
SwingUtilities.invokeLater(() -> updateTextArea(msg));
208207
}

app/src/processing/app/EditorTab.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public EditorTab(Editor editor, SketchFile file, String contents)
110110
file.setStorage(this);
111111
applyPreferences();
112112
add(scrollPane, BorderLayout.CENTER);
113-
textarea.addMouseWheelListener(this);
113+
textarea.addMouseWheelListener(this);
114114
}
115115

116116
private RSyntaxDocument createDocument(String contents) {

app/src/processing/app/SerialMonitor.java

+20-27
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
import cc.arduino.packages.BoardPort;
2222
import processing.app.legacy.PApplet;
2323

24-
import java.awt.*;
24+
import java.awt.Color;
2525
import java.awt.event.ActionEvent;
26-
import java.awt.event.ActionListener;
2726

2827
import static processing.app.I18n.tr;
2928

@@ -38,36 +37,28 @@ public SerialMonitor(Base base, BoardPort port) {
3837

3938
serialRate = PreferencesData.getInteger("serial.debug_rate");
4039
serialRates.setSelectedItem(serialRate + " " + tr("baud"));
41-
onSerialRateChange(new ActionListener() {
42-
public void actionPerformed(ActionEvent event) {
43-
String wholeString = (String) serialRates.getSelectedItem();
44-
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
45-
serialRate = Integer.parseInt(rateString);
46-
PreferencesData.set("serial.debug_rate", rateString);
47-
try {
48-
close();
49-
Thread.sleep(100); // Wait for serial port to properly close
50-
open();
51-
} catch (InterruptedException e) {
52-
// noop
53-
} catch (Exception e) {
54-
System.err.println(e);
55-
}
40+
onSerialRateChange((ActionEvent event) -> {
41+
String wholeString = (String) serialRates.getSelectedItem();
42+
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
43+
serialRate = Integer.parseInt(rateString);
44+
PreferencesData.set("serial.debug_rate", rateString);
45+
try {
46+
close();
47+
Thread.sleep(100); // Wait for serial port to properly close
48+
open();
49+
} catch (InterruptedException e) {
50+
// noop
51+
} catch (Exception e) {
52+
System.err.println(e);
5653
}
5754
});
5855

59-
onSendCommand(new ActionListener() {
60-
public void actionPerformed(ActionEvent e) {
61-
send(textField.getText());
62-
textField.setText("");
63-
}
56+
onSendCommand((ActionEvent event) -> {
57+
send(textField.getText());
58+
textField.setText("");
6459
});
6560

66-
onClearCommand(new ActionListener() {
67-
public void actionPerformed(ActionEvent e) {
68-
textArea.setText("");
69-
}
70-
});
61+
onClearCommand((ActionEvent event) -> textArea.setText(""));
7162
}
7263

7364
private void send(String s) {
@@ -93,6 +84,7 @@ private void send(String s) {
9384
}
9485
}
9586

87+
@Override
9688
public void open() throws Exception {
9789
super.open();
9890

@@ -106,6 +98,7 @@ protected void message(char buff[], int n) {
10698
};
10799
}
108100

101+
@Override
109102
public void close() throws Exception {
110103
super.close();
111104
if (serial != null) {

0 commit comments

Comments
 (0)