de.mud.terminal
Class SwingTerminal

java.lang.Object
  |
  +--java.awt.Component
        |
        +--de.mud.terminal.SwingTerminal
All Implemented Interfaces:
java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.KeyListener, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, VDUDisplay

public class SwingTerminal
extends java.awt.Component
implements VDUDisplay, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Video Display Unit emulation for Swing/AWT. This class implements all necessary features of a character display unit, but not the actual terminal emulation. It can be used as the base for terminal emulations of any kind.

This is a lightweight component. It will render very badly if used in standard AWT components without overloaded update() method. The update() method must call paint() immediately without clearing the components graphics context or parts of the screen will simply disappear.

Maintainer: Matthias L. Jugel

Version:
$Id: SwingTerminal.java,v 2.2 2003/04/27 16:36:45 marcus Exp $
Author:
Matthias L. Jugel, Marcus Meißner
See Also:
Serialized Form

Field Summary
static int COLOR_BOLD
           
static int COLOR_INVERT
           
static int RESIZE_FONT
           
static int RESIZE_NONE
           
static int RESIZE_SCREEN
           
 
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
SwingTerminal(VDUBuffer buffer)
          Create a display unit with size 80x24 and Font "Monospaced", size 12.
SwingTerminal(VDUBuffer buffer, java.awt.Font font)
          Create a new video display unit with the passed width and height in characters using a special font and font size.
 
Method Summary
 void addFocusListener(java.awt.event.FocusListener listener)
           
 void addKeyListener(java.awt.event.KeyListener listener)
          Add a key listener to the VDU.
 void addMouseListener(java.awt.event.MouseListener listener)
          Add a mouse listener to the VDU.
 void addMouseMotionListener(java.awt.event.MouseMotionListener listener)
          Add a mouse motion listener to the VDU.
 void clearSelection()
           
 java.awt.Color[] getColorSet()
          Get current color set.
 java.awt.Insets getInsets()
          The insets of the character display define the border.
 java.awt.Dimension getPreferredSize()
          Return the preferred Size of the character display.
 java.lang.String getSelection()
           
 java.awt.Dimension getSize()
          Return the real size in points of the character display.
 VDUBuffer getVDUBuffer()
          Return the currently associated VDUBuffer.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
protected  double max(double f1, double f2)
           
protected  double min(double f1, double f2)
           
 void mouseClicked(java.awt.event.MouseEvent evt)
           
 void mouseDragged(java.awt.event.MouseEvent evt)
           
 void mouseEntered(java.awt.event.MouseEvent evt)
           
 void mouseExited(java.awt.event.MouseEvent evt)
           
 java.awt.Point mouseGetPos(java.awt.Point evtpt)
          Convert Mouse Event coordinates into character cell coordinates
 void mouseMoved(java.awt.event.MouseEvent evt)
           
 void mousePressed(java.awt.event.MouseEvent evt)
          Handle mouse pressed events for copy & paste.
 void mouseReleased(java.awt.event.MouseEvent evt)
          Handle mouse released events for copy & paste.
 void paint(java.awt.Graphics g)
          Paint the current screen using the backing store image.
 void print(java.awt.Graphics g)
           
 void processFocusEvent(java.awt.event.FocusEvent evt)
           
 void processKeyEvent(java.awt.event.KeyEvent evt)
          Process key events for this component.
 void processMouseEvent(java.awt.event.MouseEvent evt)
          Process mouse events for this component.
 void processMouseMotionEvent(java.awt.event.MouseEvent evt)
          Process mouse motion events for this component.
 void redraw()
          Redraw marked lines.
