MCPcopy Index your code
hub / github.com/beanshell/beanshell / AWTConsole

Class AWTConsole

src/bsh/util/AWTConsole.java:78–336  ·  view source on GitHub ↗

An old AWT based console for BeanShell. I looked everwhere for one, and couldn't find anything that worked. I've tried to keep this as small as possible, no frills. (Well, one frill - a simple history with the up/down arrows) My hope is that this can be moved to a lightweight (portable) compone

Source from the content-addressed store, hash-verified

76 this. Also we have to use getPeer() for the big hack above.
77*/
78public class AWTConsole extends TextArea
79 implements ConsoleInterface, Runnable, KeyListener {
80
81 private OutputStream outPipe;
82 private InputStream inPipe;
83
84 // formerly public
85 private InputStream in;
86 private PrintStream out;
87
88 public Reader getIn() { return new InputStreamReader(in); }
89 public PrintStream getOut() { return out; }
90 public PrintStream getErr() { return out; }
91
92 private StringBuffer line = new StringBuffer();
93 private String startedLine;
94 private int textLength = 0;
95 private Vector history = new Vector();
96 private int histLine = 0;
97
98 public AWTConsole( int rows, int cols, InputStream cin, OutputStream cout ) {
99 super(rows, cols);
100 setFont( new Font("Monospaced",Font.PLAIN,14) );
101 setEditable(false);
102 addKeyListener ( this );
103
104 outPipe = cout;
105 if ( outPipe == null ) {
106 outPipe = new PipedOutputStream();
107 try {
108 in = new PipedInputStream((PipedOutputStream)outPipe);
109 } catch ( IOException e ) {
110 print("Console internal error...");
111 }
112 }
113
114 // start the inpipe watcher
115 inPipe = cin;
116 new Thread( this ).start();
117
118 requestFocus();
119 }
120
121 public void keyPressed( KeyEvent e ) {
122 type( e.getKeyCode(), e.getKeyChar(), e.getModifiers() );
123 e.consume();
124 }
125
126 public AWTConsole() {
127 this(12, 80, null, null);
128 }
129 public AWTConsole( InputStream in, OutputStream out ) {
130 this(12, 80, in, out);
131 }
132
133 public void type(int code, char ch, int modifiers ) {
134 switch ( code ) {
135 case ( KeyEvent.VK_BACK_SPACE ):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected