mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
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.
This commit is contained in:
parent
1a6d55480c
commit
e3f129a0ee
@ -27,6 +27,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
this.boardPort = boardPort;
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent event) {
|
||||
try {
|
||||
closed = true;
|
||||
@ -41,6 +42,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
KeyStroke wc = Editor.WINDOW_CLOSE_KEYSTROKE;
|
||||
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(wc, "close");
|
||||
getRootPane().getActionMap().put("close", (new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
close();
|
||||
@ -165,6 +167,7 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String s = consumeUpdateBuffer();
|
||||
if (s.isEmpty()) {
|
||||
|
@ -45,14 +45,15 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
||||
protected JButton clearButton;
|
||||
protected JCheckBox autoscrollBox;
|
||||
protected JCheckBox addTimeStampBox;
|
||||
protected JComboBox lineEndings;
|
||||
protected JComboBox serialRates;
|
||||
protected JComboBox<String> lineEndings;
|
||||
protected JComboBox<String> serialRates;
|
||||
|
||||
public AbstractTextMonitor(Base base, BoardPort boardPort) {
|
||||
super(boardPort);
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreateWindow(Container mainPane) {
|
||||
|
||||
mainPane.setLayout(new BorderLayout());
|
||||
@ -111,6 +112,7 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
||||
textField = new JTextField(40);
|
||||
// textField is selected every time the window is focused
|
||||
addWindowFocusListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowGainedFocus(WindowEvent e) {
|
||||
textField.requestFocusInWindow();
|
||||
}
|
||||
@ -139,22 +141,17 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
||||
minimumSize.setSize(minimumSize.getWidth() / 3, minimumSize.getHeight());
|
||||
noLineEndingAlert.setMinimumSize(minimumSize);
|
||||
|
||||
lineEndings = new JComboBox(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
|
||||
lineEndings.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
|
||||
noLineEndingAlert.setForeground(pane.getBackground());
|
||||
}
|
||||
});
|
||||
addTimeStampBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected());
|
||||
}
|
||||
lineEndings = new JComboBox<String>(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
|
||||
lineEndings.addActionListener((ActionEvent event) -> {
|
||||
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
|
||||
noLineEndingAlert.setForeground(pane.getBackground());
|
||||
});
|
||||
addTimeStampBox.addActionListener((ActionEvent event) ->
|
||||
PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected()));
|
||||
|
||||
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
|
||||
|
||||
serialRates = new JComboBox();
|
||||
serialRates = new JComboBox<String>();
|
||||
for (String rate : serialRateStrings) {
|
||||
serialRates.addItem(rate + " " + tr("baud"));
|
||||
}
|
||||
@ -177,6 +174,7 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
||||
mainPane.add(pane, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnableWindow(boolean enable)
|
||||
{
|
||||
textArea.setEnabled(enable);
|
||||
@ -203,6 +201,7 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
|
||||
serialRates.addActionListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void message(String msg) {
|
||||
SwingUtilities.invokeLater(() -> updateTextArea(msg));
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class EditorTab extends JPanel implements SketchFile.TextStorage, MouseWh
|
||||
file.setStorage(this);
|
||||
applyPreferences();
|
||||
add(scrollPane, BorderLayout.CENTER);
|
||||
textarea.addMouseWheelListener(this);
|
||||
textarea.addMouseWheelListener(this);
|
||||
}
|
||||
|
||||
private RSyntaxDocument createDocument(String contents) {
|
||||
|
@ -21,9 +21,8 @@ package processing.app;
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
|
||||
@ -38,36 +37,28 @@ public class SerialMonitor extends AbstractTextMonitor {
|
||||
|
||||
serialRate = PreferencesData.getInteger("serial.debug_rate");
|
||||
serialRates.setSelectedItem(serialRate + " " + tr("baud"));
|
||||
onSerialRateChange(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String wholeString = (String) serialRates.getSelectedItem();
|
||||
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
|
||||
serialRate = Integer.parseInt(rateString);
|
||||
PreferencesData.set("serial.debug_rate", rateString);
|
||||
try {
|
||||
close();
|
||||
Thread.sleep(100); // Wait for serial port to properly close
|
||||
open();
|
||||
} catch (InterruptedException e) {
|
||||
// noop
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
onSerialRateChange((ActionEvent event) -> {
|
||||
String wholeString = (String) serialRates.getSelectedItem();
|
||||
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
|
||||
serialRate = Integer.parseInt(rateString);
|
||||
PreferencesData.set("serial.debug_rate", rateString);
|
||||
try {
|
||||
close();
|
||||
Thread.sleep(100); // Wait for serial port to properly close
|
||||
open();
|
||||
} catch (InterruptedException e) {
|
||||
// noop
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
});
|
||||
|
||||
onSendCommand(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
send(textField.getText());
|
||||
textField.setText("");
|
||||
}
|
||||
onSendCommand((ActionEvent event) -> {
|
||||
send(textField.getText());
|
||||
textField.setText("");
|
||||
});
|
||||
|
||||
onClearCommand(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
textArea.setText("");
|
||||
}
|
||||
});
|
||||
onClearCommand((ActionEvent event) -> textArea.setText(""));
|
||||
}
|
||||
|
||||
private void send(String s) {
|
||||
@ -93,6 +84,7 @@ public class SerialMonitor extends AbstractTextMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() throws Exception {
|
||||
super.open();
|
||||
|
||||
@ -106,6 +98,7 @@ public class SerialMonitor extends AbstractTextMonitor {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
super.close();
|
||||
if (serial != null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user