charva.awt

Class Toolkit


public class Toolkit
extends java.lang.Object

The Toolkit class provides the interface to the "ncurses" library functions. Exceptions and error messages are reported to the logfile $HOME/charva.log.

The default colors are white foreground and black background, but these defaults can be modified by changing the static variables _defaultForeground and _defaultBackground.

Field Summary

static int
ACS_BTEE
static int
ACS_BULLET
static int
ACS_CKBOARD
static int
ACS_DEGREE
static int
ACS_DIAMOND
static int
ACS_HLINE
static int
ACS_LLCORNER
static int
ACS_LRCORNER
static int
ACS_LTEE
static int
ACS_PLMINUS
static int
ACS_PLUS
static int
ACS_RTEE
static int
ACS_S1
static int
ACS_S9
static int
ACS_TTEE
static int
ACS_ULCORNER
static int
ACS_URCORNER
static int
ACS_VLINE
static int
A_ALTCHARSET
static int
A_BLINK
static int
A_BOLD
static int
A_DIM
static int
A_INVIS
static int
A_NORMAL
static int
A_REVERSE
static int
A_STANDOUT
static int
A_UNDERLINE
static char
Auml
static int
BLACK
static int
BLUE
static int
BUTTON1_CLICKED
static int
BUTTON1_PRESSED
static int
BUTTON1_RELEASED
static int
BUTTON2_CLICKED
static int
BUTTON2_PRESSED
static int
BUTTON2_RELEASED
static int
BUTTON3_CLICKED
static int
BUTTON3_PRESSED
static int
BUTTON3_RELEASED
static int
CYAN
static char
Ccedil
static char
Eacute
static char
Euml
static int
GREEN
static int
KEY_MOUSE
static int
MAGENTA
static char
Ouml
static int
RED
static char
Uuml
static int
WHITE
static int
YELLOW
static Color
_defaultBackground
static Color
_defaultForeground
static boolean
isColorEnabled
This flag is true is the system property "charva.color" has been set.

Method Summary

static int
COLOR_PAIR_ATTRIBUTE(int pair_)
Emulates the terminfo COLOR_PAIR macro.
void
addChar(int chr, int attrib, int colorpair_)
Add a character to the virtual terminal at the current cursor position.
void
addHorizontalLine(int length_, int attrib_, int colorpair)
Draw a horizontal line of the specified length starting at the current cursor position.
void
addString(String str_, int attrib_, int colorpair_)
Add a string to the virtual terminal at the current cursor position.
void
addVerticalLine(int length_, int attrib_, int colorpair_)
Draw a vertical line of the specified length starting at the current cursor position.
void
beep()
Ring the terminal's bell.
void
blankBox(Point origin_, Dimension size_)
void
blankBox(Point origin_, Dimension size_, int colorpair_)
Blank out a box using the specified color pair.
void
blankBoxNative(int left_, int top_, int right_, int bottom_, int colorpair_)
Blank out the specified rectangle.
void
checkForKeystroke()
Wait up to 100msec for a keystroke (or mouse-event).
void
clear()
Clears the screen (calls the curses clear() function).
void
close()
Close the terminal window and restore terminal settings (calls the curses endwin() function).
void
drawBox(Point origin_, Dimension size_)
Draw a box.
void
drawBox(Point origin_, Dimension size_, int colorpair_)
Draw a box using the specified color pair.
void
drawBoxNative(int left_, int top_, int right_, int bottom_, int colorpair_)
void
fireKeystroke(int key_)
Processes a keystroke that was pressed in the currently displayed window.
void
fireKeystroke(int key_, Component source_)
Process a keystroke as if it was pressed while the focus was in the specified component.
void
fireMouseEvent(charva.awt.MouseEventInfo mouse_info)
Processes the mouse-click specified by mouse_info.
boolean
getBooleanCapability(String capname_)
Provides an interface to the ncurses "tigetflag()" function.
int
getColorPairIndex(ColorPair pair_)
Returns the color-pair index corresponding to the specified color-pair.
Point
getCursor()
Get absolute cursor position
Point
getCursor(Point p_)
Get absolute cursor position.
static Color
getDefaultBackground()
Returns the default background color.
static Color
getDefaultForeground()
Returns the default foreground color.
static Toolkit
getDefaultToolkit()
This static method instantiates a Toolkit object if it does not already exist; and returns a reference to the instantiated Toolkit.
int
getMaxColorPairs()
Returns the maximum number of color-pairs (provides an interface to the ncurses COLOR_PAIRS global variable).
charva.awt.MouseEventInfo
getMouseEventInfo()
Get information about a mouse event (i.e the coordinates, and which button was clicked).
int
getNumericCapability(String capname_)
Provides an interface to the ncurses "tigetnum()" function.
int
getScreenColumns()
int
getScreenRows()
Dimension
getScreenSize()
String
getStringCapability(String capname_)
Provides an interface to the ncurses "tigetstr()" function.
EventQueue
getSystemEventQueue()
Window
getTopWindow()
Get the top window of the window stack.
String
getTtyName()
Returns the tty device name (provides an interface to the Unix C function "ttyname()").
boolean
hasColors()
Returns true if the terminal is capable of displaying colours.
void
initColorPair(int pair_, int fgnd_, int bgnd_)
Provides an interface to the terminfo "init_pair()" function.
boolean
isWindowDisplayed(Window window_)
Returns true if the specified window is currently displayed.
static String
key2ASCII(int key_)
Convert the integer representation of a keystroke to an ASCII string.
void
print(String str_)
Provides an interface to the ncurses "mcprint()" function to ship the specified string to a printer attached to the terminal.
void
putp(String str_)
Provides an interface to the ncurses "putp()" function, to write a string to the terminal; the string must be a return value from getStringCapability().
void
redrawWin()
Indicate to ncurses that all the lines on the screen have changed and need to be redrawn the next time Toolkit.sync() is called.
void
resetClipRect()
Reset the clipping rectangle to the screen size.
void
setClipRect(Rectangle clip_)
Set a clipping rectangle.
void
setClipRectNative(int left_, int top_, int right_, int bottom_)
Set a clipping rectangle.
void
setCursor(Point p)
Set absolute cursor position
void
setCursor(int x_, int y_)
Set absolute cursor position
static void
setDefaultBackground(Color color_)
Changes the default background color.
static void
setDefaultForeground(Color color_)
Changes the default foreground color.
void
startColors()
An interface to the terminfo "start_colors()" function.
void
sync()
Synchronize the state of the physical terminal with the state of the virtual terminal maintained by curses (ie provides an interface to the curses refresh() function).
void
triggerGarbageCollection(Component source_)
Trigger garbage collection.

