- java.lang.Object
-
- javax.swing.text.GapContent
-
- All Implemented Interfaces:
-
SerializableAbstractDocument.Content
public class GapContent extends Object implements AbstractDocument.Content, Serializable
AbstractDocument.Content接口的实现使用与emacs使用的类似的间隙缓冲区来实现。 新新新200新新新200新新新200新新200 200 200 200新新新200新200新新200新200新新200新200新新200新200新新200新新新200新新200新新200新新200新新200新新200新新200新新200新新200新新200新新新200新新新 差距被移动到更改的位置,以利用大多数更改位于相同位置的常见行为。 在间隙边界发生的变化通常是便宜的,并且移动间隙通常比直接移动阵列内容以适应变化更便宜。跟踪变化的位置通常也很便宜。 位置实现(标记)存储数组索引,并且可以容易地从当前间隙位置计算顺序位置。 当间隙移动时,更改仅需要更新旧间隙和新间隙边界之间的标记,因此通常更新标记相当便宜。 标记被存储排序,以便它们可以通过二进制搜索快速定位。 新新200新新200新新200新新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新200新新200新200新200新200新新200新新200新新200新新200新200新新200新200新新200新新200新新200新
- 另请参见:
- Serialized Form
-
-
构造方法摘要
构造方法 Constructor 描述 GapContent()创建一个新的GapContent对象。GapContent(int initialLength)创建一个新的GapContent对象,指定初始大小。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 protected ObjectallocateArray(int len)分配一个数组以存储适当类型的项目(由子类确定)。PositioncreatePosition(int offset)在内容中创建一个位置,该内容将随内容突变而跟踪更改。protected ObjectgetArray()访问数组。protected intgetArrayLength()获取分配的数组的长度。voidgetChars(int where, int len, Segment chars)检索一部分内容。protected intgetGapEnd()获得最后的差距。protected intgetGapStart()获得开始的差距。protected VectorgetPositionsInRange(Vector v, int offset, int length)返回一个Vector包含UndoPosRef的实例,其位置范围为offset至offset+length。StringgetString(int where, int len)检索一部分内容。UndoableEditinsertString(int where, String str)在内容中插入一个字符串。intlength()返回内容的长度。UndoableEditremove(int where, int nitems)删除部分内容。protected voidreplace(int position, int rmSize, Object addItems, int addSize)用给定的新项替换存储中给定的逻辑位置。protected voidresetMarksAtZero()将偏移量为0的所有标记重置为索引为零。protected voidshiftEnd(int newSize)使差距更大,移动任何必要的数据并更新适当的标记protected voidshiftGap(int newGapStart)将差距的开始移动到新位置,而不改变间隙的大小。protected voidshiftGapEndUp(int newGapEnd)将间隙向上调整。protected voidshiftGapStartDown(int newGapStart)将间隙端向下调整。protected voidupdateUndoPositions(Vector positions, int offset, int length)重置positions所有UndoPosRef实例的positions。
-
-
-
方法详细信息
-
allocateArray
protected Object allocateArray(int len)
分配一个数组以存储适当类型的项目(由子类确定)。
-
getArrayLength
protected int getArrayLength()
获取分配的数组的长度。
-
length
public int length()
返回内容的长度。- Specified by:
-
length在接口AbstractDocument.Content - 结果
- 长度> = 1
- 另请参见:
-
AbstractDocument.Content.length()
-
insertString
public UndoableEdit insertString(int where, String str) throws BadLocationException
在内容中插入一个字符串。- Specified by:
-
insertString在接口AbstractDocument.Content - 参数
-
where- 起始位置> = 0,<length() -
str- 要插入的非空字符串 - 结果
- 用于撤消的UndoableEdit对象
- 异常
-
BadLocationException- 如果指定的位置无效 - 另请参见:
-
AbstractDocument.Content.insertString(int, java.lang.String)
-
remove
public UndoableEdit remove(int where, int nitems) throws BadLocationException
删除部分内容。- Specified by:
-
remove在接口AbstractDocument.Content - 参数
-
where- 起始位置> = 0,其中+ nitems <length() -
nitems- 要删除的字符数> = 0 - 结果
- 用于撤消的UndoableEdit对象
- 异常
-
BadLocationException- 如果指定的位置无效 - 另请参见:
-
AbstractDocument.Content.remove(int, int)
-
getString
public String getString(int where, int len) throws BadLocationException
检索一部分内容。- Specified by:
-
getString在接口AbstractDocument.Content - 参数
-
where- 起始位置> = 0 -
len- 要检索的长度> = 0 - 结果
- 表示内容的字符串
- 异常
-
BadLocationException- 如果指定的位置无效 - 另请参见:
-
AbstractDocument.Content.getString(int, int)
-
getChars
public void getChars(int where, int len, Segment chars) throws BadLocationException检索一部分内容。 如果期望的内容跨越差距,我们将复制内容。 如果所需的内容没有跨越间隙,则返回实际存储以避免复制,因为它是连续的。- Specified by:
-
getChars在接口AbstractDocument.Content - 参数
-
where- 起始位置> = 0,其中+ len <= length() -
len- 要检索的字符数> = 0 -
chars- 要返回字符的Segment对象 - 异常
-
BadLocationException- 指定的位置是否无效 - 另请参见:
-
AbstractDocument.Content.getChars(int, int, javax.swing.text.Segment)
-
createPosition
public Position createPosition(int offset) throws BadLocationException
在内容中创建一个位置,该内容将随内容突变而跟踪更改。- Specified by:
-
createPosition在接口AbstractDocument.Content - 参数
-
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)
返回一个Vector包含UndoPosRef的实例,其范围为offset到offset+length。 如果v不为空,则匹配的位置放在那里。 返回带有结果位置的向量。- 参数
-
v- 要使用的矢量,在null上创建一个新的 -
offset- 起始偏移量> = 0 -
length- 长度> = 0 - 结果
- 一组实例
-
updateUndoPositions
protected void updateUndoPositions(Vector positions, int offset, int length)
重置positions所有UndoPosRef实例的positions。这是为了内部使用,通常不是子类的兴趣。
- 参数
-
positions- 要重置的UndoPosRef实例 -
offset- 其中插入了字符串 -
length- 插入字符串的长度
-
getArray
protected final Object getArray()
访问数组。 数组的实际类型只能由子类知道。
-
getGapStart
protected final int getGapStart()
获得开始的差距。
-
getGapEnd
protected final int getGapEnd()
获得最后的差距。
-
replace
protected void replace(int position, int rmSize, Object addItems, int addSize)用给定的新项替换存储中给定的逻辑位置。 如果间隙目前不在更改位置,这将会将差距移动到正在更改的区域。- 参数
-
position- 进行更换的位置。 这不是底层存储阵列中的位置,而是连续空间中的位置被建模。 -
rmSize- 要删除的项目数 -
addItems- 要存放的新物品。
-
-