edu.neu.ccs.console
Class ConsoleTextPane

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.text.JTextComponent
                  extended byjavax.swing.JEditorPane
                      extended byjavax.swing.JTextPane
                          extended byedu.neu.ccs.console.ConsoleTextPane
All Implemented Interfaces:
Accessible, ImageObserver, JPTConstants, MenuContainer, Scrollable, Serializable, SwingConstants

final class ConsoleTextPane
extends JTextPane
implements JPTConstants, Serializable

A text pane for styled input and output of console text.

This class is used internally by the JPT and should not need to be used outside of the JPT console package.

There was a change between Java 1.4 and Java 5.0 that broke the key handler code in processComponentKeyEvent. After much effort, this method and related code has been rewritten so that it works with both Java 1.4 and Java 5.0 libraries.

In 2.7.0, made the font in the console bold by default for better readability.

Since:
1.0
Version:
2.5.0
See Also:
ConsoleWindow, ConsoleGateway, ConsoleInputListener

Nested Class Summary
 
Nested classes inherited from class javax.swing.JEditorPane
JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Nested classes inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  Style base
          Base style from which all other styles are created.
private  Color[] color
          Rendering colors used for the three streams plus the transparent renderer.
private  StyleContext context
          Style context for styles used in the text pane.
private  int currentstream
          The current stream.
private  DefaultStyledDocument doc
          Styled document used as the data model for the text pane.
private  String endl
          Platform dependent line separator sequence.
static int ERR
          Constant index for the error stream.
private  int fontSize
          The current font size as set by the setFontSize method.
static int IN
          Constant index for the input stream.
protected static int maxFontSize
          The maximum console font size.
protected static int minFontSize
          The minimum console font size.
static int OUT
          Constant index for the output stream.
private  int start
          Caret position indicating the beginning of the current input text.
private  ConsoleWindow window
          Console window containing this text pane.
 
Fields inherited from class javax.swing.JTextPane
 
Fields inherited from class javax.swing.JEditorPane
 
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.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
private ConsoleTextPane()
          Constructs a console text pane ready for modification through the deserialization process.
  ConsoleTextPane(ConsoleWindow w)
          Constructs a console text pane contained by the given console window.
 
Method Summary
 void append(String text, int stream)
          Appends the given text produced by the given output stream to the end of the text pane content.
private  void beep()
          Sounds the default system beep.
 void cut()
          Cuts the currently selected text out of the pane and stores it on the system clipboard, but only if the selected text is completely enclosed within the bounds of the current input text.
private  void fireConsoleInputPerformed(String text)
          Notifies registered listeners that an input String was gathered by console input.
 Color getErrorColor()
          Returns the current error color for this pane.
 String getFontFamilyName()
          Returns the font family name of the console font.
 int getFontSize()
          Returns the actual font size last set by the method setFontSize after any adjustments.
 Color getInputColor()
          Returns the current input color for this pane.
static int getMaximumFontSize()
          Get the maximum font size that may be set for the console window.
static int getMinimumFontSize()
          Get the minimum font size that may be set for the console window.
 Color getOutputColor()
          Returns the current output color for this pane.
private  Style getStyleFor(int stream)
          Returns the appropriate rendering style for the given stream.
 void paste()
          Pastes the clipboard contents into the pane at the current caret position, but only if the caret position or selection is completely enclosed within the bounds of the current input text.
 void processComponentKeyEvent(KeyEvent evt)
          Handles a key event trapped by the text pane.
 void replaceSelection(String text)
          Replaces the currently selected text with the given text, but only if the selected text is completely enclosed within the bounds of the current input text.
 void setErrorColor(Color c)
          Sets the current error color for this pane to the given color.
 void setFontSize(int size)
          Sets the font size for the entire pane to the given point size modulo adjustments.
 void setInputColor(Color c)
          Sets the current input color for this pane to the given color.
 void setOutputColor(Color c)
          Sets the current output color for this pane to the given color.
 void setStream(int stream)
          Sets the currently active stream for the console.
 
Methods inherited from class javax.swing.JTextPane
addStyle, createDefaultEditorKit, getCharacterAttributes, getInputAttributes, getLogicalStyle, getParagraphAttributes, getStyle, getStyledDocument, getStyledEditorKit, getUIClassID, insertComponent, insertIcon, paramString, removeStyle, 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, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
 
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, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, 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, 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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OUT

public static final int OUT
Constant index for the output stream.

See Also:
Constant Field Values

ERR

