|
25 | 25 | import javax.swing.JTextField; |
26 | 26 | import javax.swing.SwingUtilities; |
27 | 27 | import javax.swing.border.EmptyBorder; |
28 | | -import javax.swing.text.BadLocationException; |
29 | 28 | import javax.swing.text.DefaultCaret; |
30 | | -import javax.swing.text.Document; |
31 | 29 |
|
32 | 30 | import cc.arduino.packages.BoardPort; |
33 | 31 |
|
@@ -182,36 +180,24 @@ public void message(final String s) { |
182 | 180 | Date t = new Date(); |
183 | 181 | String now; |
184 | 182 | StringBuilder out = new StringBuilder(16384); |
| 183 | + boolean isStartingLine = false; |
185 | 184 |
|
186 | 185 | public void run() { |
187 | 186 | if (addTimeStampBox.isSelected()) { |
188 | 187 | t.setTime(System.currentTimeMillis()); |
189 | 188 | now = logDateFormat.format(t); |
190 | 189 | out.setLength(0); |
191 | 190 |
|
192 | | - boolean isStartingLine; |
193 | | - try { |
194 | | - Document doc = textArea.getDocument(); |
195 | | - isStartingLine = doc.getLength() == 0 || ((int) doc.getText(doc.getLength() - 1, 1).charAt(0) == 10); |
196 | | - } catch (BadLocationException e) { |
197 | | - // Should not happen but... |
198 | | - e.printStackTrace(); |
199 | | - return; |
200 | | - } |
201 | | - |
202 | 191 | StringTokenizer tokenizer = new StringTokenizer(s, "\n", true); |
203 | 192 | while (tokenizer.hasMoreTokens()) { |
204 | 193 | if (isStartingLine) { |
205 | 194 | out.append(now); |
206 | 195 | out.append(" -> "); |
207 | 196 | } |
208 | | - out.append(tokenizer.nextToken()); |
209 | | - |
210 | | - // Check if we have a "\n" token |
211 | | - if (tokenizer.hasMoreTokens()) { |
212 | | - out.append(tokenizer.nextToken()); |
213 | | - isStartingLine = true; |
214 | | - } |
| 197 | + String token = tokenizer.nextToken(); |
| 198 | + out.append(token); |
| 199 | + // tokenizer returns "\n" as a single token |
| 200 | + isStartingLine = token.charAt(0) == '\n'; |
215 | 201 | } |
216 | 202 |
|
217 | 203 | textArea.append(out.toString()); |
|
0 commit comments