org.jext.console
Class Console

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JScrollPane
                  extended byorg.jext.console.Console
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.ScrollPaneConstants, java.io.Serializable

public class Console
extends javax.swing.JScrollPane

An internal console which provide different kinds of prompts and which allows to execute both internal and external (OS specific) commands. The console is embedded in a JScrollPane and handles it by itself.

Author:
Romain Guy
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JScrollPane
javax.swing.JScrollPane.AccessibleJScrollPane, javax.swing.JScrollPane.ScrollBar
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String[] DEFAULT_PROMPTS
          Default prompt types: DOS, Jext, Linux and SunOS
static int DOS_PROMPT
          DOS prompt: /export/home/guy >
 java.awt.Color errorColor
           
 java.awt.Color infoColor
           
static int JEXT_PROMPT
          Jext prompt: Gfx@/export/home/guy >
static int LINUX_PROMPT
          Linux prompt: guy@csdlyon$
 java.awt.Color outputColor
           
 java.awt.Color promptColor
           
static int SUNOS_PROMPT
          SunOS prompt: csdlyon%
 
Fields inherited from class javax.swing.JScrollPane
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport
 
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 javax.swing.ScrollPaneConstants
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Console(JextFrame parent)
          Instanciates a new console without displaying prompt.
Console(JextFrame parent, boolean display)
          Creates a new console, embedding it in a JScrollPane.
 
Method Summary
 void add(java.lang.String add)
          Adds a String to the current command line.
 void addCommand(Command command)
          Adds a command to the linked list of commands.
 void addHistory(java.lang.String command)
          Adds a command to the history.
 void append(java.lang.String text, java.awt.Color color)
          This method appends text in the text area.
 void deleteChar()
          Delete a char from command line.
 void displayPrompt()
          Displays the prompt according to the current selected prompt type.
 void doBackwardSearch()
          Search backward in the history for a matching command, according to the command typed in the user typing space.
 void doCompletion()
          Completes current filename if possible.
 void error(java.lang.String display)
          Display a message using error color.
 void execute(java.lang.String command)
          Execute command.
protected  void finalize()
          Patch -> Memory management improvements : it may help the garbage collector.
 javax.swing.text.Document getOutputDocument()
          Return the Document in which output is performed.
 JextFrame getParentFrame()
          Returns this Console's parent.
 java.lang.String getPromptPattern()
          Get prompt pattern.
 java.io.Writer getStdErr()
          Returns a writer in which external classes can send String to make them being displayed in the console as error output.
 java.io.Writer getStdOut()
          Returns a writer in which external classes can send String to make them being displayed in the console as standard output.
 java.lang.String getText()
          Returns current command line.
 int getTypingLocation()
          Returns the position of the end of the console prompt.
 int getUserLimit()
          Returns the position in characters at which user is allowed to type his commands.
 void help()
          Displays console help.
 void help(java.lang.String display)
          Display a message using help color.
 void historyNext()
          Get next item in the history list.
 void historyPrevious()
          Get previous item in the history list.
 void info(java.lang.String display)
          Display a message using information color.
 void load()
          Load the last saved history.
 void output(java.lang.String display)
          Display a message using output color.
 java.lang.String parseCommand(java.lang.String command)
          Parse a command.
 void removeChar()
          Remove a char from current command line.
 void save()
          Save the history.
 void setBgColor(java.awt.Color color)
          Set console background color.
 void setErrorColor(java.awt.Color color)
          Set console error color.
 void setInfoColor(java.awt.Color color)
          Set console info color.
 void setOutputColor(java.awt.Color color)
          Set console output color.
 void setPromptColor(java.awt.Color color)
          Set console prompt color.
 void setPromptPattern(java.lang.String prompt)
          Set the prompt pattern.
 void setSelectionColor(java.awt.Color color)
          Set console selection color.
 void setText(java.lang.String text)
          Set user's command line content.
 void stop()
          Stops current task.
 
Methods inherited from class javax.swing.JScrollPane
createHorizontalScrollBar, createVerticalScrollBar, createViewport, getAccessibleContext, getColumnHeader, getCorner, getHorizontalScrollBar, getHorizontalScrollBarPolicy, getRowHeader, getUI, getUIClassID, getVerticalScrollBar, getVerticalScrollBarPolicy, getViewport, getViewportBorder, getViewportBorderBounds, isValidateRoot, isWheelScrollingEnabled, paramString, setColumnHeader, setColumnHeaderView, setComponentOrientation, setCorner, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setLayout, setRowHeader, setRowHeaderView, setUI, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportBorder, setViewportView, setWheelScrollingEnabled, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DOS_PROMPT

public static final int DOS_PROMPT
DOS prompt: /export/home/guy >

See Also:
Constant Field Values

JEXT_PROMPT

public static final int JEXT_PROMPT
Jext prompt: Gfx@/export/home/guy >

See Also:
Constant Field Values

LINUX_PROMPT

