jcurzez.peer.ansi
Class PeerScreen

java.lang.Object
  |
  +--jcurzez.peer.ansi.PeerScreen
All Implemented Interfaces:
ScreenPeer

public final class PeerScreen
extends java.lang.Object
implements ScreenPeer

This is the ansi implementation of jcurzez. There are no native calls, thus this implementation should work on any platform that supports Java and ansi.

For retrieving size of the screen, we use four system properties:

Those properties can be set on JVM invocation using tput(1), or environment variables COLUMNS and LINES. If they are not set, they default to 80, 24 (or 25 for Windows) and 0, 0.

Version:
0.0.4
Author:
Thomas Girard

Field Summary
private  int columns
          Number of columns the screen has.
private  int lines
          Number of lines the screen has.
private  Cell previousCell
          To optimize, we keep the last cell.
private  int previousX
          To optimize cursor motion, we store previous cursor position.
private  int previousY
          To optimize cursor motion, we store previous cursor position.
private  java.lang.StringBuffer text
          Current representation of the content of the screen.
 
Constructor Summary
PeerScreen()
          Constructs a new ANSI PeerScreen.
 
Method Summary
private  void attributeToEscapeSequence(Attribute a)
          Computes the representation of the attribute a, and appends this representation to text.
 void beep()
          Emits an audio beep.
 void end()
          Does nothing.
 int getColumns()
          Relies on the jcurzez.term.columns property, or defaults to 80 if this property is not set.
 int getFirstX()
          Retrieves the x coordinate by the time the screen object is created.
 int getFirstY()
          Retrieves the y coordinate by the time the screen object is created.
 int getLines()
          Retrieves the number of lines the screen has.
 void gotoXY(int x, int y)
          Moves the cursor on the physical screen at specified position.
 void printCell(int x, int y, Cell cell)
          Prints the cell cell on the physical screen at specified position.
 void setCursorVisibility(int v)
          Does nothing for the ansi implementation.
 void update()
          Updates the physical screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columns

private int columns
Number of columns the screen has.


lines

private int lines
Number of lines the screen has.


previousX

private int previousX
To optimize cursor motion, we store previous cursor position.


previousY

private int previousY
To optimize cursor motion, we store previous cursor position.


text

private java.lang.StringBuffer text
Current representation of the content of the screen.


previousCell

private Cell previousCell
To optimize, we keep the last cell. If the next adjacent cell has the same decoration, we won't send escape sequences again.

Constructor Detail

PeerScreen

public PeerScreen()
Constructs a new ANSI PeerScreen. Then sets colors' real objects (using Color.setRealColor(java.lang.Object)) which, for the ansi implementation, are escape sequences.

Method Detail

gotoXY

public void gotoXY(int x,
                   int y)
Description copied from interface: ScreenPeer
Moves the cursor on the physical screen at specified position. This method must not be called directly. x and y should be consistent. This method is used by refresh to move the cursor where it is supposed to be.

Specified by:
gotoXY in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
Parameters:
x - x coordinate where to send the cursor. This is an absolute coordinate.
y - y coordinate where to send the cursor. This is an absolute coordinate.
See Also:
AbstractWindow.refresh()

attributeToEscapeSequence

private void attributeToEscapeSequence(Attribute a)
Computes the representation of the attribute a, and appends this representation to text.

Parameters:
a - the attribute we want to use.

printCell

public void printCell(int x,
                      int y,
                      Cell cell)
Description copied from interface: ScreenPeer
Prints the cell cell on the physical screen at specified position.

Specified by:
printCell in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
Parameters:
x - x coordinate where to send the cursor. This is an absolute coordinate.
y - y coordinate where to send the cursor. This is an absolute coordinate.
cell - the cell to print at this position.
See Also:
Cell

getColumns

public int getColumns()
Relies on the jcurzez.term.columns property, or defaults to 80 if this property is not set.

Specified by:
getColumns in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
Returns:
the number of columns the screen has.

getLines

public int getLines()
Description copied from interface: ScreenPeer
Retrieves the number of lines the screen has. This is often 25, but it may be different if you use a xterm, a different screen mode, or frame buffering.

Specified by:
getLines in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
Returns:
the number of lines the screen has.

getFirstX

public int getFirstX()
Description copied from interface: ScreenPeer
Retrieves the x coordinate by the time the screen object is created.

Specified by:
getFirstX in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
Returns:
the x coordinate at the beginning.

getFirstY

public int getFirstY()
Description copied from interface: ScreenPeer
Retrieves the y coordinate by the time the screen object is created.

Specified by:
getFirstY in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
Returns:
the y coordinate at the beginning.

update

public void update()
Description copied from interface: ScreenPeer
Updates the physical screen. This method provides a way for a peer to optimize its display. It is called when all needed cells have been printed, and before the cursor is moved back - using ScreenPeer.gotoXY(int, int) - to where it should be.

Specified by:
update in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
See Also:
AbstractWindow.refresh()

setCursorVisibility

public void setCursorVisibility(int v)
Does nothing for the ansi implementation.

Specified by:
setCursorVisibility in interface ScreenPeer
Following copied from interface: jcurzez.peer.ScreenPeer
Parameters:
v - visibility of the cursor. One of NORMAL, INVISIBLE, VERY_VISIBLE.
See Also:
Cursor

beep

public void beep()
Description copied from interface: ScreenPeer
Emits an audio beep.

Specified by:
beep in interface ScreenPeer

end

public void end()
Does nothing.

Specified by:
end in interface ScreenPeer


Send me an email