Field Details

ACS_BTEE

public static final int ACS_BTEE

ACS_BULLET

public static final int ACS_BULLET

ACS_CKBOARD

public static final int ACS_CKBOARD

ACS_DEGREE

public static final int ACS_DEGREE

ACS_DIAMOND

public static final int ACS_DIAMOND

ACS_HLINE

public static final int ACS_HLINE

ACS_LLCORNER

public static final int ACS_LLCORNER

ACS_LRCORNER

public static final int ACS_LRCORNER

ACS_LTEE

public static final int ACS_LTEE

ACS_PLMINUS

public static final int ACS_PLMINUS

ACS_PLUS

public static final int ACS_PLUS

ACS_RTEE

public static final int ACS_RTEE

ACS_S1

public static final int ACS_S1

ACS_S9

public static final int ACS_S9

ACS_TTEE

public static final int ACS_TTEE

ACS_ULCORNER

public static final int ACS_ULCORNER

ACS_URCORNER

public static final int ACS_URCORNER

ACS_VLINE

public static final int ACS_VLINE

A_ALTCHARSET

public static final int A_ALTCHARSET

A_BLINK

public static final int A_BLINK

A_BOLD

public static final int A_BOLD

A_DIM

public static final int A_DIM

A_INVIS

public static final int A_INVIS

A_NORMAL

public static final int A_NORMAL

A_REVERSE

public static final int A_REVERSE

A_STANDOUT

public static final int A_STANDOUT

A_UNDERLINE

public static final int A_UNDERLINE

Auml

public static final char Auml
Field Value:
'\u00c4'

BLACK

public static final int BLACK

BLUE

public static final int BLUE

BUTTON1_CLICKED

public static final int BUTTON1_CLICKED
Field Value:
4

BUTTON1_PRESSED

public static final int BUTTON1_PRESSED
Field Value:
2

BUTTON1_RELEASED

public static final int BUTTON1_RELEASED
Field Value:
1

BUTTON2_CLICKED

public static final int BUTTON2_CLICKED
Field Value:
256

BUTTON2_PRESSED

