Skip to content

Commit 17b511d

Browse files
committed
Fix serial monitor timestamp print regression
Fix #8055
1 parent db2dd8f commit 17b511d

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

app/src/processing/app/AbstractTextMonitor.java

+37-31
Original file line numberDiff line numberDiff line change
@@ -174,40 +174,46 @@ public void onSerialRateChange(ActionListener listener) {
174174
serialRates.addActionListener(listener);
175175
}
176176

177-
public void message(final String s) {
178-
SwingUtilities.invokeLater(new Runnable() {
179-
// Pre-allocate all objects used for streaming data
180-
Date t = new Date();
181-
String now;
182-
StringBuilder out = new StringBuilder(16384);
183-
boolean isStartingLine = false;
184-
185-
public void run() {
186-
if (addTimeStampBox.isSelected()) {
187-
t.setTime(System.currentTimeMillis());
188-
now = logDateFormat.format(t);
189-
out.setLength(0);
190-
191-
StringTokenizer tokenizer = new StringTokenizer(s, "\n", true);
192-
while (tokenizer.hasMoreTokens()) {
193-
if (isStartingLine) {
194-
out.append(now);
195-
}
196-
String token = tokenizer.nextToken();
197-
out.append(token);
198-
// tokenizer returns "\n" as a single token
199-
isStartingLine = token.charAt(0) == '\n';
177+
class AppendMessageAction implements Runnable {
178+
public String msg;
179+
180+
@Override
181+
public void run() {
182+
if (addTimeStampBox.isSelected()) {
183+
t.setTime(System.currentTimeMillis());
184+
String now = logDateFormat.format(t);
185+
out.setLength(0);
186+
187+
StringTokenizer tokenizer = new StringTokenizer(msg, "\n", true);
188+
while (tokenizer.hasMoreTokens()) {
189+
if (isStartingLine) {
190+
out.append(now);
200191
}
201-
202-
textArea.append(out.toString());
203-
} else {
204-
textArea.append(s);
192+
String token = tokenizer.nextToken();
193+
out.append(token);
194+
// tokenizer returns "\n" as a single token
195+
isStartingLine = token.charAt(0) == '\n';
205196
}
206197

207-
if (autoscrollBox.isSelected()) {
208-
textArea.setCaretPosition(textArea.getDocument().getLength());
209-
}
198+
textArea.append(out.toString());
199+
} else {
200+
textArea.append(msg);
210201
}
211-
});
202+
203+
if (autoscrollBox.isSelected()) {
204+
textArea.setCaretPosition(textArea.getDocument().getLength());
205+
}
206+
}
207+
};
208+
209+
// Pre-allocate all objects used for streaming data
210+
private Date t = new Date();
211+
private StringBuilder out = new StringBuilder(16384);
212+
private boolean isStartingLine = true;
213+
private AppendMessageAction appendMessageAction = new AppendMessageAction();
214+
215+
public void message(String s) {
216+
appendMessageAction.msg = s;
217+
SwingUtilities.invokeLater(appendMessageAction);
212218
}
213219
}

0 commit comments

Comments
 (0)