JavaTM 2 Platform
Standard Ed. 6

javax.swing.text
类 StringContent

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

public final class StringContent
extends Object
implements AbstractDocument.Content, Serializable

AbstractDocument.Content 接口的一个实现,这是一个对相对于较小的文档和/或调试很有用的强制实现。它只能管理简单字符数组中的字符内容。而且其效率很低。

通常建议使用间隙缓冲区或拼凑表实现。此缓冲区无法扩展为大尺寸。

警告:此类的已序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储或运行相同 Swing 版本的应用程序之间的 RMI。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder


构造方法摘要
StringContent()
          创建新的 StringContent 对象。
StringContent(int initialLength)
          创建具有指定初始大小的新 StringContent。
 
方法摘要
 Position createPosition(int offset)
          在内容中创建一个位置,让其跟踪随内容的变化而进行的更改。
 void getChars(int where, int len, Segment chars)
          检索内容的某一部分,where + len 必须 <= length()
protected  Vector getPositionsInRange(Vector v, int offset, int length)
          返回一个包含 UndoPosRef 实例的 Vector,其 Position 的范围从 offsetoffset + length
 String getString(int where, int len)
          检索内容的某一部分,where + len 必须 <= length()。
 UndoableEdit insertString(int where, String str)
          将字符串插入到内容中。
 int length()
          返回内容的长度。
 UndoableEdit remove(int where, int nitems)
          移除部分内容,其中 where + nitems 必须 < length()。
protected  void updateUndoPositions(Vector positions)
          在 positions 处重新设置所有 UndoPosRef 实例的位置。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

StringContent

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


StringContent

public StringContent(int initialLength)
创建具有指定初始大小的新 StringContent。如果长度小于 1,大小将为 1。

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

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
移除部分内容,其中 where + nitems 必须 < length()。

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

getString

public String getString(int where,
                        int len)
                 throws BadLocationException
检索内容的某一部分,where + len 必须 <= length()。

指定者:
接口 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
检索内容的某一部分,where + len 必须 <= length()

指定者:
接口 AbstractDocument.Content 中的 getChars
参数:
where - 起始位置,该值 >= 0
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 - 如果指定位置无效

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)
positions 处重新设置所有 UndoPosRef 实例的位置。

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

参数:
positions - 实例的位置

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only