模块 java.desktop

类 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(int initialLength)
    创建一个具有指定初始大小的新 GapContent 对象。
  • 方法总结

    修饰符和类型
    方法
    描述
    protected Object
    allocateArray(int len)
    分配一个数组来存储适当类型的项(由子类确定)。
    createPosition(int offset)
    在内容中创建一个位置,该位置将在内容发生变化时跟踪变化。
    protected final Object
    访问数组。
    protected int
    获取分配数组的长度。
    void
    getChars(int where, int len, Segment chars)
    检索部分内容。
    protected final int
    进入缝隙的尽头。
    protected final int
    进入差距的起点。
    protected Vector
    getPositionsInRange(Vector v, int offset, int length)
    返回包含 offsetoffset + length 范围内位置的 UndoPosRef 实例的向量。
    getString(int where, int len)
    检索部分内容。
    insertString(int where, String str)
    在内容中插入一个字符串。
    int
    返回内容的长度。
    remove(int where, int nitems)
    删除部分内容。
    protected void
    replace(int position, int rmSize, Object addItems, int addSize)
    用给定的新项目替换存储中给定的逻辑位置。
    protected void
    将所有偏移量为 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)
      分配一个数组来存储适当类型的项(由子类确定)。
      参数:
      len - 数组的长度
      返回:
      某种类型的java数组
    • getArrayLength

      protected int getArrayLength()
      获取分配数组的长度。
      返回:
      数组的长度
    • length

      public int length()
      返回内容的长度。
      指定者:
      length 在接口 AbstractDocument.Content
      返回:
      长度 >= 1
      参见:
    • insertString

      public UndoableEdit  insertString(int where, String  str) throws BadLocationException
      在内容中插入一个字符串。
      指定者:
      insertString 在接口 AbstractDocument.Content
      参数:
      where - 起始位置 >= 0, < length()
      str - 要插入的非空字符串
      返回:
      用于撤消的 UndoableEdit 对象
      抛出:
      BadLocationException - 如果指定位置无效
      参见:
    • remove

      public UndoableEdit  remove(int where, int nitems) throws BadLocationException
      删除部分内容。
      指定者:
      remove 在接口 AbstractDocument.Content
      参数:
      where - 起始位置 >= 0,其中 + nitems < length()
      nitems - 要删除的字符数 >= 0
      返回:
      用于撤消的 UndoableEdit 对象
      抛出:
      BadLocationException - 如果指定位置无效
      参见:
    • getString

      public String  getString(int where, int len) throws BadLocationException
      检索部分内容。
      指定者:
      getString 在接口 AbstractDocument.Content
      参数:
      where - 起始位置 >= 0
      len - 要检索的长度 >= 0
      返回:
      表示内容的字符串
      抛出:
      BadLocationException - 如果指定位置无效
      参见:
    • getChars

      public void getChars(int where, int len, Segment  chars) throws BadLocationException
      检索部分内容。如果所需内容跨越间隙,我们复制该内容。如果所需内容没有跨越间隙,则返回实际存储以避免复制,因为它是连续的。
      指定者:
      getChars 在接口 AbstractDocument.Content
      参数:
      where - 起始位置 >= 0,其中 + len <= length()
      len - 要检索的字符数 >= 0
      chars - 返回字符的 Segment 对象
      抛出:
      BadLocationException - 如果指定位置无效
      参见:
    • createPosition

      public Position  createPosition(int offset) throws BadLocationException
      在内容中创建一个位置,该位置将在内容发生变化时跟踪变化。
      指定者:
      createPosition 在接口 AbstractDocument.Content
      参数:
      offset - 跟踪偏移 >= 0
      返回:
      位置
      抛出:
      BadLocationException - 如果指定位置无效
    • shiftEnd

      protected void shiftEnd(int newSize)
      扩大差距,移动任何必要的数据并更新适当的标记
      参数:
      newSize - 新容量
    • shiftGap

      protected void shiftGap(int newGapStart)
      将间隙的起点移动到新位置,而不更改间隙的大小。这会移动数组中的数据并相应地更新标记。
      参数:
      newGapStart - 差距的新起点
    • resetMarksAtZero

      protected void resetMarksAtZero()
      将所有偏移量为 0 的标记重置为索引也为零。
    • shiftGapStartDown

      protected void shiftGapStartDown(int newGapStart)
      向下调整间隙端。这不会移动任何数据,但会更新受边界更改影响的任何标记。从旧间隙开始到新间隙开始的所有标记都被挤压到间隙的末端(它们的位置已被删除)。
      参数:
      newGapStart - 差距的新起点
    • shiftGapEndUp

      protected void shiftGapEndUp(int newGapEnd)
      向上调整间隙端。这不会移动任何数据,但会更新受边界更改影响的任何标记。从旧间隙末端到新间隙末端的所有标记都被挤压到间隙末端(它们的位置已被移除)。
      参数:
      newGapEnd - 差距的新尽头
    • getPositionsInRange

      protected Vector  getPositionsInRange(Vector  v, int offset, int length)
      返回包含 offsetoffset + length 范围内位置的 UndoPosRef 实例的向量。如果 v 不为空,则匹配的位置将放置在那里。返回具有结果位置的向量。
      参数:
      v - 要使用的 Vector,在 null 上创建一个新的 Vector
      offset - 起始偏移量 >= 0
      length - 长度 >= 0
      返回:
      实例集
    • updateUndoPositions

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

      这意味着供内部使用,子类通常不感兴趣。

      参数:
      positions - 要重置的 UndoPosRef 实例
      offset - 插入字符串的位置
      length - 插入字符串的长度
    • getArray

      protected final Object  getArray()
      访问数组。数组的实际类型只有子类知道。
      返回:
      某种类型的java数组
    • 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 - 要存放的新物品。
      addSize - 要添加的项目数