public static final int BUTTON2_PRESSED
Field Value:
128

BUTTON2_RELEASED

public static final int BUTTON2_RELEASED
Field Value:
64

BUTTON3_CLICKED

public static final int BUTTON3_CLICKED
Field Value:
16384

BUTTON3_PRESSED

public static final int BUTTON3_PRESSED
Field Value:
8192

BUTTON3_RELEASED

public static final int BUTTON3_RELEASED
Field Value:
4096

CYAN

public static final int CYAN

Ccedil

public static final char Ccedil
Field Value:
'\u00c7'

Eacute

public static final char Eacute
Field Value:
'\u00c9'

Euml

public static final char Euml
Field Value:
'\u00cb'

GREEN

public static final int GREEN

KEY_MOUSE

public static final int KEY_MOUSE
Field Value:
409

MAGENTA

public static final int MAGENTA

Ouml

public static final char Ouml
Field Value:
'\u00d6'

RED

public static final int RED

Uuml

public static final char Uuml
Field Value:
'\u00dc'

WHITE

public static final int WHITE

YELLOW

public static final int YELLOW

_defaultBackground

public static Color _defaultBackground

_defaultForeground

public static Color _defaultForeground

isColorEnabled

public static final boolean isColorEnabled
This flag is true is the system property "charva.color" has been set.

Method Details

COLOR_PAIR_ATTRIBUTE

public static int COLOR_PAIR_ATTRIBUTE(int pair_)
Emulates the terminfo COLOR_PAIR macro.

addChar

public void addChar(int chr,
                    int attrib,
                    int colorpair_)
Add a character to the virtual terminal at the current cursor position.

addHorizontalLine

public void addHorizontalLine(int length_,
                              int attrib_,
                              int colorpair)
Draw a horizontal line of the specified length starting at the current cursor position.

addString

public void addString(String str_,
                      int attrib_,
                      int colorpair_)
Add a string to the virtual terminal at the current cursor position.

addVerticalLine

public void addVerticalLine(int length_,
                            int attrib_,
                            int colorpair_)
Draw a vertical line of the specified length starting at the current cursor position.

beep

public void beep()
Ring the terminal's bell.

blankBox

public void blankBox(Point origin_,
                     Dimension size_)

blankBox

public void blankBox(Point origin_,
                     Dimension size_,
                     int colorpair_)
Blank out a box using the specified color pair.
Parameters:
origin_ - The top left corner of the rectangle.
size_ - The dimensions of the rectangle to blank out.
colorpair_ - The number of the color-pair (foreground+background) to use for blanking the rectangle.

blankBoxNative

public void blankBoxNative(int left_,
                           int top_,
                           int right_,
                           int bottom_,
                           int colorpair_)
Blank out the specified rectangle.

checkForKeystroke

public void checkForKeystroke()
Wait up to 100msec for a keystroke (or mouse-event).

clear

public void clear()
Clears the screen (calls the curses clear() function).

close

public void close()
Close the terminal window and restore terminal settings (calls the curses endwin() function).

drawBox

public void drawBox(Point origin_,
                    Dimension size_)
Draw a box.

drawBox

public void drawBox(Point origin_,
                    Dimension size_,
                    int colorpair_)
Draw a box using the specified color pair.

drawBoxNative

public void drawBoxNative(int left_,
                          int top_,
                          int right_,
                          int bottom_,
                          int colorpair_)

fireKeystroke

public void fireKeystroke(int key_)
Processes a keystroke that was pressed in the currently displayed window.
Parameters:
key_ - the keystroke that was pressed. If it is less than 256, it is a ASCII or ISO8859-1 code; otherwise it is a function key as defined in the "VK_*" values.

fireKeystroke

public void fireKeystroke(int key_,
                          Component source_)
Process a keystroke as if it was pressed while the focus was in the specified component.
Parameters:
key_ - the keystroke that was pressed. If it is less than 256, it is an ASCII or ISO8859-1 code; otherwise it is a function key as defined in the "VK_*" values.

fireMouseEvent

public void fireMouseEvent(charva.awt.MouseEventInfo mouse_info)
Processes the mouse-click specified by mouse_info. Note that we disable mouse-click resolution in the ncurses library by setting "mouse_interval" to 0, because it doesn't appear to work properly. Instead we do it in this method.

getBooleanCapability

public boolean getBooleanCapability(String capname_)
            throws TerminfoCapabilityException
