javax.swing.text
Class GapVector

java.lang.Object
  extended byjavax.swing.text.GapVector
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
GapContent, GapContent.MarkVector

abstract class GapVector
extends Object
implements Serializable

An implementation of a gapped buffer similar to that used by emacs. The underlying storage is a java array of some type, which is known only by the subclass of this class. The array has a gap somewhere. The gap is moved to the location of changes to take advantage of common behavior where most changes occur 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.

Author:
Timothy Prinzing
See Also:
GapContent

Field Summary
private  Object array
          The array of items.
private  int g0
          start of gap in the array
private  int g1
          end of gap in the array
 
Constructor Summary
GapVector()
          Creates a new GapVector object.
GapVector(int initialLength)
          Creates a new GapVector object, with the initial size specified.
 
Method Summary
protected abstract  Object allocateArray(int len)
          Allocate an array to store items of the type appropriate (which is determined by the subclass).
(package private)  void close(int position, int nItems)
          Delete nItems at position.
protected  Object getArray()
          Access to the array.
protected abstract  int getArrayLength()
          Get the length of the allocated array
protected  int getGapEnd()
          Access to the end of the gap.
protected  int getGapStart()
          Access to the start of the gap.
(package private)  int open(int position, int nItems)
          Make space for the given number of items at the given location.
protected  void replace(int position, int rmSize, Object addItems, int addSize)
          Replace the given logical position in the storage with the given new items.
(package private)  void resize(int nsize)
          resize the underlying storage array to the given new size
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.
protected  void shiftGapEndUp(int newGapEnd)
          Adjust the gap end upward.
protected  void shiftGapStartDown(int newGapStart)
          Adjust the gap end downward.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

array

private Object array
The array of items. The type is determined by the subclass.


g0

private int g0
start of gap in the array


g1

private int g1
end of gap in the array

Constructor Detail

GapVector

public GapVector()
Creates a new GapVector object. Initial size defaults to 10.


GapVector

public GapVector(int initialLength)
Creates a new GapVector object, with the initial size specified.

Parameters:
initialLength - the initial size
Method Detail

allocateArray

protected abstract Object allocateArray(int len)
Allocate an array to store items of the type appropriate (which is determined by the subclass).


getArrayLength

protected abstract int getArrayLength()
Get the length of the allocated array


getArray

protected final Object getArray()
Access to the array. The actual type of the array is known only by the subclass.


getGapStart

protected final int getGapStart()
Access to the start of the gap.


getGapEnd

protected final int getGapEnd()
Access to the end of the gap.


replace

protected void replace(int position,
                       int rmSize,
                       Object addItems,
                       int addSize)
Replace the given logical position in the storage with the given new items. This will move the gap to the area being changed if the gap is not currently located at the change location.

Parameters:
position - the location to make the replacement. This is not the location in the underlying storage array, but the location in the contiguous space being modeled.
rmSize - the number of items to remove
addItems - the new items to place in storage.

close

void close(int position,
           int nItems)
Delete nItems at position. Squeezes any marks within the deleted area to position. This moves the gap to the best place by minimizing it's overall movement. The gap must intersect the target block.


open

int open(int position,
         int nItems)
Make space for the given number of items at the given location.

Returns:
the location that the caller should fill in

resize

void resize(int nsize)
resize the underlying storage array to the given new size


shiftEnd

protected void shiftEnd(int newSize)
Make the gap bigger, moving any necessary data and updating the appropriate marks


shiftGap

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.


shiftGapStartDown

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).


shiftGapEndUp

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).