com.cometway.text
Class StringTextBuffer

java.lang.Object
  extended by com.cometway.text.StringTextBuffer
All Implemented Interfaces:
ITextBuffer

public class StringTextBuffer
extends java.lang.Object
implements ITextBuffer

An implementatin of the ITextBuffer interface using the String object to store the contents of the text buffer.


Constructor Summary
StringTextBuffer()
          Initialize an empty text buffer.
StringTextBuffer(java.lang.String s)
          Initialize the text buffer with the supplied String.
 
Method Summary
 void addTextBufferListener(ITextBufferListener l)
          Adds an ITextBufferListener to this object to receive notifications of changes which take place when the text buffer is changed.
 void append(java.lang.String str)
          Appends the specified string to the end of this object and calls the textChanged method of its listeners with the range of the appended text.
 void delete(int fromIndex, int toIndex)
          Removes the specified range of text from this object and calls the textChanged method of its listeners with the location of the removed text.
 TextRange findText(int fromIndex, ITextFinder textFinder)
          Returns the next text range in the text buffer found by the specified text finder starting at the specified index.
 int getLength()
          Returns the size of the text buffer managed by this object.
 java.lang.String getText()
          Returns a string representing the contents of the text buffer.
 java.lang.String getText(int fromIndex, int toIndex)
          Returns a string representing the contents of the text buffer contained within the specified range.
 int indexOf(char ch, int fromIndex)
          Returns the index of the first occurence of the specified character starting at the specified location and continuing to the end of the buffer.
 void insertText(java.lang.String str, int position)
          Inserts a string into the text buffer at the specified location and calls the textChanged method of its listeners with the location of the inserted text.
 int prevIndexOf(char ch, int fromIndex)
          Returns the index of the previous occurence of the specified character starting at the specified location and continuing to the end of the buffer.
 void removeTextBufferListener(ITextBufferListener l)
          Removes an ITextBufferListener from this object.
 void setText(java.lang.String str)
          Sets the value of this text buffer to the specified String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTextBuffer

public StringTextBuffer()
Initialize an empty text buffer.


StringTextBuffer

public StringTextBuffer(java.lang.String s)
Initialize the text buffer with the supplied String.

Parameters:
a - reference to a String.
Method Detail

addTextBufferListener

public void addTextBufferListener(ITextBufferListener l)
Adds an ITextBufferListener to this object to receive notifications of changes which take place when the text buffer is changed.

Specified by:
addTextBufferListener in interface ITextBuffer
Parameters:
l - a reference to an object which implements ITextBufferListener.

append

public void append(java.lang.String str)
Appends the specified string to the end of this object and calls the textChanged method of its listeners with the range of the appended text.

Specified by:
append in interface ITextBuffer
Parameters:
str - a reference to a String.

delete

public void delete(int fromIndex,
                   int toIndex)
Removes the specified range of text from this object and calls the textChanged method of its listeners with the location of the removed text. The fromIndex and toIndex parameters may be specified in any order.

Specified by:
delete in interface ITextBuffer
Parameters:
fromIndex - the starting index from where text will be removed.
toIndex - the ending index to where text will be removed.

findText

public TextRange findText(int fromIndex,
                          ITextFinder textFinder)
Returns the next text range in the text buffer found by the specified text finder starting at the specified index.

Specified by:
findText in interface ITextBuffer
Parameters:
fromIndex - the starting index from where search will begin.
textFinder - a reference to an object implementing ITextFinder.
Returns:
a reference to a TextRange if a matching range was found; null otherwise.

getLength

public int getLength()
Returns the size of the text buffer managed by this object.

Specified by:
getLength in interface ITextBuffer
Returns:
the length of the text buffer.

getText

public java.lang.String getText()
Returns a string representing the contents of the text buffer.

Specified by:
getText in interface ITextBuffer
Returns:
a reference to a String.

getText

public java.lang.String getText(int fromIndex,
                                int toIndex)
Returns a string representing the contents of the text buffer contained within the specified range. The fromIndex and toIndex parameters may be specified in any order.

Specified by:
getText in interface ITextBuffer
Parameters:
fromIndex - the starting index from where text will be taken.
toIndex - the ending index to where text will be taken.
Returns:
a reference to a String.

indexOf

public int indexOf(char ch,
                   int fromIndex)
Returns the index of the first occurence of the specified character starting at the specified location and continuing to the end of the buffer.

Specified by:
indexOf in interface ITextBuffer
Parameters:
ch - the character to match.
fromIndex - the starting index from where the search will begin.
Returns:
the index of the next matching character, or -1 if no match was found.

insertText

public void insertText(java.lang.String str,
                       int position)
Inserts a string into the text buffer at the specified location and calls the textChanged method of its listeners with the location of the inserted text.

Specified by:
insertText in interface ITextBuffer
Parameters:
str - a reference to a String.
atIndex - the index of the location where the text should be inserted.

prevIndexOf

public int prevIndexOf(char ch,
                       int fromIndex)
Returns the index of the previous occurence of the specified character starting at the specified location and continuing to the end of the buffer.

Specified by:
prevIndexOf in interface ITextBuffer
Parameters:
ch - the character to match.
fromIndex - the starting index from where the search will begin.
Returns:
the index of the next matching character, or -1 if no match was found.

removeTextBufferListener

public void removeTextBufferListener(ITextBufferListener l)
Removes an ITextBufferListener from this object.

Specified by:
removeTextBufferListener in interface ITextBuffer
Parameters:
l - a reference to an object which implements ITextBufferListener.

setText

public void setText(java.lang.String str)
Sets the value of this text buffer to the specified String.

Specified by:
setText in interface ITextBuffer
Parameters:
str - a reference to a String.