|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjavax.swing.text.GapContent
public class GapContent
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 的范围从 offset 到 offset + 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 |
| 构造方法详细信息 |
|---|
public GapContent()
public GapContent(int initialLength)
initialLength - 初始大小| 方法详细信息 |
|---|
protected Object allocateArray(int len)
protected int getArrayLength()
public int length()
AbstractDocument.Content 中的 lengthAbstractDocument.Content.length()
public UndoableEdit insertString(int where,
String str)
throws BadLocationException
AbstractDocument.Content 中的 insertStringwhere - 起始位置,该值 >= 0 且 < length()str - 要插入的非 null 字符串
BadLocationException - 如果指定位置无效AbstractDocument.Content.insertString(int, java.lang.String)
public UndoableEdit remove(int where,
int nitems)
throws BadLocationException
AbstractDocument.Content 中的 removewhere - 起始位置,该值 >= 0 且 where + nitems < length()nitems - 要移除的字符数,该值 >= 0
BadLocationException - 如果指定位置无效AbstractDocument.Content.remove(int, int)
public String getString(int where,
int len)
throws BadLocationException
AbstractDocument.Content 中的 getStringwhere - 起始位置,该值 >= 0len - 要检索的长度,该值 >= 0
BadLocationException - 如果指定位置无效AbstractDocument.Content.getString(int, int)
public void getChars(int where,
int len,
Segment chars)
throws BadLocationException
AbstractDocument.Content 中的 getCharswhere - 起始位置,该值 >= 0,where + len <= length()len - 要检索的字符数,该值 >= 0chars - 要在其中返回字符的 Segment 对象
BadLocationException - 如果指定位置无效AbstractDocument.Content.getChars(int, int, javax.swing.text.Segment)
public Position createPosition(int offset)
throws BadLocationException
AbstractDocument.Content 中的 createPositionoffset - 要跟踪的偏移量,该值 >= 0
BadLocationException - 如果指定位置无效protected void shiftEnd(int newSize)
protected void shiftGap(int newGapStart)
protected void resetMarksAtZero()
protected void shiftGapStartDown(int newGapStart)
protected void shiftGapEndUp(int newGapEnd)
protected Vector getPositionsInRange(Vector v,
int offset,
int length)
offset 到 offset + length。如果 v 不为 null,则在此处放置匹配的 Position。返回具有结果 Position 的向量。
v - 要使用的 Vector,其位置是向量为 null 时创建的新位置offset - 起始偏移量,该值 >= 0length - 长度,该值 >= 0
protected void updateUndoPositions(Vector positions,
int offset,
int length)
positions 的所有 UndoPosRef 实例的位置。
这里指的是内部用法,通常不适合子类。
positions - 重新设置 UndoPosRef 实例的位置protected final Object getArray()
protected final int getGapStart()
protected final int getGapEnd()
protected void replace(int position,
int rmSize,
Object addItems,
int addSize)
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 removeaddItems - the new items to place in storage.
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。