Top Description Inners Fields Constructors Methods
bsh.util

public Class JConsole

extends JScrollPane
implements GUIConsoleInterface, Runnable, KeyListener, MouseListener, ActionListener, PropertyChangeListener
Class Inheritance
All Implemented Interfaces
java.beans.PropertyChangeListener, java.util.EventListener, java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.KeyListener, java.lang.Runnable, bsh.util.GUIConsoleInterface, bsh.ConsoleInterface
Imports
java.awt.Component, .Font, .Color, .Insets, .Cursor, java.awt.event.*, java.beans.PropertyChangeEvent, .PropertyChangeListener, java.io.*, java.util.Vector, javax.swing.text.*, javax.swing.*, bsh.util.NameCompletion

A JFC/Swing based console for the BeanShell desktop. This is a descendant of the old AWTConsole. Improvements by: Mark Donszelmann including Cut & Paste Improvements by: Daniel Leuck including Color and Image support, key press bug workaround

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
JConsole.BlockingPipedInputStream

The overridden read method in this class will not throw "Broken pipe" IOExceptions; It will simply wait for new writers and data.

Field Summary

Modifier and TypeField and Description
private int
private static final String
private static final String
private DefaultStyledDocument
private boolean
private int
private Vector<E>
private InputStream
private InputStream
pack-priv NameCompletion
private PrintStream
private OutputStream
private static final String
pack-priv final int
private String
private JTextPane
pack-priv String
Inherited from javax.swing.JScrollPane:
columnHeaderhorizontalScrollBarhorizontalScrollBarPolicylowerLeftlowerRightrowHeaderupperLeftupperRightverticalScrollBarverticalScrollBarPolicyviewport

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
actionPerformed(ActionEvent
the event to be processed
event
)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.
private void
append(String string)

private void
private void
public void
private void
private void
private String
public PrintStream
public Reader
public InputStream
public PrintStream
private AttributeSet
private void
private void
private void
private void
invokeAndWait(Runnable run)

If not in the event thread run via SwingUtilities.invokeAndWait()

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 void
mouseClicked(MouseEvent
the event to be processed
event
)

Implements java.awt.event.MouseListener.mouseClicked.

Invoked when the mouse button has been clicked (pressed and released) on a component.
public void
mouseEntered(MouseEvent
the event to be processed
event
)

Implements java.awt.event.MouseListener.mouseEntered.

Invoked when the mouse enters a component.
public void
mouseExited(MouseEvent
the event to be processed
event
)

Implements java.awt.event.MouseListener.mouseExited.

Invoked when the mouse exits a component.
public void
mousePressed(MouseEvent
the event to be processed
event
)

Implements java.awt.event.MouseListener.mousePressed.

Invoked when a mouse button has been pressed on a component.
public void
mouseReleased(MouseEvent
the event to be processed
event
)

Implements java.awt.event.MouseListener.mouseReleased.

Invoked when a mouse button has been released on a component.
public void
public void
println()

Prints "\\n" (i.e. newline)

public void
println(Icon icon)

public void
propertyChange(PropertyChangeEvent
A PropertyChangeEvent object describing the event source and the property that has changed.
event
)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.
private String
replaceRange(Object s, int start, int end)

public void
requestFocus()

Overrides javax.swing.JComponent.requestFocus.

Requests that this Component gets the input focus.
private void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public void
setFont(Font
the desired Font for this component
font
)

Overrides javax.swing.JComponent.setFont.

Sets the font for this component.
public void
private AttributeSet
setStyle(Font font)

private AttributeSet
setStyle(Color color)

private AttributeSet
setStyle(Font font, Color color)

private AttributeSet
setStyle(String fontFamilyName, int size, Color color)

private AttributeSet
setStyle(String fontFamilyName, int size, Color color, boolean bold, boolean italic, boolean underline)

private void
setStyle(AttributeSet attributes)

private void
setStyle(AttributeSet attributes, boolean overWrite)

public void
setWaitFeedback(boolean on)

Implements bsh.util.GUIConsoleInterface.setWaitFeedback.

e.g. the wait cursor
private void
private int
public String
toString()

Overrides java.awt.Component.toString.