Provides an interface to the ncurses "tigetflag()" function.

getColorPairIndex

public int getColorPairIndex(ColorPair pair_)
            throws TerminfoCapabilityException
Returns the color-pair index corresponding to the specified color-pair. If the color pair does not exist yet, it is created using the ncurses "init_pair" function. If all the available color-pairs are already in use, a TerminfoCapabilityException is thrown.

getCursor

public Point getCursor()
Get absolute cursor position

getCursor

public Point getCursor(Point p_)
Get absolute cursor position. Use this overloaded version to avoid allocating a new Point on the heap.

getDefaultBackground

public static Color getDefaultBackground()
Returns the default background color.

getDefaultForeground

public static Color getDefaultForeground()
Returns the default foreground color.

getDefaultToolkit

public static Toolkit getDefaultToolkit()
This static method instantiates a Toolkit object if it does not already exist; and returns a reference to the instantiated Toolkit.

getMaxColorPairs

public int getMaxColorPairs()
Returns the maximum number of color-pairs (provides an interface to the ncurses COLOR_PAIRS global variable).

getMouseEventInfo

public charva.awt.MouseEventInfo getMouseEventInfo()
Get information about a mouse event (i.e the coordinates, and which button was clicked).

getNumericCapability

public int getNumericCapability(String capname_)
            throws TerminfoCapabilityException
Provides an interface to the ncurses "tigetnum()" function.

getScreenColumns

public int getScreenColumns()

getScreenRows

public int getScreenRows()

getScreenSize

public Dimension getScreenSize()

getStringCapability

public String getStringCapability(String capname_)
            throws TerminfoCapabilityException
Provides an interface to the ncurses "tigetstr()" function.

getSystemEventQueue

public EventQueue getSystemEventQueue()

getTopWindow

public Window getTopWindow()
Get the top window of the window stack.

getTtyName

public String getTtyName()
Returns the tty device name (provides an interface to the Unix C function "ttyname()").

hasColors

public boolean hasColors()
Returns true if the terminal is capable of displaying colours.

initColorPair

public void initColorPair(int pair_,
                          int fgnd_,
                          int bgnd_)
            throws TerminfoCapabilityException
Provides an interface to the terminfo "init_pair()" function.

isWindowDisplayed

public boolean isWindowDisplayed(Window window_)
Returns true if the specified window is currently displayed.

key2ASCII

public static String key2ASCII(int key_)
Convert the integer representation of a keystroke to an ASCII string.

print

public void print(String str_)
            throws TerminfoCapabilityException
Provides an interface to the ncurses "mcprint()" function to ship the specified string to a printer attached to the terminal. Makes use of the "mc4" and "mc5" capabilities of the terminal (see "man curs_print").

putp

public void putp(String str_)
Provides an interface to the ncurses "putp()" function, to write a string to the terminal; the string must be a return value from getStringCapability().

redrawWin

public void redrawWin()
Indicate to ncurses that all the lines on the screen have changed and need to be redrawn the next time Toolkit.sync() is called. This just calls the ncurses function "redrawwin(stdscr)".

resetClipRect

public void resetClipRect()
Reset the clipping rectangle to the screen size.

setClipRect

public void setClipRect(Rectangle clip_)
Set a clipping rectangle.

setClipRectNative

public void setClipRectNative(int left_,
                              int top_,
                              int right_,
                              int bottom_)
Set a clipping rectangle.

setCursor

public void setCursor(Point p)
Set absolute cursor position

setCursor

public void setCursor(int x_,
                      int y_)
Set absolute cursor position

setDefaultBackground

public static void setDefaultBackground(Color color_)
Changes the default background color.

setDefaultForeground

public static void setDefaultForeground(Color color_)
Changes the default foreground color.

startColors

public void startColors()
An interface to the terminfo "start_colors()" function.

sync

public void sync()
Synchronize the state of the physical terminal with the state of the virtual terminal maintained by curses (ie provides an interface to the curses refresh() function).

triggerGarbageCollection

public void triggerGarbageCollection(Component source_)
Trigger garbage collection. This method can be called inside an event handler, but the call to System.gc() will be made after the event handler has completed (i.e. after drawing is completed). This is a convenient, but OPTIONAL, way of ensuring that the heap does not grow too large. Some experts say that it is better not to call System.gc() explicitly from inside an application; you take your pick.
Parameters:
source_ - the component that triggered the garbage collection (not important).