com.cometway.text
Class TextPointer

java.lang.Object
  extended by com.cometway.text.TextPointer
All Implemented Interfaces:
ITextBufferListener

public final class TextPointer
extends java.lang.Object
implements ITextBufferListener

A pointer to a position in an ITextBuffer.


Constructor Summary
TextPointer()
          Creates an empty TextPointer.
TextPointer(ITextBuffer b)
          Creates a TextPointer that points to the beginning of the given ITextBuffer.
TextPointer(ITextBuffer b, int pos)
          Creates a TextPointer that points to the given position in the given ITextBuffer.
 
Method Summary
 void deleteTo(int pos)
          Deletes all the text from the position pointed to by this instance of TextPointer to the position given as the parameter in the ITextBuffer which this TextPointer is pointing to.
 void dispose()
          Deletes all the text from the position pointed to by this instance of TextPointer to the position pointed to by the TextPointer given as the parameter in the ITextBuffer which this instance of TextPointer is pointing to.
 boolean findNext(char ch)
          Moves the position of this TextPointer to the next instance of the character given as the parameter, starting from the current position.
 boolean findNext(java.lang.String s)
          Moves the position of this TextPointer to the next instance of the String given as the parameter, starting from the current position.
 boolean findPrev(char ch)
          Moves the position of this TextPointer to the previous instance of the character given as the parameter, starting from the current position.
 int getPosition()
           
 ITextBuffer getTextBuffer()
           
 java.lang.String getTextTo(int pos)
          Returns the text from the position pointed to by this TextPointer to the position given by the parameter in the ITextBuffer which this TextPointer is pointing to.
 java.lang.String getTextTo(TextPointer p)
          Returns the text from the position pointed to by this TextPointer to the position pointed to by the TextPointer passed as the parameter in the ITextBuffer which this instance of TextPointer is pointing to.
 void insertText(java.lang.String s)
          Inserts the String passed in as the parameter in the position of this TextPointer into the ITextBuffer which this TextPointer points to.
 void offset(int relativePos)
          Offsets the current position of this TextPointer by the given parameter.
 void setListener(ITextPointerListener l)
          Sets the ITextPointerListener to be notified of changes in this TextPointer.
 void setPosition(int pos)
          Sets the position of this TextPointer.
 void setPosition(TextPointer p)
          Sets the position of this TextPointer to the position of the TextPointer passed in as the parameter.
 void setTextBuffer(ITextBuffer b)
          Sets the TextBuffer which this TextPointer is to be pointing to, and adds itself as an ITextBufferListener with the new ITextBuffer.
 void textChanged(ITextBuffer b, int start, int end)
          implementation of ITextBufferListener.textChanged()
 void textMoved(ITextBuffer b, int start, int offset)
          implementation of ITextBufferListener.textMoved()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextPointer

public TextPointer()
Creates an empty TextPointer.


TextPointer

public TextPointer(ITextBuffer b)
Creates a TextPointer that points to the beginning of the given ITextBuffer.


TextPointer

public TextPointer(ITextBuffer b,
                   int pos)
Creates a TextPointer that points to the given position in the given ITextBuffer.

Method Detail

deleteTo

public void deleteTo(int pos)
Deletes all the text from the position pointed to by this instance of TextPointer to the position given as the parameter in the ITextBuffer which this TextPointer is pointing to.


dispose

public void dispose()
Deletes all the text from the position pointed to by this instance of TextPointer to the position pointed to by the TextPointer given as the parameter in the ITextBuffer which this instance of TextPointer is pointing to. ? public void deleteTo(TextPointer p) { b.delete(this.pos, p.pos); } protected void finalize() throws Throwable { dispose(); } Disposes this TextPointer. This must be called in order for this object to be garbage collected.


getPosition

public int getPosition()
Returns:
Returns the current position.

getTextBuffer

public ITextBuffer getTextBuffer()
Returns:
Returns the current ITextBuffer which this TextPointer is pointing to.

getTextTo

public java.lang.String getTextTo(int pos)
Returns the text from the position pointed to by this TextPointer to the position given by the parameter in the ITextBuffer which this TextPointer is pointing to.


getTextTo

public java.lang.String getTextTo(TextPointer p)
Returns the text from the position pointed to by this TextPointer to the position pointed to by the TextPointer passed as the parameter in the ITextBuffer which this instance of TextPointer is pointing to.


findNext

public boolean findNext(char ch)
Moves the position of this TextPointer to the next instance of the character given as the parameter, starting from the current position.

Returns:
Returns true IFF the character was found.

findNext

public boolean findNext(java.lang.String s)
Moves the position of this TextPointer to the next instance of the String given as the parameter, starting from the current position.

Returns:
Returns true IFF the character was found.

findPrev

public boolean findPrev(char ch)
Moves the position of this TextPointer to the previous instance of the character given as the parameter, starting from the current position.

Returns:
Returns true IFF the character was found.

insertText

public void insertText(java.lang.String s)
Inserts the String passed in as the parameter in the position of this TextPointer into the ITextBuffer which this TextPointer points to.


offset

public void offset(int relativePos)
Offsets the current position of this TextPointer by the given parameter.


setListener

public void setListener(ITextPointerListener l)
Sets the ITextPointerListener to be notified of changes in this TextPointer.


setPosition

public void setPosition(int pos)
Sets the position of this TextPointer.


setPosition

public void setPosition(TextPointer p)
Sets the position of this TextPointer to the position of the TextPointer passed in as the parameter.


setTextBuffer

public void setTextBuffer(ITextBuffer b)
Sets the TextBuffer which this TextPointer is to be pointing to, and adds itself as an ITextBufferListener with the new ITextBuffer.


textChanged

public void textChanged(ITextBuffer b,
                        int start,
                        int end)
implementation of ITextBufferListener.textChanged()

Specified by:
textChanged in interface ITextBufferListener
Parameters:
b - a reference to the text buffer that changed.
start - the starting index of the changed text.
end - the ending index of the changed text.

textMoved

public void textMoved(ITextBuffer b,
                      int start,
                      int offset)
implementation of ITextBufferListener.textMoved()

Specified by:
textMoved in interface ITextBufferListener
Parameters:
b - a reference to the text buffer that moved.
start - the starting index of the moved text.
offset - the relative number of characters the text has moved towards the end of the buffer.