ti.swing.console
Class Console

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byti.swing.console.Console
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
ConsoleTextArea

public class Console
extends javax.swing.JPanel

The console is a swing component used to display a character stream. The character stream can be modified via the InputHandler. The console also supports mapping Regions over sections of the character stream. These regions can be used to, for example, apply different attributes over that section of the character stream as its being rendered (for example, different fg or bg color, different font, etc.).

This class is the swing component, it delegates most of the details of managing the console buffer, regions, and rendering the whole thing to the ConsoleBuffer class.

Version:
0.0
Author:
Rob Clark
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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 char CR
           
static char LF
           
 
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(int nrows, int ncols)
          Create a new console with the specified number of rows and cols.
 
Method Summary
 void doLayout()
          After the console is resized, this is called to layout all the sub-components (ie.
 InputHandler getInputHandler()
          Get the input handler for this console.
 java.awt.Dimension getMinimumSize()
          Returns the minimum size Dimension of the Console.
 java.awt.Dimension getPreferredSize()
          Returns the preferred size Dimension of the Console.
protected  void paintComponent(java.awt.Graphics g)
          Paint this component.
protected  void processMouseEvent(java.awt.event.MouseEvent evt)
          We need to intercept the mouse click, and request focus...
 void setFont(java.awt.Font f)
          Sets the current font.
 void setInputHandler(InputHandler ih)
          Set the input handler.
 int toOffset(java.awt.Point p)
          Convert the specified point to offset.
 java.awt.Point toPoint(int offset)
          Convert the specified offset to a point.
 void waitForRedraw()
          Block until the console is repainted.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, getNextFocusableComponent, 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, isValidateRoot, paint, paintBorder, paintChildren, 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, 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, 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, setLayout, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, 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
 

Field Detail

LF

public static final char LF
See Also:
Constant Field Values

CR

public static final char CR
See Also:
Constant Field Values
Constructor Detail

Console

public Console(int nrows,
               int ncols)
Create a new console with the specified number of rows and cols. The number of columns could change as a result of a resize, but the number of rows is fixed.

Parameters:
nrows - the number of rows
ncols - the initial number of cols
Method Detail

getInputHandler

public InputHandler getInputHandler()
Get the input handler for this console. The input handler is the mechanism for modifying the state of the console buffer. The input handler should not be cached!

Returns:
an input handler. This method will NOT return null

setInputHandler

public void setInputHandler(InputHandler ih)
Set the input handler.

Parameters:
ih - set the input handler.

toOffset

public int toOffset(java.awt.Point p)
Convert the specified point to offset. The point is specified in x and y pixel location relative to this component's origin, and the offset is an offset into the character stream.

Parameters:
p - the point
Returns:
the offset into character stream.

toPoint

public java.awt.Point toPoint(int offset)
Convert the specified offset to a point. The offset is an offset into the character stream, and the returned point is an x/y pixel coordinate, relative to this components origin, of the upper left corner of the specified offset.

Parameters:
offset - the offset int character stream
Returns:
a pixel location

setFont

public void setFont(java.awt.Font f)
Sets the current font. This will redraw the component.

Parameters:
f - the font to use as the current font

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size Dimension of the Console.

Returns:
the size

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the minimum size Dimension of the Console.

Returns:
the size

doLayout

public void doLayout()
After the console is resized, this is called to layout all the sub-components (ie. the scrollbars)


processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent evt)
We need to intercept the mouse click, and request focus... probably there is a better way to get focus?


paintComponent

protected void paintComponent(java.awt.Graphics g)
Paint this component.


waitForRedraw

public void waitForRedraw()
Block until the console is repainted.