JavaTM 2 Platform
Standard Ed. 6

javax.swing.text
类 GapContent

java.lang.Object
  继承者 javax.swing.text.GapContent
所有已实现的接口:
Serializable, AbstractDocument.Content

public class GapContent
extends Object
implements AbstractDocument.Content, Serializable

AbstractDocument.Content 接口的一个实现,使用类似于 emacs 使用的间隙缓冲区来实现。基础存储是一个 unicode 字符数组,在数组的某个位置存在间隙。将该间隙移动到要进行更改的位置,以便利用一般行为,让多数更改都在原来的位置上进行。在间隙边界发生更改通常很容易,而且移动间隙通常比直接移动数组内容来适应更改要更容易。

跟踪更改的位置也通常容易维护。Position 实现(标记)存储数组索引,并可方便地根据当前间隙位置计算连续位置。更改只需要更新移动间隙时新旧间隙边界之间的标记,因此更新标记通常会相当容易。该标记是按顺序存储的,所以可以使用二分查找法快速找到。这提高了添加标记的成本,但降低了保持标记更新的成本。


构造方法摘要
GapContent()
          创建新的 GapContent 对象。
GapContent(int initialLength)
          创建具有指定初始大小的新 GapContent 对象。
 
方法摘要
protected  Object allocateArray(int len)
          分配一个存储适当类型项的数组(由子类确定)。
 Position createPosition(int offset)
          在内容中创建一个位置,使其在内容发生变化时能跟踪内容的更改。
protected  Object getArray()
          Access to the array.
protected  int getArrayLength()
          获取分配的数组的长度。
 void getChars(int where, int len, Segment chars)
          检索部分内容。
protected  int getGapEnd()
          Access to the end of the gap.
protected  int getGapStart()
          Access to the start of the gap.
protected  Vector getPositionsInRange(Vector v, int offset, int length)
          返回一个包含 UndoPosRef 实例的 Vector,其 Position 的范围从 offsetoffset + length
 String getString(int where, int len)
          检索部分内容。
 UndoableEdit insertString(int where, String str)
          在内容中插入字符串。
 int length()
          返回内容的长度。
 UndoableEdit remove(int where, int nitems)
          移除部分内容。
protected  void replace(int position, int rmSize, Object addItems, int addSize)
          Replace the given logical position in the storage with the given new items.
protected  void resetMarksAtZero()
          重新设置具有 0 偏移量的所有标记,使其也有零索引。
protected  void shiftEnd(int newSize)
          扩大间隙、移动任何必要的数据和更新适当的标记。
protected  void shiftGap(int newGapStart)
          将间隙的起始点移动到新位置,而不更改间隙的大小。
protected  void shiftGapEndUp(int newGapEnd)
          调整间隙,使其结尾向前扩展。
protected  void shiftGapStartDown(int newGapStart)
          调整间隙,使其结尾向后扩展。
protected  void updateUndoPositions(Vector positions, int offset, int length)
          重新设置处在 positions 的所有 UndoPosRef 实例的位置。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

GapContent

public GapContent()
创建新的 GapContent 对象。初始大小默认为 10。


GapContent

public GapContent(int initialLength)
创建具有指定初始大小的新 GapContent 对象。初始大小不允许小于 2,以便留出空间供再次包含间隙和拆分操作。

参数:
initialLength - 初始大小
方法详细信息

allocateArray

protected Object allocateArray(int len)
分配一个存储适当类型项的数组(由子类确定)。


getArrayLength

protected int getArrayLength()
获取分配的数组的长度。


length

public int length()
返回内容的长度。

指定者:
接口 AbstractDocument.Content 中的 length
返回:
长度,该值 >= 1
另请参见:
AbstractDocument.Content.length()

insertString

public UndoableEdit insertString(int where,
                                 String str)
                          throws BadLocationException
在内容中插入字符串。

