com.sshtools.terminal
Class TerminalEmulation

java.lang.Object
  extended by com.sshtools.terminal.VDUBuffer
      extended by com.sshtools.terminal.TerminalEmulation
All Implemented Interfaces:
VDUInput

public class TerminalEmulation
extends VDUBuffer
implements VDUInput

A VDUBuffer extension that provides VT100, VT220, VT320 and ANSI emulation. Sequences returned from the host are interpreted and the buffer adjusted accordingly.

Author:
$Author: lee $

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sshtools.terminal.VDUBuffer
VDUBuffer.BufferLock, VDUBuffer.ResizeListener
 
Field Summary
static java.lang.String ANSI
          Supported terminal type *
static java.lang.String DEFAULT_REMOTE_CHARSET
          Default remote character set "ISO-8859-1" *
static int EOL_CR
          Line ending type *
static int EOL_CR_LF
          Line ending type *
static int EOL_DEFAULT
          Line ending type *
static java.lang.String VT100
          Supported terminal type *
static java.lang.String VT220
          Supported terminal type *
static java.lang.String VT320
          Supported terminal type *
 
Fields inherited from class com.sshtools.terminal.VDUBuffer
BOLD, bufferLock, bufSize, charArray, charAttributes, COLOR, COLOR_BG, COLOR_FG, cursorX, cursorY, display, fill, height, INVERT, lineMarker, listenerList, LOW, maxBufSize, NORMAL, screenBase, SCROLL_DOWN, SCROLL_UP, scrollMarker, showcursor, UNDERLINE, update, width, windowBase
 
Fields inherited from interface com.sshtools.terminal.VDUInput
KEY_ACTION, KEY_ALT, KEY_CONTROL, KEY_SHIFT
 
Constructor Summary
TerminalEmulation(java.lang.String termType)
          Construct a new TerminalEmulation given a terminal type and the VirtualTerminal it is being used with.
TerminalEmulation(java.lang.String termType, int width, int height)
          Construct a new TerminalEmulation given a terminal type, the VirtualTerminal it is being used with and a size.
 
Method Summary
 void addListener(TerminalEmulationListener listener)
          Add a listener.
 void beep()
          Beep the system bell (if present)
 void clearScreen()
          Clear the screen
 boolean getAudibleBell()
          Get whether there should be a audible warning when a BEL is received.
 java.net.URL getBeepAudioResource()
          Set the location of the sound file to play in place of the system beep.
 java.lang.String getCharsetName()
          Get terminal charset character set name.
 int getEOL()
          Get the EOL (end of line) type.
 java.io.OutputStream getKeyboardOutputStream()
          Get an OutputStream which can be used to write data into a terminal much like a keyboard.
 java.awt.Dimension getScreenSize()
          Return the current size (in characters).