Returns a string representation of this component and its values.
private synchronized void
Inherited from javax.swing.JScrollPane:
createHorizontalScrollBarcreateVerticalScrollBarcreateViewportgetAccessibleContextgetColumnHeadergetCornergetHorizontalScrollBargetHorizontalScrollBarPolicygetRowHeadergetUIgetUIClassIDgetVerticalScrollBargetVerticalScrollBarPolicygetViewportgetViewportBordergetViewportBorderBoundsisValidateRootisWheelScrollingEnabledparamStringsetColumnHeadersetColumnHeaderViewsetComponentOrientationsetCornersetHorizontalScrollBarsetHorizontalScrollBarPolicysetLayoutsetRowHeadersetRowHeaderViewsetUIsetVerticalScrollBarsetVerticalScrollBarPolicysetViewportsetViewportBordersetViewportViewsetWheelScrollingEnabledupdateUI

Field Detail

cmdStartback to summary
private int cmdStart
COPYback to summary
private static final String COPY
CUTback to summary
private static final String CUT
docback to summary
private DefaultStyledDocument doc
gotUpback to summary
private boolean gotUp
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
nameCompletionback to summary
pack-priv NameCompletion nameCompletion
outback to summary
private PrintStream out
outPipeback to summary
private OutputStream outPipe
PASTEback to summary
private static final String PASTE
SHOW_AMBIG_MAXback to summary
pack-priv final int SHOW_AMBIG_MAX
startedLineback to summary
private String startedLine
textback to summary
private JTextPane text
ZEROSback to summary
pack-priv String ZEROS

Constructor Detail

JConsoleback to summary
public JConsole()
JConsoleback to summary
public JConsole(InputStream cin, OutputStream cout)

Method Detail

acceptLineback to summary
private void acceptLine(String line)
actionPerformedback to summary
public void actionPerformed(ActionEvent event)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Parameters
event:ActionEvent

the event to be processed

appendback to summary
private void append(String string)
doCommandCompletionback to summary
private void doCommandCompletion(String part)
enterback to summary
private void enter()
errorback to summary
public void error(Object o)

Implements bsh.ConsoleInterface.error.

forceCaretMoveToEndback to summary
private void forceCaretMoveToEnd()
forceCaretMoveToStartback to summary
private void forceCaretMoveToStart()
getCmdback to summary
private String getCmd()
getErrback to summary
public PrintStream getErr()

Implements bsh.ConsoleInterface.getErr.

getInback to summary
public Reader getIn()

Implements bsh.ConsoleInterface.getIn.

getInputStreamback to summary
public InputStream getInputStream()
getOutback to summary
public PrintStream getOut()

Implements bsh.ConsoleInterface.getOut.

getStyleback to summary
private AttributeSet getStyle()
historyDownback to summary
private void historyDown()
historyUpback to summary
private void historyUp()
inPipeWatcherback to summary
private void inPipeWatcher() throws IOException
invokeAndWaitback to summary
private void invokeAndWait(Runnable run)

If not in the event thread run via SwingUtilities.invokeAndWait()

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

mouseClickedback to summary
public void mouseClicked(MouseEvent event)

Implements java.awt.event.MouseListener.mouseClicked.

Doc from java.awt.event.MouseListener.mouseClicked.

Invoked when the mouse button has been clicked (pressed and released) on a component.

Parameters
event:MouseEvent

the event to be processed

mouseEnteredback to summary
public void mouseEntered(MouseEvent event)

Implements java.awt.event.MouseListener.mouseEntered.

Doc from java.awt.event.MouseListener.mouseEntered.

Invoked when the mouse enters a component.

Parameters
event:MouseEvent

the event to be processed

mouseExitedback to summary
public void mouseExited(MouseEvent event)

Implements java.awt.event.MouseListener.mouseExited.

Doc from java.awt.event.MouseListener.mouseExited.

Invoked when the mouse exits a component.

Parameters
event:MouseEvent

the event to be processed

mousePressedback to summary
public void mousePressed(MouseEvent event)

Implements java.awt.event.MouseListener.mousePressed.

Doc from java.awt.event.MouseListener.mousePressed.

