net.slashie.libjcsi.jcurses
Class JCursesConsoleInterface

java.lang.Object
  extended by net.slashie.libjcsi.jcurses.JCursesConsoleInterface
All Implemented Interfaces:
ConsoleSystemInterface

public class JCursesConsoleInterface
extends java.lang.Object
implements ConsoleSystemInterface

This provides an interface using JCurses

Author:
Santiago Zapata

Field Summary
 
Fields inherited from interface net.slashie.libjcsi.ConsoleSystemInterface
BLACK, BLUE, BROWN, CYAN, DARK_BLUE, DARK_RED, GRAY, GREEN, LEMON, LIGHT_GRAY, MAGENTA, PURPLE, RED, TEAL, WHITE, YELLOW
 
Constructor Summary
JCursesConsoleInterface()
           
 
Method Summary
 void cls()
          Clears the screen
 void flash(int color)
          Makes the screen flash with a given color
 void flushColorTable()
          This flushes the internal Hashtable for the colors.
 CharKey inkey()
          Waits until a key is pressed and returns it
 java.lang.String input()
          Reads a string from the keyboard
 java.lang.String input(int l)
          Reads a string from the keyboard with a maximum length
 boolean isInsideBounds(int x, int y)
           
 boolean isInsideBounds(Position p)
          Checks if the position is valid
 void locateCaret(int x, int y)
          Locates the input caret on a given position
 char peekChar(int x, int y)
          Checks what character is at a given position
 int peekColor(int x, int y)
          Checks what color is at a given position
 void print(int x, int y, char character, CSIColor csiColor)
          Prints a character on the console, using a custom color
 void print(int x, int y, char what, int color)
          Prints a character on the console
 void print(int x, int y, java.lang.String what)
          Prints a String on the console with the default color.
 void print(int x, int y, java.lang.String string, CSIColor csiColor)
          Prints a String on the console, using a custom color.
 void print(int x, int y, java.lang.String what, int color)
          Prints a String on the console in the color specified.
 void refresh()
          Refreshes the screen, printing all characters that were buffered Some implementations may instead write directly to the console
 void refresh(java.lang.Thread t)
          Refreshes the screen, printing all characters that were buffered, and interrupts the Thread Some implementations may instead write directly to the console
 void restore()
          Restores the contents of the backup buffer to screen
 void safeprint(int x, int y, char what, int color)
          Same as print but must check for validity of the coordinates
 void saveBuffer()
          Saves the screen contents to a backup buffer
 void setAutoRefresh(boolean value)
          Sets whether or not a buffer will be used
 void waitKey(int keyCode)
          Waits for the user to press a key
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JCursesConsoleInterface

public JCursesConsoleInterface()
Method Detail

print

public void print(int x,
                  int y,
                  char what,
                  int color)
Description copied from interface: ConsoleSystemInterface
Prints a character on the console

Specified by:
print in interface ConsoleSystemInterface
Parameters:
x - horizontal position
y - vertical position
what - The character to be printed
color - The color, one of the ConsoleSystemInterface constants

print

public void print(int x,
                  int y,
                  java.lang.String what,
                  int color)
Description copied from interface: ConsoleSystemInterface
Prints a String on the console in the color specified. Does not check for running of the edge of the screen, so calling function must do such a check to avoid errors.

Specified by:
print in interface ConsoleSystemInterface
Parameters:
x - horizontal starting position
y - vertical position
what - The string to be printed
color - The color, one of the ConsoleSystemInterface constants

print

public void print(int x,
                  int y,
                  java.lang.String what)
Description copied from interface: ConsoleSystemInterface
Prints a String on the console with the default color. Does not check for running of the edge of the screen, so calling function must do such a check to avoid errors.

Specified by:
print in interface ConsoleSystemInterface
Parameters:
x - horizontal starting position
y - vertical starting position
what - The String to be printed

peekChar

public char peekChar(int x,
                     int y)
Description copied from interface: ConsoleSystemInterface
Checks what character is at a given position

Specified by:
peekChar in interface ConsoleSystemInterface
Parameters:
x - horizontal position
y - vertical position
Returns:
The character at the x,y position

peekColor

public int peekColor(int x,
                     int y)
Description copied from interface: ConsoleSystemInterface
Checks what color is at a given position

Specified by:
peekColor in interface ConsoleSystemInterface
Parameters:
x - horizontal position
y - vertical position
Returns:
The color at the x,y position

inkey

