de.mud.terminal

Class SwingTerminal

Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, VDUDisplay

public class SwingTerminal
extends Component
implements VDUDisplay, KeyListener, MouseListener, 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 511 2005-11-18 19:36:06Z marcus $
Author:
Matthias L. Jugel, Marcus Mei???ner

Field Summary

static int
COLOR_BOLD
static int
COLOR_INVERT
static int
RESIZE_FONT
static int
RESIZE_NONE
static int
RESIZE_SCREEN

Constructor Summary

SwingTerminal(VDUBuffer buffer)
Create a display unit with size 80x24 and Font "Monospaced", size 12.
SwingTerminal(VDUBuffer buffer, 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(FocusListener listener)
void
addKeyListener(KeyListener listener)
Add a key listener to the VDU.
void
addMouseListener(MouseListener listener)
Add a mouse listener to the VDU.
void
addMouseMotionListener(MouseMotionListener listener)
Add a mouse motion listener to the VDU.
void
clearSelection()
Color[]
getColorSet()
Get current color set.
Insets
getInsets()
The insets of the character display define the border.
Dimension
getPreferredSize()
Return the preferred Size of the character display.
String
getSelection()
Dimension
getSize()
Return the real size in points of the character display.
VDUBuffer
getVDUBuffer()
Return the currently associated VDUBuffer.
void
keyPressed(KeyEvent e)
void
keyReleased(KeyEvent e)
void
keyTyped(KeyEvent e)
protected double
max(double f1, double f2)
protected double
min(double f1, double f2)
void
mouseClicked(MouseEvent evt)
void
mouseDragged(MouseEvent evt)
void
mouseEntered(MouseEvent evt)
void
mouseExited(MouseEvent evt)
Point
mouseGetPos(Point evtpt)
Convert Mouse Event coordinates into character cell coordinates
void
mouseMoved(MouseEvent evt)
void
mousePressed(MouseEvent evt)
Handle mouse pressed events for copy & paste.
void
mouseReleased(MouseEvent evt)
Handle mouse released events for copy & paste.
void
paint(Graphics g)
Paint the current screen using the backing store image.
void
print(Graphics g)
void
processFocusEvent(FocusEvent evt)
void
processKeyEvent(KeyEvent evt)
Process key events for this component.
void
processMouseEvent(MouseEvent evt)
Process mouse events for this component.
void
processMouseMotionEvent(MouseEvent evt)
Process mouse motion events for this component.
void
redraw()
Redraw marked lines.
protected void
redraw(Graphics g)
void
removeFocusListener(FocusListener listener)
void
removeKeyListener(KeyListener listener)
Remove key listener from the VDU.
void
removeMouseListener(MouseListener listener)
Remove a mouse listener to the VDU.
void
removeMouseMotionListener(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(Color[] colorset)
Set new color set for the display.
void
setCursorColors(Color fg, Color bg)
Set cursor FG and BG colors
void
setFont(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(JScrollBar scrollBar)
Connect a scrollbar to the VDU.
void
setVDUBuffer(VDUBuffer buffer)
Set a new terminal (VDU) buffer.
void
updateScrollBar()

Field Details

COLOR_BOLD

public static final int COLOR_BOLD
Field Value:
8

COLOR_INVERT

public static final int COLOR_INVERT
Field Value:
9

RESIZE_FONT

public static final int RESIZE_FONT
Field Value:
1

RESIZE_NONE

public static final int RESIZE_NONE
Field Value:
0

RESIZE_SCREEN

public static final int RESIZE_SCREEN
Field Value:
2

Constructor Details

SwingTerminal

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

SwingTerminal

public SwingTerminal(VDUBuffer buffer,
                     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)

Method Details

addFocusListener

public void addFocusListener(FocusListener listener)

addKeyListener

public void addKeyListener(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.
Parameters:
listener - the key listener

addMouseListener

public void addMouseListener(MouseListener listener)
Add a mouse listener to the VDU. This is the implementation for the lightweight event handling.
Parameters:
listener - the new mouse listener

addMouseMotionListener

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

clearSelection

public void clearSelection()

getColorSet

public Color[] getColorSet()
Get current color set.
Returns:
the color set currently associated

getInsets

public Insets getInsets()
The insets of the character display define the border.
Returns:
Insets border thickness in pixels

getPreferredSize

public Dimension getPreferredSize()
Return the preferred Size of the character display. This turns out to be the actual size.
Returns:
Dimension dimension of the display
See Also:
SwingTerminal

getSelection

public String getSelection()

getSize

public Dimension getSize()
Return the real size in points of the character display.
Returns:
Dimension the dimension of the display
See Also:
java.awt.Dimension

getVDUBuffer

public VDUBuffer getVDUBuffer()
Return the currently associated VDUBuffer.
Specified by:
getVDUBuffer in interface VDUDisplay
Returns:
the current buffer

keyPressed

public void keyPressed(KeyEvent e)

keyReleased

public void keyReleased(KeyEvent e)

keyTyped

public void keyTyped(KeyEvent e)

max

protected double max(double f1,
                     double f2)

min

protected double min(double f1,
                     double f2)

mouseClicked

public void mouseClicked(MouseEvent evt)

mouseDragged

public void mouseDragged(MouseEvent evt)

mouseEntered

public void mouseEntered(MouseEvent evt)

mouseExited

public void mouseExited(MouseEvent evt)

mouseGetPos

public Point mouseGetPos(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

mouseMoved

public void mouseMoved(MouseEvent evt)

mousePressed

public void mousePressed(MouseEvent evt)
Handle mouse pressed events for copy & paste.
Parameters:
evt - the event that occured
See Also:
java.awt.event.MouseEvent

mouseReleased

public void mouseReleased(MouseEvent evt)
Handle mouse released events for copy & paste.
Parameters:
evt - the mouse event

paint

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

print

public void print(Graphics g)

processFocusEvent

public void processFocusEvent(FocusEvent evt)

processKeyEvent

public void processKeyEvent(KeyEvent evt)
Process key events for this component.
Parameters:
evt - the dispatched key event

processMouseEvent

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

processMouseMotionEvent

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

redraw

public void redraw()
Redraw marked lines.
Specified by:
redraw in interface VDUDisplay

redraw

protected void redraw(Graphics g)

removeFocusListener

public void removeFocusListener(FocusListener listener)

removeKeyListener

public void removeKeyListener(KeyListener listener)
Remove key listener from the VDU. It is a prerequisite for a lightweigh component.
Parameters:
listener - the key listener to remove

removeMouseListener

public void removeMouseListener(MouseListener listener)
Remove a mouse listener to the VDU. This is the implementation for the lightweight event handling.
Parameters:
listener - the mouse listener to remove

removeMouseMotionListener

public void removeMouseMotionListener(MouseMotionListener listener)
Remove a mouse motion listener to the VDU. This is the implementation for the lightweight event handling.
Parameters:
listener - the mouse motion listener to remove

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

setBounds

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

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

setColorSet

public void setColorSet(Color[] colorset)
Set new color set for the display.
Parameters:
colorset - new color set

setCursorColors

public void setCursorColors(Color fg,
                            Color bg)
Set cursor FG and BG colors
Parameters:
fg - foreground color or null
bg - background color or null

setFont

public void setFont(Font font)
Set the font to be used for rendering the characters on screen.
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

setScrollbar

public void setScrollbar(JScrollBar scrollBar)
Connect a scrollbar to the VDU. This should be done differently using a property change listener.
Parameters:
scrollBar - the scroll bar

setVDUBuffer

public void setVDUBuffer(VDUBuffer buffer)
Set a new terminal (VDU) buffer.
Specified by:
setVDUBuffer in interface VDUDisplay
Parameters:
buffer - new buffer

updateScrollBar

public void updateScrollBar()
Specified by:
updateScrollBar in interface VDUDisplay