Invoked when a mouse button has been pressed on a component.

Parameters
event:MouseEvent

the event to be processed

mouseReleasedback to summary
public void mouseReleased(MouseEvent event)

Implements java.awt.event.MouseListener.mouseReleased.

Doc from java.awt.event.MouseListener.mouseReleased.

Invoked when a mouse button has been released on a component.

Parameters
event:MouseEvent

the event to be processed

printlnback to summary
public void println(Object o)

Implements bsh.ConsoleInterface.println.

printlnback to summary
public void println()

Prints "\\n" (i.e. newline)

printlnback to summary
public void println(Icon icon)
propertyChangeback to summary
public void propertyChange(PropertyChangeEvent event)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

Parameters
event:PropertyChangeEvent

A PropertyChangeEvent object describing the event source and the property that has changed.

replaceRangeback to summary
private String replaceRange(Object s, int start, int end)
requestFocusback to summary
public void requestFocus()

Overrides javax.swing.JComponent.requestFocus.

Doc from javax.swing.JComponent.requestFocus.

Requests that this Component gets the input focus. Refer to Component.requestFocus() for a complete description of this method.

Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow(). If you would like more information on focus, see How to Use the Focus Subsystem, a section in The Java Tutorial.

resetCommandStartback to summary
private void resetCommandStart()
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

setFontback to summary
public void setFont(Font font)

Overrides javax.swing.JComponent.setFont.

Doc from javax.swing.JComponent.setFont.

Sets the font for this component.

Parameters
font:Font

the desired Font for this component

setNameCompletionback to summary
public void setNameCompletion(NameCompletion nc)

Implements bsh.util.GUIConsoleInterface.setNameCompletion.

setStyleback to summary
private AttributeSet setStyle(Font font)
setStyleback to summary
private AttributeSet setStyle(Color color)
setStyleback to summary
private AttributeSet setStyle(Font font, Color color)
setStyleback to summary
private AttributeSet setStyle(String fontFamilyName, int size, Color color)
setStyleback to summary
private AttributeSet setStyle(String fontFamilyName, int size, Color color, boolean bold, boolean italic, boolean underline)
setStyleback to summary
private void setStyle(AttributeSet attributes)
setStyleback to summary
private void setStyle(AttributeSet attributes, boolean overWrite)
setWaitFeedbackback to summary
public void setWaitFeedback(boolean on)

Implements bsh.util.GUIConsoleInterface.setWaitFeedback.

Doc from bsh.util.GUIConsoleInterface.setWaitFeedback.

e.g. the wait cursor

showHistoryLineback to summary
private void showHistoryLine()
textLengthback to summary
private int textLength()
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
private synchronized void type(KeyEvent e)
bsh.util back to summary

public Class JConsole.BlockingPipedInputStream

extends PipedInputStream
Class Inheritance

The overridden read method in this class will not throw "Broken pipe" IOExceptions; It will simply wait for new writers and data. This is used by the JConsole internal read thread to allow writers in different (and in particular ephemeral) threads to write to the pipe. It also checks a little more frequently than the original read().

Warning

read() will not even error on a read to an explicitly closed pipe (override closed to for that).

Field Summary

Modifier and TypeField and Description
pack-priv boolean
Inherited from java.io.PipedInputStream:
bufferinoutPIPE_SIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.PipedInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.
public synchronized int
read()

Overrides java.io.PipedInputStream.read.

Reads the next byte of data from this piped input stream.
Inherited from java.io.PipedInputStream:
availableconnectreadreceive

Field Detail

closedback to summary
pack-priv boolean closed

Constructor Detail

BlockingPipedInputStreamback to summary
public BlockingPipedInputStream(PipedOutputStream pout) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.PipedInputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.PipedInputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Exceptions
IOException:
if an I/O error occurs.
readback to summary
public synchronized int read() throws IOException

Overrides java.io.PipedInputStream.read.

Doc from java.io.PipedInputStream.read.

Reads the next byte of data from this piped input stream. The value byte is returned as an int in the range 0 to 255. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Exceptions
IOException:
if the pipe is unconnected, broken, closed, or if an I/O error occurs.