public static final int LINUX_PROMPT
Linux prompt: guy@csdlyon$

See Also:
Constant Field Values

SUNOS_PROMPT

public static final int SUNOS_PROMPT
SunOS prompt: csdlyon%

See Also:
Constant Field Values

DEFAULT_PROMPTS

public static final java.lang.String[] DEFAULT_PROMPTS
Default prompt types: DOS, Jext, Linux and SunOS


errorColor

public java.awt.Color errorColor

promptColor

public java.awt.Color promptColor

outputColor

public java.awt.Color outputColor

infoColor

public java.awt.Color infoColor
Constructor Detail

Console

public Console(JextFrame parent)
Instanciates a new console without displaying prompt.

Parameters:
parent - Jext parent

Console

public Console(JextFrame parent,
               boolean display)
Creates a new console, embedding it in a JScrollPane. By default console help is displayed.

Parameters:
parent - Jext parent
display - If set on true, prompt is displayed
Method Detail

getParentFrame

public JextFrame getParentFrame()
Returns this Console's parent.


getOutputDocument

public javax.swing.text.Document getOutputDocument()
Return the Document in which output is performed.


addCommand

public void addCommand(Command command)
Adds a command to the linked list of commands.


setBgColor

public void setBgColor(java.awt.Color color)
Set console background color.

Parameters:
color - Color to be used

setErrorColor

public void setErrorColor(java.awt.Color color)
Set console error color.

Parameters:
color - Color to be used

setPromptColor

public void setPromptColor(java.awt.Color color)
Set console prompt color.

Parameters:
color - Color to be used

setOutputColor

public void setOutputColor(java.awt.Color color)
Set console output color.

Parameters:
color - Color to be used

setInfoColor

public void setInfoColor(java.awt.Color color)
Set console info color.

Parameters:
color - Color to be used

setSelectionColor

public void setSelectionColor(java.awt.Color color)
Set console selection color.

Parameters:
color - Color to be used

save

public void save()
Save the history.


load

public void load()
Load the last saved history.


setPromptPattern

public void setPromptPattern(java.lang.String prompt)
Set the prompt pattern.


getPromptPattern

public java.lang.String getPromptPattern()
Get prompt pattern.


displayPrompt

public void displayPrompt()
Displays the prompt according to the current selected prompt type.


append

public void append(java.lang.String text,
                   java.awt.Color color)
This method appends text in the text area.

Parameters:
text - The text to append in the text area

addHistory

public void addHistory(java.lang.String command)
Adds a command to the history.

Parameters:
command - Command to add in the history

removeChar

public void removeChar()
Remove a char from current command line. Stands for BACKSPACE action.


deleteChar

public void deleteChar()
Delete a char from command line. Stands for DELETE action.


add

public void add(java.lang.String add)
Adds a String to the current command line.

Parameters:
add - String to be added

getUserLimit

public int getUserLimit()
Returns the position in characters at which user is allowed to type his commands.

Returns:
Beginning of user typing space

getTypingLocation

public int getTypingLocation()
Returns the position of the end of the console prompt.


doCompletion

public void doCompletion()
Completes current filename if possible.


doBackwardSearch

public void doBackwardSearch()
Search backward in the history for a matching command, according to the command typed in the user typing space.


historyPrevious

public void historyPrevious()
Get previous item in the history list.


historyNext

public void historyNext()
Get next item in the history list.


setText

public void setText(java.lang.String text)
Set user's command line content.

Parameters:
text - Text to be put on command line.

getText

public java.lang.String getText()
Returns current command line.


help

public void help()
Displays console help.


info

public void info(java.lang.String display)
Display a message using information color.

Parameters:
display - String to be displayed
Since:
Jext3.2pre4

help

public void help(java.lang.String display)
Display a message using help color.

Parameters:
display - String to be displayed

error

public void error(java.lang.String display)
Display a message using error color.

Parameters:
display - String to be displayed

output

public void output(java.lang.String display)
Display a message using output color.

Parameters:
display - String to be displayed

stop

public void stop()
Stops current task.


parseCommand

public java.lang.String parseCommand(java.lang.String command)
Parse a command. Replace internal variables by their values.

Parameters:
command - Command to be parsed

execute

public void execute(java.lang.String command)
Execute command. First parse it then check if command is built-in. At last, a process is created and threads which handle output streams are started.

Parameters:
command - Command to be execute

getStdOut

public java.io.Writer getStdOut()
Returns a writer in which external classes can send String to make them being displayed in the console as standard output.


getStdErr

public java.io.Writer getStdErr()
Returns a writer in which external classes can send String to make them being displayed in the console as error output.


finalize

protected void finalize()
                 throws java.lang.Throwable
Patch -> Memory management improvements : it may help the garbage collector. -> Author : Julien Ponge (julien@izforge.com) -> Date : 23, May 2001

Throws:
java.lang.Throwable


Copyright © 2002 Romain Guy.