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();
initConsole(false);
JalviewAppender jappender = new JalviewAppender();
jappender.setLayout(new SimpleLayout());
- jappender.setTextArea(textArea);
+ JalviewAppender.setTextArea(textArea);
org.apache.log4j.Logger.getRootLogger().addAppender(jappender);
}
{
textArea.setText("");
}
-
+ int lines=0,lim=1000;
public synchronized void run()
{
try
if (pin.available() != 0)
{
String input = this.readLine(pin);
+ stdout.print(input);
textArea.append(input);
+ lines++;
}
if (quit)
return;
if (pin2.available() != 0)
{
String input = this.readLine(pin2);
+ stderr.print(input);
textArea.append(input);
+ lines++;
}
if (quit)
return;
{
textArea.append("\nConsole reports an Internal error.");
textArea.append("The error is: " + e);
+ lines+=2;
}
// just for testing (Throw a Nullpointer after 1 second)
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();
+ }
}