From: jprocter Date: Fri, 26 Mar 2010 12:23:50 +0000 (+0000) Subject: console output to stderr and stdout, and console buffer stays constant size (needs... X-Git-Tag: Release_2_5~110 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d0d3897c2bbba80ed870da1ad5d70eadfec8c5f9;p=jalview.git console output to stderr and stdout, and console buffer stays constant size (needs optimising) --- diff --git a/src/jalview/gui/Console.java b/src/jalview/gui/Console.java index 57d563b..39b0ab3 100644 --- a/src/jalview/gui/Console.java +++ b/src/jalview/gui/Console.java @@ -47,7 +47,8 @@ public class Console extends WindowAdapter implements WindowListener, private Thread reader2; private boolean quit; - + private final PrintStream stdout = System.out; + private final PrintStream stderr = System.err; private final PipedInputStream pin = new PipedInputStream(); private final PipedInputStream pin2 = new PipedInputStream(); @@ -178,7 +179,7 @@ public class Console extends WindowAdapter implements WindowListener, initConsole(false); JalviewAppender jappender = new JalviewAppender(); jappender.setLayout(new SimpleLayout()); - jappender.setTextArea(textArea); + JalviewAppender.setTextArea(textArea); org.apache.log4j.Logger.getRootLogger().addAppender(jappender); } @@ -225,7 +226,7 @@ public class Console extends WindowAdapter implements WindowListener, { textArea.setText(""); } - + int lines=0,lim=1000; public synchronized void run() { try @@ -241,7 +242,9 @@ public class Console extends WindowAdapter implements WindowListener, if (pin.available() != 0) { String input = this.readLine(pin); + stdout.print(input); textArea.append(input); + lines++; } if (quit) return; @@ -258,7 +261,9 @@ public class Console extends WindowAdapter implements WindowListener, if (pin2.available() != 0) { String input = this.readLine(pin2); + stderr.print(input); textArea.append(input); + lines++; } if (quit) return; @@ -267,6 +272,7 @@ public class Console extends WindowAdapter implements WindowListener, { textArea.append("\nConsole reports an Internal error."); textArea.append("The error is: " + e); + lines+=2; } // just for testing (Throw a Nullpointer after 1 second) @@ -281,6 +287,18 @@ public class Console extends WindowAdapter implements WindowListener, throw new NullPointerException( "Application test: throwing an NullPointerException It should arrive at the console"); } + // trim the buffer + if (lines>lim) + { + try { + String header = textArea.getText(0,textArea.getLineEndOffset(5))+"\n..Truncated..\n"; // keep first 5 lines for startup info + int truncate = textArea.getLineEndOffset(lim-7-lines); + textArea.setText(header+textArea.getText(truncate,textArea.getText().length()-truncate)); } catch (Exception e) + { + e.printStackTrace(); + } + lines = textArea.getLineCount(); + } }