@@ -171,56 +171,37 @@ public void onSerialRateChange(ActionListener listener) {
171
171
serialRates .addActionListener (listener );
172
172
}
173
173
174
- public void message (final String msg ) {
175
- SwingUtilities .invokeLater (new UpdateTextAreaAction (textArea ,
176
- addTimeStampBox .isSelected (),
177
- autoscrollBox .isSelected (),
178
- msg ));
174
+ public void message (String msg ) {
175
+ SwingUtilities .invokeLater (() -> updateTextArea (msg ));
179
176
}
180
177
181
- static class UpdateTextAreaAction implements Runnable {
178
+ private static final String LINE_SEPARATOR = "\n " ;
179
+ private boolean isStartingLine = true ;
182
180
183
- private static final String LINE_SEPARATOR = "\n " ;
184
-
185
- private String msg ;
186
- private boolean addTimeStamp ;
187
- private boolean doAutoscroll ;
188
- private TextAreaFIFO textArea ;
189
-
190
- UpdateTextAreaAction (TextAreaFIFO textArea , boolean addTimeStamp ,
191
- boolean doAutoscroll , String msg ) {
192
- this .msg = msg ;
193
- this .textArea = textArea ;
194
- this .addTimeStamp = addTimeStamp ;
195
- this .doAutoscroll = doAutoscroll ;
181
+ protected void updateTextArea (String msg ) {
182
+ if (addTimeStampBox .isSelected ()) {
183
+ textArea .append (addTimestamps (msg ));
184
+ } else {
185
+ textArea .append (msg );
196
186
}
197
-
198
- public void run () {
199
- if (addTimeStamp ) {
200
- textArea .append (addTimestamps (msg ));
201
- } else {
202
- textArea .append (msg );
203
- }
204
- if (doAutoscroll ) {
205
- textArea .setCaretPosition (textArea .getDocument ().getLength ());
206
- }
187
+ if (autoscrollBox .isSelected ()) {
188
+ textArea .setCaretPosition (textArea .getDocument ().getLength ());
207
189
}
190
+ }
208
191
209
- private String addTimestamps (String text ) {
210
- String now = new SimpleDateFormat ("HH:mm:ss.SSS -> " ).format (new Date ());
211
- final StringBuilder sb = new StringBuilder (text .length () + now .length ());
212
- boolean isStartingLine = true ;
213
- StringTokenizer tokenizer = new StringTokenizer (text , LINE_SEPARATOR , true );
214
- while (tokenizer .hasMoreTokens ()) {
215
- if (isStartingLine ) {
216
- sb .append (now );
217
- }
218
- String token = tokenizer .nextToken ();
219
- sb .append (token );
220
- // tokenizer returns "\n" as a single token
221
- isStartingLine = token .equals (LINE_SEPARATOR );
192
+ private String addTimestamps (String text ) {
193
+ String now = new SimpleDateFormat ("HH:mm:ss.SSS -> " ).format (new Date ());
194
+ final StringBuilder sb = new StringBuilder (text .length () + now .length ());
195
+ StringTokenizer tokenizer = new StringTokenizer (text , LINE_SEPARATOR , true );
196
+ while (tokenizer .hasMoreTokens ()) {
197
+ if (isStartingLine ) {
198
+ sb .append (now );
222
199
}
223
- return sb .toString ();
200
+ String token = tokenizer .nextToken ();
201
+ sb .append (token );
202
+ // tokenizer returns "\n" as a single token
203
+ isStartingLine = token .equals (LINE_SEPARATOR );
224
204
}
205
+ return sb .toString ();
225
206
}
226
207
}
0 commit comments