package genegui; import java.io.*; import javax.swing.event.*; import javax.swing.*; /** Console.java Implements an InternalJFrame "console" for displaying output from Ingeneue the standard and/or error output streams. */ public class Console extends PrintStream { /** */ private JTextPane Display; /** */ private JInternalFrame DisplayFrame; /** */ private PrintStream OriginalPrintStream; /** */ private JScrollPane ScrollPane; /** */ private boolean StandardError = false; /** */ private boolean StandardOutput = false; public Console(String title, PrintStream originalPrintStream) { super(new PipedOutputStream()); OriginalPrintStream = originalPrintStream; StandardError = (OriginalPrintStream==System.err); StandardOutput = (OriginalPrintStream==System.out); Display = new JTextPane(); Display.setText(""); ScrollPane = new JScrollPane(Display); DisplayFrame = new JInternalFrame(title,true,true,true,true); DisplayFrame.setContentPane(ScrollPane); DisplayFrame.addInternalFrameListener(new InternalFrameAdapter() { public void internalFrameClosing(InternalFrameEvent ife) { if (StandardError) System.setErr(OriginalPrintStream); if (StandardOutput) System.setOut(OriginalPrintStream); } }); } /** @author WJS */ public JInternalFrame getFrame() { return(DisplayFrame); } /** @author WJS */ public int getHeight() { return(DisplayFrame.getHeight()); } public boolean isClosed() { return(DisplayFrame.isClosed()); } private void output(String s) { Display.setText(Display.getText()+s); } public void print(char c) { char[] cs = new char[1]; cs[0] = c; output(new String(cs)); } public void print(char[] c) { output(new String(c)); } public void print(double d) { output(Double.toString(d)); } public void print(float f) { output(Float.toString(f)); } public void print(int i) { output(Integer.toString(i)); } public void print(long l) { output(Long.toString(l)); } public void print(Object o) { output(o.toString()); } public void print(String s) { output(s); } public void println() { output("\n"); } public void println(char c) { char[] cs = new char[1]; cs[0] = c; output(new String(cs)+"\n"); } public void println(char[] c) { output(new String(c)+"\n"); } public void println(double d) { output(Double.toString(d)+"\n"); } public void println(float f) { output(Float.toString(f)+"\n"); } public void println(int i) { output(Integer.toString(i)+"\n"); } public void println(long l) { output(Long.toString(l)+"\n"); } public void println(Object o) { output(o.toString()+"\n"); } public void println(String s) { output(s+"\n"); } public void setLocation(int x, int y) { DisplayFrame.setLocation(x,y); } public void show(boolean show) { DisplayFrame.show(show); } public void toFront() { DisplayFrame.toFront(); } public void write(byte[] buff, int offset, int length) { output(new String(buff,offset,length)); } public void write(int b) { byte[] bs = new byte[1]; bs[0] = (byte)b; output(new String(bs,0,1)); } }