net.slashie.libjcsi.wswing
Class WSwingConsoleInterface

java.lang.Object
  extended by net.slashie.libjcsi.wswing.WSwingConsoleInterface
All Implemented Interfaces:
java.awt.event.ComponentListener, java.lang.Runnable, java.util.EventListener, ConsoleSystemInterface

public class WSwingConsoleInterface
extends java.lang.Object
implements ConsoleSystemInterface, java.lang.Runnable, java.awt.event.ComponentListener

Swing interface for input and output. Returns keystrokes as CharKeys. Shows the characters in a Frame

Author:
Santiago Zapata, Eben Howard

Field Summary
static java.awt.Font consoleFont
          Current printing cursor position
static int xdim
           
static int ydim
           
 
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
WSwingConsoleInterface(java.lang.String windowName, boolean sandboxDeploy)
          Allows for setting the window's name and deploying as a Java WebStart application.
 
Method Summary
 void cls()
          Clears the screen
 void componentHidden(java.awt.event.ComponentEvent e)
           
 void componentMoved(java.awt.event.ComponentEvent e)
           
 void componentResized(java.awt.event.ComponentEvent e)
           
 void componentShown(java.awt.event.ComponentEvent e)
           
 void flash(int color)
          Flashes the output area a specified color.
 void flushColorTable()
          This flushes the internal Hashtable for the colors.
 int getColor(java.lang.String colorName)
           
 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 locate(int x, int y)
           
 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
 CSIColor peekCSIColor(int x, int y)
           
 void print(int x, int y, char what, CSIColor color)
          Prints a character on the console, using a custom color
 void print(int x, int y, char what, CSIColor color, CSIColor back)
           
 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 what, CSIColor color)
          Prints a String on the console, using a custom color.
 void print(int x, int y, java.lang.String what, CSIColor color, CSIColor background)
           
 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 toNotify)
          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 run()
           
 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
 

Field Detail

consoleFont

public static java.awt.Font consoleFont
Current printing cursor position


xdim

public static int xdim

ydim

public static int ydim
Constructor Detail

WSwingConsoleInterface

public WSwingConsoleInterface(java.lang.String windowName,
                              boolean sandboxDeploy)
Allows for setting the window's name and deploying as a Java WebStart application.

Parameters:
windowName -
sandboxDeploy - true if intended at a Java Webstart application
Method Detail

flash

public void flash(int color)
Flashes the output area a specified color. Currently inoperable.

Specified by:
flash in interface ConsoleSystemInterface
Parameters:
color -

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

cls

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

Specified by:
cls in interface ConsoleSystemInterface

locate

public void locate(int x,
                   int y)

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

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,
                  CSIColor color)
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
what - The String to be printed
color - The color, a rgba instance of CSIColor

print

public void print(int x,
                  int y,
                  java.lang.String what,
                  CSIColor color,
                  CSIColor background)

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,
                  char what,
                  CSIColor color)
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
what - The character to be printed
color - The color, a rgba instance of CSIColor

print

public void print(int x,
                  int y,
                  char what,
                  CSIColor color,
                  CSIColor back)

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

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

refresh

public void refresh(java.lang.Thread toNotify)
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

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

getColor

public int getColor(java.lang.String colorName)

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

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

peekCSIColor

public CSIColor peekCSIColor(int x,
                             int y)

run

public void run()
Specified by:
run in interface java.lang.Runnable

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)

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

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Specified by:
componentResized in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Specified by:
componentShown in interface java.awt.event.ComponentListener

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