ti.swing.console
Interface InputHandler

All Known Implementing Classes:
InputAdapter

public interface InputHandler

The way data gets input to the Console is via an input handler. The input handlers can be chained together to handle more sophisticated input (for example embedded HTML or ANSI escape codes).

Version:
0.0
Author:
Rob Clark

Method Summary
 void addRegion(Region r)
          Add a region mapped over a section of character stream.
 void append(char[] cbuf, int off, int len)
          Append characters to the end of the character stream.
 void close()
          Close method to do any cleanup.
 java.lang.Object getBufferLock()
          Get an object on which to synchronize access to a buffer.
 char[] getData(int offset, int len)
          Get the data within the specified region.
 int getOffset()
          Get the current offset of the last character in the character stream.
 java.util.Iterator getRegions(int offset, int len)
          Get an iterator of the regions containing the specified range.
 void lock()
          Lock the console from repaints.
 void removeRegion(Region r)
          Remove a region.
 void unlock()
          Unlock the console, rerendering if needed.
 void zap(int num)
          Delete characters from end of character stream.
 

Method Detail

append

public void append(char[] cbuf,
                   int off,
                   int len)
Append characters to the end of the character stream.

Parameters:
cbuf - the character buffer
off - the offset into cbuf to first character to append
len - the number of characters to append

zap

public void zap(int num)
Delete characters from end of character stream.

Parameters:
num - the number of characters to delete

getOffset

public int getOffset()
Get the current offset of the last character in the character stream.

Returns:
an offset

getData

public char[] getData(int offset,
                      int len)
Get the data within the specified region. If the requested region has scrolled past the top of the buffer, the returned data may be truncated.

Parameters:
offset - the begining of the range
len - the length of the range in characters
Returns:
the data

addRegion

public void addRegion(Region r)
Add a region mapped over a section of character stream. If the section of the character stream over which the region is mapped has scrolled off the top of the fixed size row buffer, the region will be automatically removed.

Parameters:
r - region to add
See Also:
removeRegion(ti.swing.console.Region)

removeRegion

public void removeRegion(Region r)
Remove a region.

Parameters:
r - region to remove
See Also:
addRegion(ti.swing.console.Region)

getRegions

public java.util.Iterator getRegions(int offset,
                                     int len)
Get an iterator of the regions containing the specified range. Access to the iterator must be synchronized on thebuffer-lock, to prevent concurrent modification problems. For example:
   synchronized( ih.getBufferLock() )
   {
     for( Iterator itr=ih.getRegions( off, len ); itr.hasNext(); )
     {
       ...
     }
   }
 

Parameters:
offset - the begining of the range
len - the length of the range in characters
Returns:
an iterator of Region
See Also:
getBufferLock()

getBufferLock

public java.lang.Object getBufferLock()
Get an object on which to synchronize access to a buffer.

Returns:
an object suitable for synchronizing access
See Also:
getRegions(int, int)

lock

public void lock()
Lock the console from repaints. This can be used to batch multiple updates (append(char[], int, int), zap(int), addRegion(ti.swing.console.Region), removeRegion(ti.swing.console.Region)) and only trigger a single repaint at the end.

See Also:
unlock()

unlock

public void unlock()
Unlock the console, rerendering if needed.

See Also:
lock()

close

public void close()
Close method to do any cleanup.