protected  void redraw(java.awt.Graphics g)
           
 void removeFocusListener(java.awt.event.FocusListener listener)
           
 void removeKeyListener(java.awt.event.KeyListener listener)
          Remove key listener from the VDU.
 void removeMouseListener(java.awt.event.MouseListener listener)
          Remove a mouse listener to the VDU.
 void removeMouseMotionListener(java.awt.event.MouseMotionListener listener)
          Remove a mouse motion listener to the VDU.
 void setBorder(int thickness, boolean raised)
          Set the border thickness and the border type.
 void setBounds(int x, int y, int w, int h)
          Reshape character display according to resize strategy.
 void setColorPrinting(boolean colorPrint)
          Set default for printing black&white or colorized as displayed on screen.
 void setColorSet(java.awt.Color[] colorset)
          Set new color set for the display.
 void setCursorColors(java.awt.Color fg, java.awt.Color bg)
          Set cursor FG and BG colors
 void setFont(java.awt.Font font)
          Set the font to be used for rendering the characters on screen.
 void setResizeStrategy(int strategy)
          Set the strategy when window is resized.
 void setScrollbar(javax.swing.JScrollBar scrollBar)
          Connect a scrollbar to the VDU.
 void setVDUBuffer(VDUBuffer buffer)
          Set a new terminal (VDU) buffer.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseWheelListener, addNotify, 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, getAccessibleContext, 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, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, 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, printAll, processComponentEvent, processEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RESIZE_NONE

public static final int RESIZE_NONE
See Also:
Constant Field Values

RESIZE_FONT

public static final int RESIZE_FONT
See Also:
Constant Field Values

RESIZE_SCREEN

public static final int RESIZE_SCREEN
See Also:
Constant Field Values

COLOR_BOLD

public static final int COLOR_BOLD
See Also:
Constant Field Values

COLOR_INVERT

public static final int COLOR_INVERT
See Also:
Constant Field Values
Constructor Detail

SwingTerminal

public SwingTerminal(VDUBuffer buffer,
                     java.awt.Font font)
Create a new video display unit with the passed width and height in characters using a special font and font size. These features can be set independently using the appropriate properties.

Parameters:
buffer - a VDU buffer to be associated with the display
font - the font to be used (usually Monospaced)

SwingTerminal

public SwingTerminal(VDUBuffer buffer)
Create a display unit with size 80x24 and Font "Monospaced", size 12.

Method Detail

max

protected double max(double f1,
                     double f2)

min

protected double min(double f1,
                     double f2)

setVDUBuffer

public void setVDUBuffer(VDUBuffer buffer)
Set a new terminal (VDU) buffer.

Specified by:
setVDUBuffer in interface VDUDisplay
Parameters:
buffer - new buffer

getVDUBuffer

public VDUBuffer getVDUBuffer()
Return the currently associated VDUBuffer.

Specified by:
getVDUBuffer in interface VDUDisplay
Returns:
the current buffer

setColorSet

public void setColorSet(java.awt.Color[] colorset)
Set new color set for the display.

Parameters:
colorset - new color set

getColorSet

public java.awt.Color[] getColorSet()
Get current color set.

Returns:
the color set currently associated

setFont

public void setFont(java.awt.Font font)
Set the font to be used for rendering the characters on screen.

Overrides:
setFont in class java.awt.Component
Parameters:
font - the new font to be used.

setResizeStrategy

public void setResizeStrategy(int strategy)
Set the strategy when window is resized. RESIZE_FONT is default.

Parameters:
strategy - the strategy
See Also:
RESIZE_NONE, RESIZE_FONT, RESIZE_SCREEN

setBorder

public void setBorder(int thickness,
                      boolean raised)
Set the border thickness and the border type.

Parameters:
thickness - border thickness in pixels, zero means no border
raised - a boolean indicating a raised or embossed border

setScrollbar

public void setScrollbar(javax.swing.JScrollBar scrollBar)
Connect a scrollbar to the VDU. This should be done differently using a property change listener.

Parameters:
scrollBar - the scroll bar

redraw

public void redraw()
Redraw marked lines.

Specified by:
redraw in interface VDUDisplay

redraw

protected void redraw(java.awt.Graphics g)

paint

public void paint(java.awt.Graphics g)
Paint the current screen using the backing store image.

Overrides:
paint in class java.awt.Component

setColorPrinting

public void setColorPrinting(boolean colorPrint)
Set default for printing black&white or colorized as displayed on screen.

Parameters:
colorPrint - true = print in full color, default b&w only

print

public void print(java.awt.Graphics g)
Overrides:
print in class java.awt.Component

mouseGetPos

public java.awt.Point mouseGetPos(java.awt.Point evtpt)
Convert Mouse Event coordinates into character cell coordinates

