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 updating 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.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | GapContent.
UnoableEdit created for inserts. |
| pack-priv class | GapContent.
Holds the data for a mark... |
| pack-priv static class | |
| pack-priv class | GapContent.
UndoableEdit created for removes. |
| pack-priv class | |
| pack-priv class | GapContent.
Used to hold a reference to a Mark that is being reset as the result of removing from the content. |
| Modifier and Type | Field and Description |
|---|---|
| private static final char[] | |
| pack-priv static final int | |
| private transient GapContent. | |
| private transient ReferenceQueue | |
| private transient GapContent. | search
Record used for searching for the place to start updating mark indexes when the gap boundaries are moved. |
| private transient int | unusedMarks
The number of unused mark entries |
| Access | Constructor and Description |
|---|---|
| public | |
| public | GapContent(int
the initial size initialLength)Creates a new GapContent object, with the initial size specified. |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | allocateArray(int len)
Implements abstract javax. Allocate an array to store items of the type appropriate (which is determined by the subclass). |
| pack-priv final int | Returns: < 0 if o1 < o2, 0 if the same, > 0 if o1 > o2the first object o1,the second object o2Compares two marks. |
| public Position | Returns: the positionthe offset to track >= 0 offset)Implements javax. Creates a position within the content that will track change as the content is mutated. |
| pack-priv final int | findMarkAdjustIndex(int searchIndex)
Finds the index to start mark adjustments given some search index. |
| pack-priv final int | Returns: the indexthe mark to insert oFinds the index of where to insert a new mark. |
| protected int | getArrayLength()
Implements abstract javax. Get the length of the allocated array. |
| public void | getChars(int
the starting position >= 0, where + len <= length() where, int the number of characters to retrieve >= 0 len, Segment the Segment object to return the characters in chars)Implements javax. Retrieves a portion of the content. |
| pack-priv int | getNewArraySize(int reqSize)
Overrides javax. Overridden to make growth policy less aggressive for large text amount. |
| protected Vector | Returns: the set of instancesthe Vector to use, with a new one created on null v, int the starting offset >= 0 offset, int the length >= 0 length)Returns a Vector containing instances of UndoPosRef for the
Positions in the range
|
| public String | Returns: a string representing the contentthe starting position >= 0 where, int the length to retrieve >= 0 len)Implements javax. Retrieves a portion of the content. |
| public UndoableEdit | Returns: an UndoableEdit object for undoingthe starting position >= 0, < length() where, String the non-null string to insert str)Implements javax. Inserts a string into the content. |
| public int | Returns: the length >= 1Implements javax. Returns the length of the content. |
| private void | |
| public UndoableEdit | Returns: an UndoableEdit object for undoingthe starting position >= 0, where + nitems < length() where, int the number of characters to remove >= 0 nitems)Implements javax. Removes part of the content. |
| pack-priv final void | |
| protected void | |
| pack-priv void | resize(int nsize)
Overrides javax. resize the underlying storage array to the given new size |
| protected void | shiftEnd(int newSize)
Overrides javax. Make the gap bigger, moving any necessary data and updating the appropriate marks |
| protected void | shiftGap(int newGapStart)
Overrides javax. Move the start of the gap to a new location, without changing the size of the gap. |
| protected void | shiftGapEndUp(int newGapEnd)
Overrides javax. Adjust the gap end upward. |
| protected void | shiftGapStartDown(int newGapStart)
Overrides javax. Adjust the gap end downward. |
| protected void | updateUndoPositions(Vector<E>
the UndoPosRef instances to reset positions, int where the string was inserted offset, int length of inserted string length)Resets the location for all the UndoPosRef instances
in |
| empty | back to summary |
|---|---|
| private static final char[] empty | |
| GROWTH_SIZE | back to summary |
|---|---|
| pack-priv static final int GROWTH_SIZE | |
| marks | back to summary |
|---|---|
| private transient GapContent. | |
| queue | back to summary |
|---|---|
| private transient ReferenceQueue<GapContent. | |
| search | back to summary |
|---|---|
| private transient GapContent. Record used for searching for the place to start updating mark indexes when the gap boundaries are moved. | |
| unusedMarks | back to summary |
|---|---|
| private transient int unusedMarks The number of unused mark entries | |
| GapContent | back to summary |
|---|---|
| public GapContent() Creates a new GapContent object. Initial size defaults to 10. | |
| GapContent | back to summary |
|---|---|
| public GapContent(int initialLength) Creates a new GapContent object, with the initial size specified. The initial size will not be allowed to go below 2, to give room for the implied break and the gap.
| |
| allocateArray | back to summary |
|---|---|
| protected Object allocateArray(int len) Implements abstract javax. Allocate an array to store items of the type appropriate (which is determined by the subclass). | |
| compare | back to summary |
|---|---|
| pack-priv final int compare(GapContent. Compares two marks.
| |
| createPosition | back to summary |
|---|---|
| public Position createPosition(int offset) throws BadLocationException Implements javax. Creates a position within the content that will track change as the content is mutated.
| |
| findMarkAdjustIndex | back to summary |
|---|---|
| pack-priv final int findMarkAdjustIndex(int searchIndex) Finds the index to start mark adjustments given some search index. | |
| findSortIndex | back to summary |
|---|---|
| pack-priv final int findSortIndex(GapContent. Finds the index of where to insert a new mark.
| |
| getArrayLength | back to summary |
|---|---|
| protected int getArrayLength() Implements abstract javax. Get the length of the allocated array. | |
| getChars | back to summary |
|---|---|
| public void getChars(int where, int len, Segment chars) throws BadLocationException Implements javax. 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.
| |
| getNewArraySize | back to summary |
|---|---|
| pack-priv int getNewArraySize(int reqSize) Overrides javax. Overridden to make growth policy less aggressive for large text amount. | |
| getPositionsInRange | back to summary |
|---|---|
| protected Vector Returns a Vector containing instances of UndoPosRef for the
Positions in the range
| |
| getString | back to summary |
|---|---|
| public String getString(int where, int len) throws BadLocationException Implements javax. Retrieves a portion of the content.
| |
| insertString | back to summary |
|---|---|
| public UndoableEdit insertString(int where, String str) throws BadLocationException Implements javax. Inserts a string into the content.
| |
| length | back to summary |
|---|---|
| public int length() Implements javax. Returns the length of the content.
| |
| readObject | back to summary |
|---|---|
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException
| |
| remove | back to summary |
|---|---|
| public UndoableEdit remove(int where, int nitems) throws BadLocationException Implements javax. Removes part of the content.
| |
| removeUnusedMarks | back to summary |
|---|---|
| pack-priv final void removeUnusedMarks() Remove all unused marks out of the sorted collection of marks. | |
| resetMarksAtZero | back to summary |
|---|---|
| protected void resetMarksAtZero() Resets all the marks that have an offset of 0 to have an index of zero as well. | |
| resize | back to summary |
|---|---|
| pack-priv void resize(int nsize) Overrides javax. Doc from javax. resize the underlying storage array to the given new size
| |
| shiftEnd | back to summary |
|---|---|
| protected void shiftEnd(int newSize) Overrides javax. Make the gap bigger, moving any necessary data and updating the appropriate marks | |
| shiftGap | back to summary |
|---|---|
| protected void shiftGap(int newGapStart) Overrides javax. 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. | |
| shiftGapEndUp | back to summary |
|---|---|
| protected void shiftGapEndUp(int newGapEnd) Overrides javax. 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). | |
| shiftGapStartDown | back to summary |
|---|---|
| protected void shiftGapStartDown(int newGapStart) Overrides javax. 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). | |
| updateUndoPositions | back to summary |
|---|---|
| protected void updateUndoPositions(Vector<E> positions, int offset, int length) Resets the location for all the UndoPosRef instances
in This is meant for internal usage, and is generally not of interest to subclasses.
| |
| Modifier and Type | Field and Description |
|---|---|
| protected int | length
Length of string inserted. |
| protected int | offset
Where string was inserted. |
| protected Vector | posRefs
An array of instances of UndoPosRef for the Positions in the range that was removed, valid after undo. |
| protected String | string
The string that was inserted. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | redo()
Overrides javax. Implements javax. Throws |
| public void | undo()
Overrides javax. Implements javax. Throws |
| length | back to summary |
|---|---|
| protected int length Length of string inserted. | |
| offset | back to summary |
|---|---|
| protected int offset Where string was inserted. | |
| posRefs | back to summary |
|---|---|
| protected Vector<E> posRefs An array of instances of UndoPosRef for the Positions in the range that was removed, valid after undo.
| |
| string | back to summary |
|---|---|
| protected String string The string that was inserted. This will only be valid after an undo. | |
| InsertUndo | back to summary |
|---|---|
| protected InsertUndo(int offset, int length) | |
| redo | back to summary |
|---|---|
| public void redo() throws CannotRedoException Overrides javax. Implements javax. Doc from javax. Throws
| |
| undo | back to summary |
|---|---|
| public void undo() throws CannotUndoException Overrides javax. Implements javax. Doc from javax. Throws
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | MarkData(int index, GapContent.
|
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| pack-priv GapContent. |
| index | back to summary |
|---|---|
| pack-priv int index | |
| MarkData | back to summary |
|---|---|
| pack-priv MarkData(int index) | |
| MarkData | back to summary |
|---|---|
| pack-priv MarkData(int index, GapContent. | |
| getOffset | back to summary |
|---|---|
| public int getOffset() Fetch the location in the contiguous sequence being modeled. The index in the gap array is held by the mark, so it is adjusted according to it's relationship to the gap. | |
| getPosition | back to summary |
|---|---|
| pack-priv GapContent. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv GapContent. |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| protected Object | allocateArray(int len)
Implements abstract javax. Allocate an array to store items of the type appropriate (which is determined by the subclass). |
| public GapContent. | |
| protected int | getArrayLength()
Implements abstract javax. Get the length of the allocated array |
| public void | |
| protected void | replaceRange(int start, int end, Object[] marks)
Replaces the elements in the specified range with the passed in objects. |
| public int |
| oneMark | back to summary |
|---|---|
| pack-priv GapContent. | |
| MarkVector | back to summary |
|---|---|
| pack-priv MarkVector() | |
| MarkVector | back to summary |
|---|---|
| pack-priv MarkVector(int size) | |
| addElement | back to summary |
|---|---|
| public void addElement(GapContent. Add a mark to the end | |
| allocateArray | back to summary |
|---|---|
| protected Object allocateArray(int len) Implements abstract javax. Allocate an array to store items of the type appropriate (which is determined by the subclass). | |
| elementAt | back to summary |
|---|---|
| public GapContent. Fetches the mark at the given index | |
| getArrayLength | back to summary |
|---|---|
| protected int getArrayLength() Implements abstract javax. Get the length of the allocated array | |
| insertElementAt | back to summary |
|---|---|
| public void insertElementAt(GapContent. Inserts a mark into the vector | |
| replaceRange | back to summary |
|---|---|
| protected void replaceRange(int start, int end, Object[] marks) Replaces the elements in the specified range with the passed
in objects. This will NOT adjust the gap. The passed in indices
do not account for the gap, they are the same as would be used
int | |
| size | back to summary |
|---|---|
| public int size() Returns the number of marks currently held | |
| Modifier and Type | Field and Description |
|---|---|
| protected int | length
Length of string removed. |
| protected int | offset
Where the string was removed from. |
| protected Vector | posRefs
An array of instances of UndoPosRef for the Positions in the range that was removed, valid before undo. |
| protected String | string
The string that was removed. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | redo()
Overrides javax. Implements javax. Throws |
| public void | undo()
Overrides javax. Implements javax. Throws |
| length | back to summary |
|---|---|
| protected int length Length of string removed. | |
| offset | back to summary |
|---|---|
| protected int offset Where the string was removed from. | |
| posRefs | back to summary |
|---|---|
| protected Vector<GapContent. An array of instances of UndoPosRef for the Positions in the range that was removed, valid before undo. | |
| string | back to summary |
|---|---|
| protected String string The string that was removed. This is valid when redo is valid. | |
| RemoveUndo | back to summary |
|---|---|
protected RemoveUndo(int offset, String string)
| |
| redo | back to summary |
|---|---|
| public void redo() throws CannotRedoException Overrides javax. Implements javax. Doc from javax. Throws
| |
| undo | back to summary |
|---|---|
| public void undo() throws CannotUndoException Overrides javax. Implements javax. Doc from javax. Throws
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv GapContent. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public int | getOffset()
Implements javax. Fetches the current offset within the document. |
| pack-priv void | |
| public String |
| mark | back to summary |
|---|---|
| pack-priv GapContent. | |
| StickyPosition | back to summary |
|---|---|
| pack-priv StickyPosition() | |
| getOffset | back to summary |
|---|---|
| public int getOffset() Implements javax. Doc from javax. Fetches the current offset within the document. | |
| setMark | back to summary |
|---|---|
| pack-priv void setMark(GapContent. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| protected GapContent. | rec
Mark to reset offset. |
| protected int | undoLocation
Previous Offset of rec. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected void | resetLocation(int
end location of inserted string. endOffset, int resulting end of gap. g1)Resets the location of the Position to the offset when the receiver was instantiated. |
| rec | back to summary |
|---|---|
| protected GapContent. Mark to reset offset. | |
| undoLocation | back to summary |
|---|---|
| protected int undoLocation Previous Offset of rec. | |
| UndoPosRef | back to summary |
|---|---|
| pack-priv UndoPosRef(GapContent. | |
| resetLocation | back to summary |
|---|---|
| protected void resetLocation(int endOffset, int g1) Resets the location of the Position to the offset when the receiver was instantiated.
| |