Top Description Fields Constructors Methods
bsh.util

public Class AWTConsole

extends TextArea
implements ConsoleInterface, Runnable, KeyListener
Class Inheritance
All Implemented Interfaces
java.awt.event.KeyListener, java.util.EventListener, java.lang.Runnable, bsh.ConsoleInterface
Imports
java.awt.*, java.awt.event.*, java.io.*, java.util.Vector, bsh.*

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) component with JFC soon... but Swing is still very slow and buggy. Done: see JConsole.java The big Hack: The heinous, disguisting hack in here is to keep the caret (cursor) at the bottom of the text (without the user having to constantly click at the bottom). It wouldn't be so bad if the damned setCaretPostition() worked as expected. But the AWT TextArea for some insane reason treats NLs as characters... oh, and it refuses to let you set a caret position greater than the text length - for which it counts NLs as *one* character. The glorious hack to fix this is to go the TextComponent peer. I really hate this. Out of date: This class is out of date. It does not use the special blocking piped input stream that the jconsole uses. Deprecation: This file uses two deprecate APIs. We want to be a PrintStream so that we can redirect stdout to our console... I don't see a way around this. Also we have to use getPeer() for the big hack above.

Field Summary

Modifier and TypeField and Description
private int
private Vector<E>
private InputStream
private InputStream
private StringBuffer
private PrintStream
private OutputStream
private String
private int
Inherited from java.awt.TextArea:
SCROLLBARS_BOTHSCROLLBARS_HORIZONTAL_ONLYSCROLLBARS_NONESCROLLBARS_VERTICAL_ONLY

Constructor Summary

AccessConstructor and Description
public
AWTConsole(int rows, int cols, InputStream cin, OutputStream cout)

public
public

Method Summary

Modifier and TypeMethod and Description
private void
private int
private void
doChar(char ch)

private void
public void
public PrintStream
public Reader
public PrintStream
private void
private void
private void
public void
keyPressed(KeyEvent
the event to be processed
e
)

Implements java.awt.event.KeyListener.keyPressed.

Invoked when a key has been pressed.
public void
keyReleased(KeyEvent
the event to be processed
e
)

Implements java.awt.event.KeyListener.keyReleased.

Invoked when a key has been released.
public void
keyTyped(KeyEvent
the event to be processed
e
)

Implements java.awt.event.KeyListener.keyTyped.

Invoked when a key has been typed.
public static void
main(String[] args)

public void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public void
setCaretPosition(int
the position of the text insertion caret
pos
)

Overrides java.awt.TextComponent.setCaretPosition.

Sets the position of the text insertion caret.
private void
public String
toString()

Overrides java.awt.Component.toString.

Returns a string representation of this component and its values.
public void
type(int code, char ch, int modifiers)

Inherited from java.awt.TextArea:
addNotifyappendappendTextgetAccessibleContextgetColumnsgetMinimumSizegetMinimumSizegetPreferredSizegetPreferredSizegetRowsgetScrollbarVisibilityinsertinsertTextminimumSizeminimumSizeparamStringpreferredSizepreferredSizereplaceRangereplaceTextsetColumnssetRows

Field Detail

histLineback to summary
private int histLine
historyback to summary
private Vector<E> history
inback to summary
private InputStream in
inPipeback to summary
private InputStream inPipe
lineback to summary
private StringBuffer line
outback to summary
private PrintStream out
outPipeback to summary
private OutputStream outPipe
startedLineback to summary
private String startedLine
textLengthback to summary
private int textLength

Constructor Detail

AWTConsoleback to summary
public AWTConsole(int rows, int cols, InputStream cin, OutputStream cout)
AWTConsoleback to summary
public AWTConsole()
AWTConsoleback to summary
public AWTConsole(InputStream in, OutputStream out)

Method Detail

acceptLineback to summary
private void acceptLine(String line)
countNLsback to summary
private int countNLs()
doCharback to summary
private void doChar(char ch)
enterback to summary
private void enter()
errorback to summary
public void error(Object o)

Implements bsh.ConsoleInterface.error.

getErrback to summary
public PrintStream getErr()

Implements bsh.ConsoleInterface.getErr.

getInback to summary
public Reader getIn()

Implements bsh.ConsoleInterface.getIn.

getOutback to summary
public PrintStream getOut()

Implements bsh.ConsoleInterface.getOut.

historyDownback to summary
private void historyDown()
historyUpback to summary
private void historyUp()
inPipeWatcherback to summary
private void inPipeWatcher() throws IOException
keyPressedback to summary
public void keyPressed(KeyEvent e)

Implements java.awt.event.KeyListener.keyPressed.

Doc from java.awt.event.KeyListener.keyPressed.

Invoked when a key has been pressed. See the class description for KeyEvent for a definition of a key pressed event.

Parameters
e:KeyEvent

the event to be processed

keyReleasedback to summary
public void keyReleased(KeyEvent e)

Implements java.awt.event.KeyListener.keyReleased.

Doc from java.awt.event.KeyListener.keyReleased.

Invoked when a key has been released. See the class description for KeyEvent for a definition of a key released event.

Parameters
e:KeyEvent

the event to be processed

keyTypedback to summary
public void keyTyped(KeyEvent e)

Implements java.awt.event.KeyListener.keyTyped.

Doc from java.awt.event.KeyListener.keyTyped.

Invoked when a key has been typed. See the class description for KeyEvent for a definition of a key typed event.

Parameters
e:KeyEvent

the event to be processed

mainback to summary
public static void main(String[] args)
printlnback to summary
public void println(Object o)

Implements bsh.ConsoleInterface.println.

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

setCaretPositionback to summary
public void setCaretPosition(int pos)

Overrides java.awt.TextComponent.setCaretPosition.

Doc from java.awt.TextComponent.setCaretPosition.

Sets the position of the text insertion caret. The caret position is constrained to be between 0 and the last character of the text, inclusive. If the passed-in value is greater than this range, the value is set to the last character (or 0 if the TextComponent contains no text) and no error is returned. If the passed-in value is less than 0, an IllegalArgumentException is thrown.

Parameters
pos:int

the position of the text insertion caret

showHistoryLineback to summary
private void showHistoryLine()
toStringback to summary
public String toString()

Overrides java.awt.Component.toString.

Doc from java.awt.Component.toString.

Returns a string representation of this component and its values.

Returns:String

a string representation of this component

typeback to summary
public void type(int code, char ch, int modifiers)