wyvern.common.util
Class TextDisplay

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bywyvern.common.util.TextDisplay
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class TextDisplay
extends java.awt.Canvas

A super-lightweight replacement for java.awt.TextArea that lets you change the font + color for each line you append. Read-only, append-only. Supports line-wrap. Only supports a single font size and style for the entire document. You should normally use a wyvern.common.util.ColorTextArea, which maintains a TextDisplay in a ScrollPane.

Version:
1.0, Apr 3, 2002
Author:
Steve Yegge
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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
TextDisplay(java.awt.Frame frame, ColorTextArea parent)
          Constructs a new TextDisplay within a ColorTextArea.
 
Method Summary
 void addDisplayLine(wyvern.common.util.TextDisplay.Line line)
          Adds a display line, nuking any linefeeds, since they show up as weird characters on the handhelds.
 void append(java.lang.String text)
          Appends a string in black.
 void append(java.lang.String text, java.awt.Color color)
          Appends text in the specified color.
 void checkLinefeeds(wyvern.common.util.TextDisplay.Line line)
          Breaks a complete line at linefeeds.
 int chopLine(java.lang.String text, java.awt.FontMetrics fm, int width)
          Chops a line mid-word.
static void debug(java.lang.String msg)
          Prints debugging message.
 void drawBackgroundImage(java.awt.Graphics g)
          Tiles the background image into the text area.
 void ensureBuffers()
          Makes sure our buffer is the size of our bounds.
 int getDisplayLines()
          Returns the number of display lines in our history buffer.
 java.awt.Dimension getMinimumSize()
          Returns minimum size.
 java.awt.Dimension getPreferredSize()
          Returns preferred size.
 int getVisibleLines()
          Returns the number of lines we can see on the screen in the given font.
 void paint(java.awt.Graphics g)
          Draws the text.
 void resetBounds()
          Redoes our geometry.
 void rewrapLines()
          Recomputes the display lines from the text lines.
 void setBackground(java.awt.Color color)
          Sets background color.
 void setBackgroundImage(java.awt.Image img)
          Sets background
 void setFont(java.awt.Font f)
          Sets a new font, re-wrapping the lines.
 void setMaxLines(int lines)
          Sets the maximum number of lines we'll display before starting to remove them from the top.
 void setScrollPosition(int line)
          Sets the display line we're currently scrolled to.
 void setText(java.lang.String text)
          Replaces the text.
 void setText(java.lang.String text, java.awt.Color color)
          Replaces all the text with a new string in the specified color.
 void update(java.awt.Graphics g)
          Avoids flicker.
 void wrapLine(wyvern.common.util.TextDisplay.Line line)
          Wraps a single line of text to fit in the display.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextDisplay

public TextDisplay(java.awt.Frame frame,
                   ColorTextArea parent)
Constructs a new TextDisplay within a ColorTextArea.

Method Detail

setMaxLines

public void setMaxLines(int lines)
Sets the maximum number of lines we'll display before starting to remove them from the top.


getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns minimum size.


getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns preferred size.


setBackground

public void setBackground(java.awt.Color color)
Sets background color.


setBackgroundImage

public void setBackgroundImage(java.awt.Image img)
Sets background


setFont

public void setFont(java.awt.Font f)
Sets a new font, re-wrapping the lines.


append

public void append(java.lang.String text)
Appends a string in black.


append

public void append(java.lang.String text,
                   java.awt.Color color)
Appends text in the specified color.


resetBounds

public void resetBounds()
Redoes our geometry.


ensureBuffers

public void ensureBuffers()
Makes sure our buffer is the size of our bounds.


setScrollPosition

public void setScrollPosition(int line)
Sets the display line we're currently scrolled to.


setText

public void setText(java.lang.String text)
Replaces the text.


setText

public void setText(java.lang.String text,
                    java.awt.Color color)
Replaces all the text with a new string in the specified color.


wrapLine

public void wrapLine(wyvern.common.util.TextDisplay.Line line)
Wraps a single line of text to fit in the display. Adds the resulting pieces to displayLines_.


chopLine

public int chopLine(java.lang.String text,
                    java.awt.FontMetrics fm,
                    int width)
Chops a line mid-word.

Returns:
the position to chop at

checkLinefeeds

public void checkLinefeeds(wyvern.common.util.TextDisplay.Line line)
Breaks a complete line at linefeeds.


addDisplayLine

public void addDisplayLine(wyvern.common.util.TextDisplay.Line line)
Adds a display line, nuking any linefeeds, since they show up as weird characters on the handhelds.


rewrapLines

public void rewrapLines()
Recomputes the display lines from the text lines. Called (somehow) when width changes.


update

public void update(java.awt.Graphics g)
Avoids flicker.


paint

public void paint(java.awt.Graphics g)
Draws the text.


drawBackgroundImage

public void drawBackgroundImage(java.awt.Graphics g)
Tiles the background image into the text area.


getDisplayLines

public int getDisplayLines()
Returns the number of display lines in our history buffer.


getVisibleLines

public int getVisibleLines()
Returns the number of lines we can see on the screen in the given font.


debug

public static void debug(java.lang.String msg)
Prints debugging message.