Home » openjdk-7 » javax » swing » text » [javadoc | source]
javax.swing.text
public class: GapContent [javadoc | source]
java.lang.Object
   javax.swing.text.GapVector
      javax.swing.text.GapContent

All Implemented Interfaces:
    Content, java$io$Serializable

An implementation of the AbstractDocument.Content interface implemented using a gapped buffer similar to that used by emacs. The underlying storage is a array of unicode characters with a gap somewhere. The gap is moved to the location of changes to take advantage of common behavior where most changes are in the same location. Changes that occur at a gap boundary are generally cheap and moving the gap is generally cheaper than moving the array contents directly to accomodate the change.

The positions tracking change are also generally cheap to maintain. The Position implementations (marks) store the array index and can easily calculate the sequential position from the current gap location. Changes only require update to the the marks between the old and new gap boundaries when the gap is moved, so generally updating the marks is pretty cheap. The marks are stored sorted so they can be located quickly with a binary search. This increases the cost of adding a mark, and decreases the cost of keeping the mark updated.

Nested Class Summary:
final class  GapContent.MarkData  Holds the data for a mark... separately from the real mark so that the real mark (Position that the caller of createPosition holds) can be collected if there are no more references to it. The update table holds only a reference to this data. 
final class  GapContent.StickyPosition   
static class  GapContent.MarkVector   
final class  GapContent.UndoPosRef  Used to hold a reference to a Mark that is being reset as the result of removing from the content. 
class  GapContent.InsertUndo  UnoableEdit created for inserts. 
class  GapContent.RemoveUndo  UndoableEdit created for removes. 
Field Summary
static final  int GROWTH_SIZE     
Constructor:
 public GapContent() 
 public GapContent(int initialLength) 
Method from javax.swing.text.GapContent Summary:
allocateArray,   compare,   createPosition,   findMarkAdjustIndex,   findSortIndex,   getArrayLength,   getChars,   getNewArraySize,   getPositionsInRange,   getString,   insertString,   length,   remove,   removeUnusedMarks,   resetMarksAtZero,   shiftEnd,   shiftGap,   shiftGapEndUp,   shiftGapStartDown,   updateUndoPositions
Methods from javax.swing.text.GapVector:
allocateArray,   close,   getArray,   getArrayLength,   getGapEnd,   getGapStart,   getNewArraySize,   open,   replace,   resize,   shiftEnd,   shiftGap,   shiftGapEndUp,   shiftGapStartDown
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.text.GapContent Detail:
 protected Object allocateArray(int len) 
    Allocate an array to store items of the type appropriate (which is determined by the subclass).
 final int compare(MarkData o1,
    MarkData o2) 
    Compares two marks.
 public Position createPosition(int offset) throws BadLocationException 
    Creates a position within the content that will track change as the content is mutated.
 final int findMarkAdjustIndex(int searchIndex) 
    Finds the index to start mark adjustments given some search index.
 final int findSortIndex(MarkData o) 
    Finds the index of where to insert a new mark.
 protected int getArrayLength() 
    Get the length of the allocated array.
 public  void getChars(int where,
    int len,
    Segment chars) throws BadLocationException 
    Retrieves a portion of the content. If the desired content spans the gap, we copy the content. If the desired content does not span the gap, the actual store is returned to avoid the copy since it is contiguous.
 int getNewArraySize(int reqSize) 
    Overridden to make growth policy less agressive for large text amount.
 protected Vector getPositionsInRange(Vector v,
    int offset,
    int length) 
    Returns a Vector containing instances of UndoPosRef for the Positions in the range offset to offset + length. If v is not null the matching Positions are placed in there. The vector with the resulting Positions are returned.
 public String getString(int where,
    int len) throws BadLocationException 
    Retrieves a portion of the content.
 public UndoableEdit insertString(int where,
    String str) throws BadLocationException 
    Inserts a string into the content.
 public int length() 
    Returns the length of the content.
 public UndoableEdit remove(int where,
    int nitems) throws BadLocationException 
    Removes part of the content.
 final  void removeUnusedMarks() 
    Remove all unused marks out of the sorted collection of marks.
 protected  void resetMarksAtZero() 
    Resets all the marks that have an offset of 0 to have an index of zero as well.
 protected  void shiftEnd(int newSize) 
    Make the gap bigger, moving any necessary data and updating the appropriate marks
 protected  void shiftGap(int newGapStart) 
    Move the start of the gap to a new location, without changing the size of the gap. This moves the data in the array and updates the marks accordingly.
 protected  void shiftGapEndUp(int newGapEnd) 
    Adjust the gap end upward. This doesn't move any data, but it does update any marks affected by the boundary change. All marks from the old gap end up to the new gap end are squeezed to the end of the gap (their location has been removed).
 protected  void shiftGapStartDown(int newGapStart) 
    Adjust the gap end downward. This doesn't move any data, but it does update any marks affected by the boundary change. All marks from the old gap start down to the new gap start are squeezed to the end of the gap (their location has been removed).
 protected  void updateUndoPositions(Vector positions,
    int offset,
    int length) 
    Resets the location for all the UndoPosRef instances in positions.

    This is meant for internal usage, and is generally not of interest to subclasses.