org.freehep.jas.plugin.console
Class Console

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JEditorPane
                      extended by javax.swing.JTextPane
                          extended by org.freehep.jas.plugin.console.Console
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class Console
extends JTextPane

A TextArea that supports terminal like functionality.

Version:
$Id: Console.java 14085 2012-12-13 18:37:19Z tonyj $
Author:
Tony Johnson (tonyj@slac.stanford.edu)
See Also:
Serialized Form

Nested Class Summary
static class Console.AutoShow
           
 
Nested classes/interfaces inherited from class javax.swing.JEditorPane
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JEditorPane
HONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITS
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Console()
          Create a new Console
 
Method Summary
 void addInterruptListener(ActionListener l)
          Adds a listener for CTRL^C events
 void addNotify()
           
protected  void autoShow()
          A method to be called to request that the console "pop up".
 void clear()
          Clears any output from the Console
 void close()
          A method to be called to request that the console be closed.
 void dispose()
          Cleans up resources associated with this console.
protected  void fireInterruptAction()
          Called when CTRL^C is detected.
 Console.AutoShow getAutoShow()
           
 MutableAttributeSet getInputAttributes()
           
 ConsoleInputStream getInputStream()
          Create an input stream for reading user input from the console.
 ConsoleInputStream getInputStream(String initialPrompt)
          Create an input stream for reading user input from the console.
 OutputStream getLogStream()
          Get the current log stream
 int getMaxScrollback()
           
 ConsoleOutputStream getOutputStream(AttributeSet set)
           
 ConsoleOutputStream getOutputStream(AttributeSet set, boolean autoShow)
          Get an output stream for writing to the console.
 Color getPromptColor()
          Getter for property promptColor.
 void insertTextAsIfTypedByUser(String text)
          Insert text (command(s)) as if it were typed by the user.
 boolean isLoggingEnabled()
          Test if logging is currently enabled
 void paste()
           
 void removeInterruptListener(ActionListener l)
          Remove a listener for CTRL^C events.
 void setAutoShow(Console.AutoShow autoShow)
           
 void setLoggingEnabled(boolean log)
          Temporarily disables/enables logging.
 void setLogStream(OutputStream out)
          Sets a stream to use for writing logging output.
 void setMaxScrollback(int maxLines)
           
 void setPromptColor(Color promptColor)
          Setter for property promptColor.
 
Methods inherited from class javax.swing.JTextPane
addStyle, createDefaultEditorKit, getCharacterAttributes, getLogicalStyle, getParagraphAttributes, getStyle, getStyledDocument, getStyledEditorKit, getUIClassID, insertComponent, insertIcon, paramString, removeStyle, replaceSelection, setCharacterAttributes, setDocument, setEditorKit, setLogicalStyle, setParagraphAttributes, setStyledDocument
 
Methods inherited from class javax.swing.JEditorPane
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Console

public Console()
Create a new Console

Method Detail

getInputStream

public ConsoleInputStream getInputStream()
Create an input stream for reading user input from the console. The input stream will use the default prompt.

Returns:
The newly created input stream

getInputStream

public ConsoleInputStream getInputStream(String initialPrompt)
Create an input stream for reading user input from the console.

Parameters:
initialPrompt - The prompt to use for user input
Returns:
The newly created input stream

setLogStream

public void setLogStream(OutputStream out)
Sets a stream to use for writing logging output. All input/output to the console will also be logged to this output stream.

Parameters:
out - The output stream to use, or null to turn off logging.

getLogStream

public OutputStream getLogStream()
Get the current log stream

Returns:
The current log stream, or null if no current stream

setLoggingEnabled

public void setLoggingEnabled(boolean log)
Temporarily disables/enables logging.

Parameters:
log - true to enable logging.

isLoggingEnabled

public boolean isLoggingEnabled()
Test if logging is currently enabled

Returns:
true if logging enabled.

getOutputStream

public ConsoleOutputStream getOutputStream(AttributeSet set,
                                           boolean autoShow)
Get an output stream for writing to the console.

Parameters:
set - The attributes for text created by this output stream, * or null for the default attributes.
autoShow - If true the console will "pop to the front" when new output is written.
Returns:
The newly created output stream

getOutputStream

public ConsoleOutputStream getOutputStream(AttributeSet set)

addInterruptListener

public void addInterruptListener(ActionListener l)
Adds a listener for CTRL^C events

Parameters:
l - The listener to add.

dispose

public void dispose()
Cleans up resources associated with this console. Closes any input or output streams associated with this console.


insertTextAsIfTypedByUser

public void insertTextAsIfTypedByUser(String text)
Insert text (command(s)) as if it were typed by the user. The text will be sent to the Console's input stream. Any text already typed by the user will not be included in the text sent.

Parameters:
text - text to send

paste

public void paste()
Overrides:
paste in class JTextComponent

close

public void close()
A method to be called to request that the console be closed. Typically called by scripting engines when the user types "quit" or the equivalent. This close method does nothing, but is designed to be overridden by subclasses.


autoShow

protected void autoShow()
A method to be called to request that the console "pop up". This method does nothing but is designed to be overridden by subclassses.


removeInterruptListener

public void removeInterruptListener(ActionListener l)
Remove a listener for CTRL^C events.

Parameters:
l - The listener to remove

fireInterruptAction

protected void fireInterruptAction()
Called when CTRL^C is detected. Calls all the registered listeners.


clear

public void clear()
Clears any output from the Console


getInputAttributes

public MutableAttributeSet getInputAttributes()
Overrides:
getInputAttributes in class JTextPane

getPromptColor

public Color getPromptColor()
Getter for property promptColor.

Returns:
Value of property promptColor.

setPromptColor

public void setPromptColor(Color promptColor)
Setter for property promptColor.

Parameters:
promptColor - New value of property promptColor.

getMaxScrollback

public int getMaxScrollback()

setMaxScrollback

public void setMaxScrollback(int maxLines)

getAutoShow

public Console.AutoShow getAutoShow()

setAutoShow

public void setAutoShow(Console.AutoShow autoShow)

addNotify

public void addNotify()
Overrides:
addNotify in class JComponent


Copyright © 2013. All Rights Reserved.