net.sourceforge.nite.gui.textviewer
Class PositionElementMapper

java.lang.Object
  extended by net.sourceforge.nite.gui.textviewer.PositionElementMapper

public class PositionElementMapper
extends java.lang.Object

Author:
judyr This class is used to map between character positions in a document, and the NTextElements in a document Maintain a flat list of elements in the right order, without repetition. When you need to map a character position to an element, iterate over them until you find one which matches. Then when you do an update you just to increment/decrement the start position of every element after the one which changed

Constructor Summary
PositionElementMapper()
           
 
Method Summary
 void addElement(int position, NTextElement newEl)
          Add an element into the map at the specified index.
 void appendElement(NTextElement e)
          Adds this element and the
 NTextElement getElementAtPosition(int position)
          Return the text element which is placed at the specified character position in the document
 int getTextElementPosition(NTextElement e)
          Return the character position of the specified text element
 void removeElement(NTextElement e)
          The specified textelement has been removed from the document, so remove it from the index.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PositionElementMapper

public PositionElementMapper()
Method Detail

addElement

public void addElement(int position,
                       NTextElement newEl)
Add an element into the map at the specified index. This means incrementing or decrementing positions of the other text elements after that point in the list

Parameters:
index -
e -

appendElement

public void appendElement(NTextElement e)
Adds this element and the

Parameters:
e -

removeElement

public void removeElement(NTextElement e)
The specified textelement has been removed from the document, so remove it from the index. Also update the positions of the text elements after the specified one in the document.

Parameters:
e -

getElementAtPosition

public NTextElement getElementAtPosition(int position)
Return the text element which is placed at the specified character position in the document

Parameters:
index -
Returns:

getTextElementPosition

public int getTextElementPosition(NTextElement e)
Return the character position of the specified text element

Parameters:
e -
Returns: