|
@@ -1,7 +1,6 @@
|
|
|
package com.its.vds.ui;
|
|
|
|
|
|
import javax.swing.*;
|
|
|
-import javax.swing.text.BadLocationException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
|
|
@@ -9,6 +8,7 @@ public class JTextAreaOutputStream extends OutputStream {
|
|
|
|
|
|
private final JTextArea logArea;
|
|
|
public static boolean isLoggingPause = false;
|
|
|
+ private final StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
public JTextAreaOutputStream(JTextArea logArea) {
|
|
|
if (logArea == null)
|
|
@@ -16,23 +16,23 @@ public class JTextAreaOutputStream extends OutputStream {
|
|
|
this.logArea = logArea;
|
|
|
}
|
|
|
|
|
|
- public synchronized void logWrite(String text) {
|
|
|
- Runnable runnable = new Runnable() {
|
|
|
- public void run() {
|
|
|
- logArea.append(text);
|
|
|
- if (logArea.getDocument().getLength() >
|
|
|
- 50000) {
|
|
|
- try {
|
|
|
- logArea.getDocument().remove(0, 5000);
|
|
|
- } catch (BadLocationException e) {
|
|
|
- //log.error("Can't clean log", e);
|
|
|
- }
|
|
|
- }
|
|
|
- logArea.setCaretPosition(logArea.getDocument().getLength());
|
|
|
- }
|
|
|
- };
|
|
|
- SwingUtilities.invokeLater(runnable);
|
|
|
- }
|
|
|
+// public synchronized void logWrite(String text) {
|
|
|
+// Runnable runnable = new Runnable() {
|
|
|
+// public void run() {
|
|
|
+// logArea.append(text);
|
|
|
+// if (logArea.getDocument().getLength() >
|
|
|
+// 50000) {
|
|
|
+// try {
|
|
|
+// logArea.getDocument().remove(0, 5000);
|
|
|
+// } catch (BadLocationException e) {
|
|
|
+// //log.error("Can't clean log", e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// logArea.setCaretPosition(logArea.getDocument().getLength());
|
|
|
+// }
|
|
|
+// };
|
|
|
+// SwingUtilities.invokeLater(runnable);
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
public void write(byte[] buffer, int offset, int length) throws IOException
|
|
@@ -61,6 +61,30 @@ public class JTextAreaOutputStream extends OutputStream {
|
|
|
|
|
|
@Override
|
|
|
public void write(int b) throws IOException {
|
|
|
- write (new byte [] {(byte)b}, 0, 1);
|
|
|
+// if (b == '\r')
|
|
|
+// return;
|
|
|
+
|
|
|
+ if (b == '\n') {
|
|
|
+ final String text = sb.toString() + "\n";
|
|
|
+ SwingUtilities.invokeLater(new Runnable ()
|
|
|
+ {
|
|
|
+ @Override
|
|
|
+ public void run()
|
|
|
+ {
|
|
|
+ synchronized (logArea) {
|
|
|
+ if (logArea.getLineCount() > 2000) {
|
|
|
+ logArea.setText(null);
|
|
|
+ }
|
|
|
+ logArea.append(text);
|
|
|
+ logArea.setCaretPosition(logArea.getDocument().getLength());
|
|
|
+ sb.setLength(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ sb.append((char) b);
|
|
|
+ }
|
|
|
+
|
|
|
+ //write (new byte [] {(byte)b}, 0, 1);
|
|
|
}
|
|
|
}
|