Skip to content

Commit 12cddf0

Browse files
author
Federico Fissore
committed
SerialMonitor: added "no line ending" alert
1 parent 2ce3a4a commit 12cddf0

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

app/src/processing/app/AbstractMonitor.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
public abstract class AbstractMonitor extends JFrame implements MessageConsumer {
1818

19+
protected final JLabel noLineEndingAlert;
1920
protected JTextArea textArea;
2021
protected JScrollPane scrollPane;
2122
protected JTextField textField;
@@ -69,29 +70,33 @@ public void actionPerformed(ActionEvent event) {
6970

7071
getContentPane().add(scrollPane, BorderLayout.CENTER);
7172

72-
JPanel pane = new JPanel();
73-
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
74-
pane.setBorder(new EmptyBorder(4, 4, 4, 4));
73+
JPanel upperPane = new JPanel();
74+
upperPane.setLayout(new BoxLayout(upperPane, BoxLayout.X_AXIS));
75+
upperPane.setBorder(new EmptyBorder(4, 4, 4, 4));
7576

7677
textField = new JTextField(40);
7778
sendButton = new JButton(_("Send"));
7879

79-
pane.add(textField);
80-
pane.add(Box.createRigidArea(new Dimension(4, 0)));
81-
pane.add(sendButton);
80+
upperPane.add(textField);
81+
upperPane.add(Box.createRigidArea(new Dimension(4, 0)));
82+
upperPane.add(sendButton);
8283

83-
getContentPane().add(pane, BorderLayout.NORTH);
84+
getContentPane().add(upperPane, BorderLayout.NORTH);
8485

85-
pane = new JPanel();
86+
final JPanel pane = new JPanel();
8687
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
8788
pane.setBorder(new EmptyBorder(4, 4, 4, 4));
8889

8990
autoscrollBox = new JCheckBox(_("Autoscroll"), true);
9091

92+
noLineEndingAlert = new JLabel(I18n.format(_("You've pressed {0} but nothing was sent. Should you select a line ending?"), _("Send")));
93+
noLineEndingAlert.setForeground(pane.getBackground());
94+
9195
lineEndings = new JComboBox(new String[]{_("No line ending"), _("Newline"), _("Carriage return"), _("Both NL & CR")});
9296
lineEndings.addActionListener(new ActionListener() {
9397
public void actionPerformed(ActionEvent event) {
9498
Preferences.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
99+
noLineEndingAlert.setForeground(pane.getBackground());
95100
}
96101
});
97102
if (Preferences.get("serial.line_ending") != null) {
@@ -113,6 +118,8 @@ public void actionPerformed(ActionEvent event) {
113118

114119
pane.add(autoscrollBox);
115120
pane.add(Box.createHorizontalGlue());
121+
pane.add(noLineEndingAlert);
122+
pane.add(Box.createRigidArea(new Dimension(8, 0)));
116123
pane.add(lineEndings);
117124
pane.add(Box.createRigidArea(new Dimension(8, 0)));
118125
pane.add(serialRates);

app/src/processing/app/SerialMonitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import processing.core.PApplet;
2222

23+
import java.awt.*;
2324
import java.awt.event.ActionEvent;
2425
import java.awt.event.ActionListener;
2526

@@ -77,6 +78,10 @@ private void send(String s) {
7778
s += "\r\n";
7879
break;
7980
}
81+
if ("".equals(s) && lineEndings.getSelectedIndex() == 0 && !Preferences.has("runtime.line.ending.alert.notified")) {
82+
noLineEndingAlert.setForeground(Color.RED);
83+
Preferences.set("runtime.line.ending.alert.notified", "true");
84+
}
8085
serial.write(s);
8186
}
8287
}

0 commit comments

Comments
 (0)