public static final int ERR
Constant index for the error stream.

See Also:
Constant Field Values

IN

public static final int IN
Constant index for the input stream.

See Also:
Constant Field Values

endl

private transient String endl
Platform dependent line separator sequence.


start

private int start
Caret position indicating the beginning of the current input text.


context

private StyleContext context
Style context for styles used in the text pane.


doc

private DefaultStyledDocument doc
Styled document used as the data model for the text pane.


base

private Style base
Base style from which all other styles are created.


color

private Color[] color
Rendering colors used for the three streams plus the transparent renderer.


window

private ConsoleWindow window
Console window containing this text pane.


currentstream

private int currentstream
The current stream.


minFontSize

protected static final int minFontSize
The minimum console font size.

See Also:
Constant Field Values

maxFontSize

protected static final int maxFontSize
The maximum console font size.

See Also:
Constant Field Values

fontSize

private int fontSize
The current font size as set by the setFontSize method.

Constructor Detail

ConsoleTextPane

private ConsoleTextPane()
Constructs a console text pane ready for modification through the deserialization process.


ConsoleTextPane

public ConsoleTextPane(ConsoleWindow w)
Constructs a console text pane contained by the given console window.

Parameters:
w - the console window to contain the new pane
Method Detail

processComponentKeyEvent

public void processComponentKeyEvent(KeyEvent evt)
Handles a key event trapped by the text pane.

Parameters:
evt - the trapped key event

append

public void append(String text,
                   int stream)
Appends the given text produced by the given output stream to the end of the text pane content.

Parameters:
text - the text to append to the pane
stream - the identifier of the stream that produced the text
See Also:
replaceSelection(String)

replaceSelection

public void replaceSelection(String text)
Replaces the currently selected text with the given text, but only if the selected text is completely enclosed within the bounds of the current input text.

Parameters:
text - the text with which to replace the selected text
See Also:
append(String, int)

cut

public void cut()
Cuts the currently selected text out of the pane and stores it on the system clipboard, but only if the selected text is completely enclosed within the bounds of the current input text.

See Also:
paste()

paste

public void paste()
Pastes the clipboard contents into the pane at the current caret position, but only if the caret position or selection is completely enclosed within the bounds of the current input text.

See Also:
cut()

getFontFamilyName

public final String getFontFamilyName()
Returns the font family name of the console font.


getFontSize

public final int getFontSize()

Returns the actual font size last set by the method setFontSize after any adjustments.


getMinimumFontSize

public static final int getMinimumFontSize()
Get the minimum font size that may be set for the console window.


getMaximumFontSize

public static final int getMaximumFontSize()
Get the maximum font size that may be set for the console window.


setFontSize

public final void setFontSize(int size)

Sets the font size for the entire pane to the given point size modulo adjustments. The font size is forced between a minimum of 10 and a maximum of 72.

Parameters:
size - the desired font size

setStream

public void setStream(int stream)
Sets the currently active stream for the console. Used to differentiate the state when input is being accepted from the state when output is being appended.

Parameters:
stream - the active stream for the console which must equal OUT, ERR, or IN

setInputColor

public void setInputColor(Color c)
Sets the current input color for this pane to the given color. Sets to black if the given color is null.

Parameters:
c - the desired input color
See Also:
getInputColor()

getInputColor

public Color getInputColor()
Returns the current input color for this pane.

See Also:
setInputColor(Color)

setOutputColor

public void setOutputColor(Color c)
Sets the current output color for this pane to the given color. Sets to black if the given color is null.

Parameters:
c - the desired output color
See Also:
getOutputColor()

getOutputColor

public Color getOutputColor()
Returns the current output color for this pane.

See Also:
setOutputColor(Color)

setErrorColor

public void setErrorColor(Color c)
Sets the current error color for this pane to the given color. Sets to black if the given color is null.

Parameters:
c - the desired error color
See Also:
getErrorColor()

getErrorColor

public Color getErrorColor()
Returns the current error color for this pane.

See Also:
setErrorColor(Color)

fireConsoleInputPerformed

private void fireConsoleInputPerformed(String text)
Notifies registered listeners that an input String was gathered by console input.

Parameters:
text - the gathered input String
See Also:
ConsoleInputListener

getStyleFor

private Style getStyleFor(int stream)
Returns the appropriate rendering style for the given stream.

Parameters:
stream - the stream to be rendered

beep

private void beep()
Sounds the default system beep. This method is no longer used in this class but is retained for possible future use.