public CharKey inkey()
Description copied from interface: ConsoleSystemInterface
Waits until a key is pressed and returns it

Specified by:
inkey in interface ConsoleSystemInterface
Returns:
The key that was pressed

locateCaret

public void locateCaret(int x,
                        int y)
Description copied from interface: ConsoleSystemInterface
Locates the input caret on a given position

Specified by:
locateCaret in interface ConsoleSystemInterface
Parameters:
x - horizontal position
y - vertical position

input

public java.lang.String input()
Description copied from interface: ConsoleSystemInterface
Reads a string from the keyboard

Specified by:
input in interface ConsoleSystemInterface
Returns:
The String that was read after pressing enter

input

public java.lang.String input(int l)
Description copied from interface: ConsoleSystemInterface
Reads a string from the keyboard with a maximum length

Specified by:
input in interface ConsoleSystemInterface
Returns:
The String that was read after pressing enter, truncated at specified length

isInsideBounds

public boolean isInsideBounds(Position p)
Description copied from interface: ConsoleSystemInterface
Checks if the position is valid

Specified by:
isInsideBounds in interface ConsoleSystemInterface
Parameters:
p - position to be tested
Returns:
true if the position is valid

isInsideBounds

public boolean isInsideBounds(int x,
                              int y)

cls

public void cls()
Description copied from interface: ConsoleSystemInterface
Clears the screen

Specified by:
cls in interface ConsoleSystemInterface

refresh

public void refresh()
Description copied from interface: ConsoleSystemInterface
Refreshes the screen, printing all characters that were buffered Some implementations may instead write directly to the console

Specified by:
refresh in interface ConsoleSystemInterface

refresh

public void refresh(java.lang.Thread t)
Description copied from interface: ConsoleSystemInterface
Refreshes the screen, printing all characters that were buffered, and interrupts the Thread Some implementations may instead write directly to the console

Specified by:
refresh in interface ConsoleSystemInterface

flash

public void flash(int color)
Description copied from interface: ConsoleSystemInterface
Makes the screen flash with a given color

Specified by:
flash in interface ConsoleSystemInterface

setAutoRefresh

public void setAutoRefresh(boolean value)
Description copied from interface: ConsoleSystemInterface
Sets whether or not a buffer will be used

Specified by:
setAutoRefresh in interface ConsoleSystemInterface
Parameters:
value - true to activate buffer

safeprint

public void safeprint(int x,
                      int y,
                      char what,
                      int color)
Description copied from interface: ConsoleSystemInterface
Same as print but must check for validity of the coordinates

Specified by:
safeprint in interface ConsoleSystemInterface
Parameters:
x - horizontal position
y - vertical position
what - The character to be printed
color - The color, one of the ConsoleSystemInterface constants

waitKey

public void waitKey(int keyCode)
Description copied from interface: ConsoleSystemInterface
Waits for the user to press a key

Specified by:
waitKey in interface ConsoleSystemInterface
Parameters:
keyCode - code of specific key to wait for

restore

public void restore()
Description copied from interface: ConsoleSystemInterface
Restores the contents of the backup buffer to screen

Specified by:
restore in interface ConsoleSystemInterface

saveBuffer

public void saveBuffer()
Description copied from interface: ConsoleSystemInterface
Saves the screen contents to a backup buffer

Specified by:
saveBuffer in interface ConsoleSystemInterface

print

public void print(int x,
                  int y,
                  char character,
                  CSIColor csiColor)
Description copied from interface: ConsoleSystemInterface
Prints a character on the console, using a custom color

Specified by:
print in interface ConsoleSystemInterface
Parameters:
x - horizontal position
y - vertical position
character - The character to be printed
csiColor - The color, a rgba instance of CSIColor

print

public void print(int x,
                  int y,
                  java.lang.String string,
                  CSIColor csiColor)
Description copied from interface: ConsoleSystemInterface
Prints a String on the console, using a custom color. Does not check for running of the edge of the screen, so calling function must do such a check to avoid errors.

Specified by:
print in interface ConsoleSystemInterface
Parameters:
x - horizontal position
y - vertical position
string - The String to be printed
csiColor - The color, a rgba instance of CSIColor

flushColorTable

public void flushColorTable()
Description copied from interface: ConsoleSystemInterface
This flushes the internal Hashtable for the colors. Should be called when changing the map drasticaly, such as during a level change event.

Specified by:
flushColorTable in interface ConsoleSystemInterface