ti.swing.console
Class InputAdapter

java.lang.Object
  extended byti.swing.console.InputAdapter
All Implemented Interfaces:
InputHandler
Direct Known Subclasses:
ColorInputHandler, LogInputHandler

public abstract class InputAdapter
extends java.lang.Object
implements InputHandler

An InputHandler adapter, provides default methods that just fwd the request to the parent. A subclass can just override the methods it cares about.

Version:
0.0
Author:
Rob Clark

Constructor Summary
InputAdapter(InputHandler parent)
          Class Constructor.
 
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 for doing any cleanup.
 java.lang.Object getBufferLock()
          Get an object on which to synchronize access to a region iterator.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputAdapter

public InputAdapter(InputHandler parent)
Class Constructor.

Parameters:
parent - the parent of this input adapter
Method Detail

append

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

Specified by:
append in interface InputHandler
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.

Specified by:
zap in interface InputHandler
Parameters:
num - the number of characters to delete

getOffset

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

Specified by:
getOffset in interface InputHandler
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.

Specified by:
getData in interface InputHandler
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.

Specified by:
addRegion in interface InputHandler
Parameters:
r - region to add
See Also:
removeRegion(ti.swing.console.Region)

removeRegion

public void removeRegion(Region r)
Remove a region.

Specified by:
removeRegion in interface InputHandler
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 the buffer-lock, to* prevent concurrent modification problems. For example:
   synchronized( ih.getBufferLock() )
   {
     for( Iterator itr=ih.getRegions( off, len ); itr.hasNext(); )
     {
       ...
     }
   }
 

Specified by:
getRegions in interface InputHandler
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 region iterator.

Specified by:
getBufferLock in interface InputHandler
Returns:
an object suitable for synchronizing region iterator 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.

Specified by:
lock in interface InputHandler
See Also:
unlock()

unlock

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

Specified by:
unlock in interface InputHandler
See Also:
lock()

close

public void close()
Close method for doing any cleanup.

Specified by:
close in interface InputHandler