static java.util.Vector getSupportedEmulations()
          Return a Vector of supported terminal types for this emulator.
 java.io.InputStream getTerminalInputStream()
          This InputStream contains the outgoing data from the terminal (such as keystrokes etc) and should typically be attached to the OutputStream of the underlying transport mechanism.
 java.io.OutputStream getTerminalOutputStream()
          This OutputStream should receive all incoming data for the terminal (such as echo'd keystrokes and process output) and should typically be attached to the InputStream of the underlying transport mechanism.
 java.lang.String getTerminalType()
          Get the terminal type.
 boolean isLocalEcho()
          Get whether characters typed should also be echoed to the screen locally.
 boolean isReturnOnNewLine()
          Get whether a carriage return should be output upon receiving a new line.
 boolean isShowCursor()
          Get whether the cursor is being shown.
 boolean isVisibleBell()
          Get whether there should be a visible warning when a BEL is received.
 void keyPressed(int keyCode, char keyChar, int modifiers)
          A key has been pressed.
 void keyTyped(int keyCode, char keyChar, int modifiers)
          A key has been typed.
 char map_cp850_unicode(char x)
           
 void mousePressed(int x, int y, int modifiers)
          A mouse button has been pressed.
 void mouseReleased(int x, int y, int modifiers)
          A mouse button has been released.
 int putChar(int c, int l, char ch, int attributes)
           
 void putString(java.lang.String s)
          Write a string to the terminal at the current cursor position
 java.lang.String readLine()
           Read a line of text from the keyboard, echoing it on the screen and return whatever was type back as a string.
 void removeListener(TerminalEmulationListener listener)
          Remove a listener.
 void reset()
          Hard-reset the terminal.
protected  void sendTelnetCommand(byte cmd)
           
 void setAnswerBack(java.lang.String ab)
          Set the string to send back to the host when the terminal receives an answer back request.
 void setAudibleBell(boolean audibleBell)
          Set whether there should be a audible warning when a BEL is received.
 void setBackspaceSendsDel(boolean backspaceSendsDel)
          Set whether backspace sends DEL or BS.
 void setBeepAudioResource(java.net.URL beepAudioResource)
          Set the location of the sound file to play in place of the system beep.
 void setCharsetName(java.lang.String charsetName)
          Set terminal character set name.
 void setEOL(int eol)
          Set the EOL (end of line) type.
 void setIBMCharset(boolean ibm)
          Set whether to use the IBM character set
 void setKeyCodes(java.util.Properties codes)
          The definition of key codes should only be done if your application uses a very different keyboard layout than the standard vt320.
 void setLocalEcho(boolean echo)
          Set whether characters typed should also be echoed to the screen locally.
 void setReturnNewLine(boolean returnOnNewLine)
          Set whether a carriage return should be output upon receiving a new line.
 void setTerminalType(java.lang.String termType)
          Set the terminal type.
 void setVisibleBell(boolean visibleBell)
          Set whether there should be a visible warning when a BEL is received.
 void setVMS(boolean vms)
          Set whether the host is VMS.
 void startRecording(java.io.OutputStream recordingOutputStream)
           
 void stopRecording()
           
 void writeString(java.lang.String string)
          Write some text to the terminal.
 
Methods inherited from class com.sshtools.terminal.VDUBuffer
addResizeListener, deleteArea, deleteArea, deleteChar, deleteLine, fireResize, getAttributes, getBottomMargin, getBufferLock, getBufferSize, getChar, getColumns, getCursorX, getCursorY, getLine, getMaxBufferSize, getRows, getTopMargin, getWindowBase, insertChar, insertLine, insertLine, insertLine, insertLine, markLine, putChar, putString, putString, redraw, removeResizeListener, setBottomMargin, setBufferSize, setCursorPosition, setDisplay, setScreenSize, setTopMargin, setWindowBase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOL_DEFAULT

public static final int EOL_DEFAULT
Line ending type *

See Also:
Constant Field Values

EOL_CR_LF

public static final int EOL_CR_LF
Line ending type *

See Also:
Constant Field Values

EOL_CR

public static final int EOL_CR
Line ending type *

See Also:
Constant Field Values

DEFAULT_REMOTE_CHARSET

public static final java.lang.String DEFAULT_REMOTE_CHARSET
Default remote character set "ISO-8859-1" *

See Also:
Constant Field Values

VT320

public static final java.lang.String VT320
Supported terminal type *

See Also:
Constant Field Values

VT220

public static final java.lang.String VT220
Supported terminal type *

See Also:
Constant Field Values

VT100

public static final java.lang.String VT100
Supported terminal type *

See Also:
Constant Field Values

ANSI

public static final java.lang.String ANSI
Supported terminal type *

See Also:
Constant Field Values
Constructor Detail

TerminalEmulation

public TerminalEmulation(java.lang.String termType)
Construct a new TerminalEmulation given a terminal type and the VirtualTerminal it is being used with. The terminal will have a size of 80 characters wide by 24 character high.

Parameters:
termType - terminal type TerminalEmulation.VT100 or TerminalEmulation.VT220 or TerminalEmulation.VT320 or TerminalEmulation.ANSI.

TerminalEmulation

public TerminalEmulation(java.lang.String termType,
                         int width,
                         int height)
Construct a new TerminalEmulation given a terminal type, the VirtualTerminal it is being used with and a size. The size is the character height and width visible at any one time.

Parameters:
termType - terminal type TerminalEmulation.VT100 or TerminalEmulation.VT220 or TerminalEmulation.VT320 or TerminalEmulation.ANSI.
width - width in characters of display
height - height in characters of display
terminal - virtual terminal
Method Detail

setCharsetName

public void setCharsetName(java.lang.String charsetName)
Set terminal character set name.

Parameters:
charsetName - character set name
Throws:
java.lang.IllegalArgumentException - if unsupported encoding.

addListener

public void addListener(TerminalEmulationListener listener)
Add a listener.

Parameters:
listener -

removeListener

public void removeListener(TerminalEmulationListener listener)
Remove a listener.

Parameters:
listener -

putChar

public int putChar(int c,
                   int l,
                   char ch,
                   int attributes)
Overrides:
putChar in class VDUBuffer

getCharsetName

public java.lang.String getCharsetName()
Get terminal charset character set name.

Returns:
terminal character set name

getSupportedEmulations

public static java.util.Vector getSupportedEmulations()
Return a Vector of supported terminal types for this emulator.

Returns:
supported terminal types

readLine

public java.lang.String readLine()

Read a line of text from the keyboard, echoing it on the screen and return whatever was type back as a string. This method will interrupt any I/O that is occuring on the streams thats have been set for this terminal and literally take over the terminal.

This may be useful if the caller wants input from the user that is to be used in a context other than a

Returns:
text read from terminal

setBeepAudioResource

public void setBeepAudioResource(java.net.URL beepAudioResource)
Set the location of the sound file to play in place of the system beep. Only supported on the Java2 platform.

Parameters:
beepAudioResource - sound location

getBeepAudioResource

public java.net.URL getBeepAudioResource()
Set the location of the sound file to play in place of the system beep. Only supported on the Java2 platform.

Returns:
sound location

beep

public void beep()
Beep the system bell (if present)


setVisibleBell

public void setVisibleBell(boolean visibleBell)
Set whether there should be a visible warning when a BEL is received. This implementation will briefly reverse the foreground and backgrounds.

Parameters:
visibleBell - visible bell

isVisibleBell

public boolean isVisibleBell()
Get whether there should be a visible warning when a BEL is received. This implementation will briefly reverse the foreground and backgrounds.

Returns:
visible bell

setAudibleBell

public void setAudibleBell(boolean audibleBell)
Set whether there should be a audible warning when a BEL is received. This implementation will either play the system beep, or play an audio resource

Parameters:
audibleBell - audible bell

getAudibleBell

public boolean getAudibleBell()
Get whether there should be a audible warning when a BEL is received. This implementation will either play the system beep, or play an audio resource

Returns:
audible bell

setEOL

public void setEOL(int eol)
Set the EOL (end of line) type. This determines if the host will be sent just a CR or a CR+LF sequence when the user hits the enter key.

Parameters:
eol - line endings type TerminalEmulation.EOL_DEFAULT or TerminalEmulation.EOL_CR_LF or TerminalEmulation.EOL_DEFAULT.

getEOL

public int getEOL()
Get the EOL (end of line) type. This determines if the host will be sent just a CR or a CR+LF sequence when the user hits the enter key.

Returns:
line endings type TerminalEmulation.EOL_DEFAULT or TerminalEmulation.EOL_CR_LF or TerminalEmulation.EOL_DEFAULT.

setTerminalType

public void setTerminalType(java.lang.String termType)
Set the terminal type.

Parameters:
termType - terminal type TerminalEmulation.VT100 or TerminalEmulation.VT220 or TerminalEmulation.VT320 or TerminalEmulation.ANSI.

getTerminalType

public java.lang.String getTerminalType()
Get the terminal type.

Returns:
terminal type TerminalEmulation.VT100 or TerminalEmulation.VT220 or TerminalEmulation.VT320 or TerminalEmulation.ANSI.

putString

public void putString(java.lang.String s)
Write a string to the terminal at the current cursor position

Parameters:
s - string to put to terminal

sendTelnetCommand

protected void sendTelnetCommand(byte cmd)

getKeyboardOutputStream

public java.io.OutputStream getKeyboardOutputStream()
Description copied from interface: VDUInput
Get an OutputStream which can be used to write data into a terminal much like a keyboard.

Specified by:
getKeyboardOutputStream in interface VDUInput
Returns:

getTerminalOutputStream

public java.io.OutputStream getTerminalOutputStream()
This OutputStream should receive all incoming data for the terminal (such as echo'd keystrokes and process output) and should typically be attached to the InputStream of the underlying transport mechanism.

Returns:
terminal output stream

getTerminalInputStream

public java.io.InputStream getTerminalInputStream()
This InputStream contains the outgoing data from the terminal (such as keystrokes etc) and should typically be attached to the OutputStream of the underlying transport mechanism.

Returns:
terminal input stream

clearScreen

public void clearScreen()
Clear the screen


startRecording

public void startRecording(java.io.OutputStream recordingOutputStream)

stopRecording

public void stopRecording()
                   throws java.io.IOException
Throws:
java.io.IOException

mousePressed

public void mousePressed(int x,
                         int y,
                         int modifiers)
Description copied from interface: VDUInput
A mouse button has been pressed.

Specified by:
mousePressed in interface VDUInput

mouseReleased

public void mouseReleased(int x,
                          int y,
                          int modifiers)
Description copied from interface: VDUInput
A mouse button has been released.

Specified by:
mouseReleased in interface VDUInput

setLocalEcho

public void setLocalEcho(boolean echo)
Set whether characters typed should also be echoed to the screen locally.

Parameters:
echo - local echo

isLocalEcho

public boolean isLocalEcho()
Get whether characters typed should also be echoed to the screen locally.

Returns:
local echo

setBackspaceSendsDel

public void setBackspaceSendsDel(boolean backspaceSendsDel)
Set whether backspace sends DEL or BS. This will overide an key maps that have been set

Parameters:
backspaceSendsDel - backspace sends DEL instead of BS

setVMS

public void setVMS(boolean vms)
Set whether the host is VMS.

Parameters:
vms - vms host

setIBMCharset

public void setIBMCharset(boolean ibm)
Set whether to use the IBM character set

Parameters:
ibm - IBM character set

setKeyCodes

public void setKeyCodes(java.util.Properties codes)
Description copied from interface: VDUInput
The definition of key codes should only be done if your application uses a very different keyboard layout than the standard vt320. The definition of almost all special keys is possible and follows rules described below:

[SCA] KEY=STRING

The characters enclosed in [ and ] are optional and only one of the characters 'S' (Shift), 'C' (Control) or 'A' (Alt) may appear before the KEY, which is a textual representation (F1, PGUP etc) of the key you would like to redefine.

The new STRING you define to be sent when pressing the key should come after the equal sign (=). Hash marks (#) in the file declare a line as comment and will be ignored. Some examples explain the syntax:

Send the string "test" when pressing the F1 key:

F1 = test

On pressing Control + PGUP send the string "pgup pressed":

CPGUP = pgup pressed

Redefine the key Alt + F12 to send an escape character:

AF12 = \\e

As you can see the string you can define may contain special characters which may be escaped using the backslash (\). Allowed special characters follow in the table below:

(Important: for some of the escape codes you need two backslashes as these are our own definitions and not known by the Java Property mechanism)

 Character  Explanation
 \\b        Backspace, this character is usually sent by the <- key
            (not the cursor left key!).
 \\e        Escape, this character is usually sent by the Esc key.
 \n         (only one backslash) Newline, this character will move the cursor
            to a new line. On UNIX systems it is equivalent to carriage return + newline.
            Usually the Enter key send this character.
 \r         (only one backslash) Carriage Return, this key moves the cursor
            to the beginning of the line. In conjunction with Newline it moves the cursor
            to the beginning of a new line.
 \t         (only one backslash) Tabulator, the tab character is sent by the
 {key:->}   key and moves the cursor to the next tab stop defined by the terminal.
 \\v        Vertical Tabulator, sends a vertical tabulator character.
 \\a        Bell, sends a terminal bell character which should make the
            terminal sound its bell.
 \number    Inserts the character that is defined by this number in the ISO
            Latin1 character set. The number should be a decimal value.
The following table explains which key may be redefined. As explained above each of the keys may be prefixed by a character defining the redefinition that occures if it is pressed in conjunction with the shift, control or alt keys.

 Key        Comments
 F1 - F20   The function key, F1, F2 ... up to F20.
 PGUP       The Page Up key.
 PGDOWN     The Page Down key.
 END        The End key.
 HOME       The Home (Pos 1) key.
 INSERT     The Insert key.
 REMOVE     The Remove key.
 UP         The Cursor Up key.
 DOWN       The Cursor Down key.
 LEFT       The Cursor Left key.
 RIGHT      The Cursor right key.
 NUMPAD0    The numbered Numpad keys.
 ...
 NUMPAD9    The numbered Numpad keys.
 ESCAPE     The ESCAPE key.
 BACKSPACE  The backspace key.
 TAB        The tabulator key.

Specified by:
setKeyCodes in interface VDUInput
Parameters:
codes - properites object containing the key codes.

setAnswerBack

public void setAnswerBack(java.lang.String ab)
Set the string to send back to the host when the terminal receives an answer back request.

Parameters:
ab - answer back string

keyPressed

public void keyPressed(int keyCode,
                       char keyChar,
                       int modifiers)
Description copied from interface: VDUInput
A key has been pressed.

Specified by:
keyPressed in interface VDUInput

keyTyped

public void keyTyped(int keyCode,
                     char keyChar,
                     int modifiers)
Description copied from interface: VDUInput
A key has been typed.

Specified by:
keyTyped in interface VDUInput

reset

public void reset()
Hard-reset the terminal. All streams will be closed and the display will be reset to its "power-on" state.


getScreenSize

public java.awt.Dimension getScreenSize()
Return the current size (in characters).

Returns:
screen size

isShowCursor

public boolean isShowCursor()
Get whether the cursor is being shown.

Specified by:
isShowCursor in class VDUBuffer
Returns:
is the cursor being shown

writeString

public void writeString(java.lang.String string)
Write some text to the terminal. The string will be parsed for new line sequences and output accordingly.

Parameters:
string - string to write to terminal

setReturnNewLine

public void setReturnNewLine(boolean returnOnNewLine)
Set whether a carriage return should be output upon receiving a new line.

Parameters:
returnOnNewLine - carriage return on new line

isReturnOnNewLine

public boolean isReturnOnNewLine()
Get whether a carriage return should be output upon receiving a new line.

Returns:
carriage return on new line

map_cp850_unicode

public char map_cp850_unicode(char x)
Parameters:
x -
Returns:
character


Copyright © 2003-2009 SSHTOOLS LTD. All Rights Reserved.