Parameters:
evtpt - the mouse point to be converted
Returns:
Character cell coordinate of passed point

setCursorColors

public void setCursorColors(java.awt.Color fg,
                            java.awt.Color bg)
Set cursor FG and BG colors

Parameters:
fg - foreground color or null
bg - background color or null

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Reshape character display according to resize strategy.

Overrides:
setBounds in class java.awt.Component
See Also:
setResizeStrategy(int)

getSize

public java.awt.Dimension getSize()
Return the real size in points of the character display.

Overrides:
getSize in class java.awt.Component
Returns:
Dimension the dimension of the display
See Also:
Dimension

getPreferredSize

public java.awt.Dimension getPreferredSize()
Return the preferred Size of the character display. This turns out to be the actual size.

Overrides:
getPreferredSize in class java.awt.Component
Returns:
Dimension dimension of the display
See Also:
Component.size()

getInsets

public java.awt.Insets getInsets()
The insets of the character display define the border.

Returns:
Insets border thickness in pixels

clearSelection

public void clearSelection()

getSelection

public java.lang.String getSelection()

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent evt)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent evt)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Handle mouse pressed events for copy & paste.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
evt - the event that occured
See Also:
MouseEvent

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Handle mouse released events for copy & paste.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
evt - the mouse event

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

addMouseListener

public void addMouseListener(java.awt.event.MouseListener listener)
Add a mouse listener to the VDU. This is the implementation for the lightweight event handling.

Overrides:
addMouseListener in class java.awt.Component
Parameters:
listener - the new mouse listener

removeMouseListener

public void removeMouseListener(java.awt.event.MouseListener listener)
Remove a mouse listener to the VDU. This is the implementation for the lightweight event handling.

Overrides:
removeMouseListener in class java.awt.Component
Parameters:
listener - the mouse listener to remove

addMouseMotionListener

public void addMouseMotionListener(java.awt.event.MouseMotionListener listener)
Add a mouse motion listener to the VDU. This is the implementation for the lightweight event handling.

Overrides:
addMouseMotionListener in class java.awt.Component
Parameters:
listener - the mouse motion listener

removeMouseMotionListener

public void removeMouseMotionListener(java.awt.event.MouseMotionListener listener)
Remove a mouse motion listener to the VDU. This is the implementation for the lightweight event handling.

Overrides:
removeMouseMotionListener in class java.awt.Component
Parameters:
listener - the mouse motion listener to remove

processMouseEvent

public void processMouseEvent(java.awt.event.MouseEvent evt)
Process mouse events for this component. It will call the methods (mouseClicked() etc) in the added mouse listeners.

Overrides:
processMouseEvent in class java.awt.Component
Parameters:
evt - the dispatched mouse event

processMouseMotionEvent

public void processMouseMotionEvent(java.awt.event.MouseEvent evt)
Process mouse motion events for this component. It will call the methods (mouseDragged() etc) in the added mouse motion listeners.

Overrides:
processMouseMotionEvent in class java.awt.Component
Parameters:
evt - the dispatched mouse event

addKeyListener

public void addKeyListener(java.awt.event.KeyListener listener)
Add a key listener to the VDU. This is necessary to be able to receive keyboard input from this component. It is a prerequisite for a lightweigh component.

Overrides:
addKeyListener in class java.awt.Component
Parameters:
listener - the key listener

removeKeyListener

public void removeKeyListener(java.awt.event.KeyListener listener)
Remove key listener from the VDU. It is a prerequisite for a lightweigh component.

Overrides:
removeKeyListener in class java.awt.Component
Parameters:
listener - the key listener to remove

processKeyEvent

public void processKeyEvent(java.awt.event.KeyEvent evt)
Process key events for this component.

Overrides:
processKeyEvent in class java.awt.Component
Parameters:
evt - the dispatched key event

addFocusListener

public void addFocusListener(java.awt.event.FocusListener listener)
Overrides:
addFocusListener in class java.awt.Component

removeFocusListener

public void removeFocusListener(java.awt.event.FocusListener listener)
Overrides:
removeFocusListener in class java.awt.Component

processFocusEvent

public void processFocusEvent(java.awt.event.FocusEvent evt)
Overrides:
processFocusEvent in class java.awt.Component