指定者:
接口 AbstractDocument.Content 中的 insertString
参数:
where - 起始位置,该值 >= 0 且 < length()
str - 要插入的非 null 字符串
返回:
撤消的 UndoableEdit 对象
抛出:
BadLocationException - 如果指定位置无效
另请参见:
AbstractDocument.Content.insertString(int, java.lang.String)

remove

public UndoableEdit remove(int where,
                           int nitems)
                    throws BadLocationException
移除部分内容。

指定者:
接口 AbstractDocument.Content 中的 remove
参数:
where - 起始位置,该值 >= 0 且 where + nitems < length()
nitems - 要移除的字符数,该值 >= 0
返回:
撤消的 UndoableEdit 对象
抛出:
BadLocationException - 如果指定位置无效
另请参见:
AbstractDocument.Content.remove(int, int)

getString

public String getString(int where,
                        int len)
                 throws BadLocationException
检索部分内容。

指定者:
接口 AbstractDocument.Content 中的 getString
参数:
where - 起始位置,该值 >= 0
len - 要检索的长度,该值 >= 0
返回:
一个表示该内容的字符串
抛出:
BadLocationException - 如果指定位置无效
另请参见:
AbstractDocument.Content.getString(int, int)

getChars

public void getChars(int where,
                     int len,
                     Segment chars)
              throws BadLocationException
检索部分内容。如果所需内容跨越间隙,则要复制该内容。如果所需内容未跨越间隙,则由于它是连续的,所以返回实际的存储而不用复制。

指定者:
接口 AbstractDocument.Content 中的 getChars
参数:
where - 起始位置,该值 >= 0,where + len <= length()
len - 要检索的字符数,该值 >= 0
chars - 要在其中返回字符的 Segment 对象
抛出:
BadLocationException - 如果指定位置无效
另请参见:
AbstractDocument.Content.getChars(int, int, javax.swing.text.Segment)

createPosition

public Position createPosition(int offset)
                        throws BadLocationException
在内容中创建一个位置,使其在内容发生变化时能跟踪内容的更改。

指定者:
接口 AbstractDocument.Content 中的 createPosition
参数:
offset - 要跟踪的偏移量,该值 >= 0
返回:
位置
抛出:
BadLocationException - 如果指定位置无效

shiftEnd

protected void shiftEnd(int newSize)
扩大间隙、移动任何必要的数据和更新适当的标记。


shiftGap

protected void shiftGap(int newGapStart)
将间隙的起始点移动到新位置,而不更改间隙的大小。这会移动数组中的数据和更新相应的标记。


resetMarksAtZero

protected void resetMarksAtZero()
重新设置具有 0 偏移量的所有标记,使其也有零索引。


shiftGapStartDown

protected void shiftGapStartDown(int newGapStart)
调整间隙,使其结尾向后扩展。此操作不移动任何数据,但它一定会更新受边界更改影响的所有标记。从旧间隙起始点向后到新间隙起始点的所有标记都合并到了间隙的结尾(其位置已被移除)。


shiftGapEndUp

protected void shiftGapEndUp(int newGapEnd)
调整间隙,使其结尾向前扩展。此操作不移动任何数据,但它一定会更新受边界更改影响的所有标记。从旧间隙结尾点向前到新间隙结尾点的所有标记都合并到了间隙的结尾(其位置已被移除)。


getPositionsInRange

protected Vector getPositionsInRange(Vector v,
                                     int offset,
                                     int length)
返回一个包含 UndoPosRef 实例的 Vector,其 Position 的范围从 offsetoffset + length。如果 v 不为 null,则在此处放置匹配的 Position。返回具有结果 Position 的向量。

参数:
v - 要使用的 Vector,其位置是向量为 null 时创建的新位置
offset - 起始偏移量,该值 >= 0
length - 长度,该值 >= 0
返回:
实例的集合

updateUndoPositions

protected void updateUndoPositions(Vector positions,
                                   int offset,
                                   int length)
重新设置处在 positions 的所有 UndoPosRef 实例的位置。

这里指的是内部用法,通常不适合子类。

参数:
positions - 重新设置 UndoPosRef 实例的位置

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.

参数:
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.

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策