所有类


javax.swing.text
类 DefaultStyledDocument

java.lang.Object
  继承者 javax.swing.text.AbstractDocument
      继承者 javax.swing.text.DefaultStyledDocument
所有已实现的接口:
Serializable, Document, StyledDocument
直接已知子类:
HTMLDocument

public class DefaultStyledDocument
   
   
   
   
extends AbstractDocument
implements StyledDocument

能够以类似富文本格式 (Rich Text Format) 的方式对其字符和段落样式进行标记的文档。此文档的元素结构表示样式在运行时的相互引用。这些样式运行被映射到段落元素结构(也有可能以其他结构形式驻留)。样式运行在段落边界处中断,原因是段落边界被指派了逻辑样式。

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

另请参见:
Document, AbstractDocument

嵌套类摘要
static classDefaultStyledDocument.AttributeUndoableEdit
          用于记住 AttributeSet 对 Element 更改的一个 UndoableEdit。
 classDefaultStyledDocument.ElementBuffer
          管理对元素层次结构更改的类。
static classDefaultStyledDocument.ElementSpec
          构建元素的规范。
protected  classDefaultStyledDocument.SectionElement
          文档的默认根元素... 与所包含的段落/行对应。
 
从类 javax.swing.text.AbstractDocument 继承的嵌套类/接口
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
 
字段摘要
protected  DefaultStyledDocument.ElementBufferbuffer
           
static intBUFFER_SIZE_DEFAULT
          初始内容缓冲区的默认大小。
 
从类 javax.swing.text.AbstractDocument 继承的字段
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
 
从接口 javax.swing.text.Document 继承的字段
StreamDescriptionProperty, TitleProperty
 
构造方法摘要
DefaultStyledDocument()
          构造默认的样式化文档。
DefaultStyledDocument(AbstractDocument.Content c, StyleContext styles)
          构造样式化文档。
DefaultStyledDocument(StyleContext styles)
          构造具有默认的内容存储实现和一组共享样式的样式化文档。
 
方法摘要
 voidaddDocumentListener(DocumentListener listener)
          添加负责通知任何更改的文档侦听器。
 StyleaddStyle(String nm, Style parent)
          向逻辑样式层次结构中添加新样式。
protected  voidcreate(DefaultStyledDocument.ElementSpec[] data)
          初始化文档,以反映给定元素结构(即由 getDefaultRootElement 方法报告的结构)。
protected  AbstractDocument.AbstractElementcreateDefaultRoot()
          创建用于代表默认文档结构的根元素。
 ColorgetBackground(AttributeSet attr)
          从属性集获得背景颜色。
 ElementgetCharacterElement(int pos)
          获得基于某个位置的字符元素。
 ElementgetDefaultRootElement()
          获得默认的根元素。
 FontgetFont(AttributeSet attr)
          从属性集获得字体。
 ColorgetForeground(AttributeSet attr)
          从属性集获得前景色。
 StylegetLogicalStyle(int p)
          获取表示给定位置处分配给段落的逻辑样式。
 ElementgetParagraphElement(int pos)
          获得位于偏移量 pos 的段落元素。
 StylegetStyle(String nm)
          获取以前添加的已命名的样式。
 Enumeration<?>getStyleNames()
          获取样式名称列表。
protected  voidinsert(int offset, DefaultStyledDocument.ElementSpec[] data)
          批量插入新元素。
protected  voidinsertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
          在文本插入后更新文档结构。
 voidremoveDocumentListener(DocumentListener listener)
          移除文档侦听器。
 voidremoveStyle(String nm)
          移除以前添加到文档中的已命名样式。
protected  voidremoveUpdate(AbstractDocument.DefaultDocumentEvent chng)
          在文本移除后更新文档结构。
 voidsetCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)
          为文档某些部分设置属性。
 voidsetLogicalStyle(int pos, Style s)
          设置给定位置处用于段落的逻辑样式。
 voidsetParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)
          设置段落属性。
protected  voidstyleChanged(Style style)
          此文档样式有任何改变时调用。
 
从类 javax.swing.text.AbstractDocument 继承的方法
addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, insertString, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
从接口 javax.swing.text.Document 继承的方法
addUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, insertString, putProperty, remove, removeUndoableEditListener, render
 

字段详细信息

BUFFER_SIZE_DEFAULT

public static final int BUFFER_SIZE_DEFAULT
初始内容缓冲区的默认大小。

另请参见:
常量字段值

buffer

protected DefaultStyledDocument.ElementBuffer buffer
构造方法详细信息

DefaultStyledDocument

public DefaultStyledDocument(AbstractDocument.Content c,
                             StyleContext styles)
构造样式化文档。

参数:
c - 内容容器
styles - 可跨文档共享的资源和样式定义

DefaultStyledDocument

public DefaultStyledDocument(StyleContext styles)
构造具有默认的内容存储实现和一组共享样式的样式化文档。

参数:
styles - 样式

DefaultStyledDocument

public DefaultStyledDocument()
构造默认的样式化文档。此缓冲区输入内容大小为 BUFFER_SIZE_DEFAULT 并有一个由文档的生命周期确定其范围且不与其他文档共享的样式上下文。

方法详细信息

getDefaultRootElement

public Element getDefaultRootElement()
获得默认的根元素。

指定者:
接口 Document 中的 getDefaultRootElement
指定者:
AbstractDocument 中的 getDefaultRootElement
返回:
另请参见:
Document.getDefaultRootElement()

create

protected void create(DefaultStyledDocument.ElementSpec[] data)
初始化文档,以反映给定元素结构(即由 getDefaultRootElement 方法报告的结构)。如果该文档包含了任何数据,将首先移除这些数据。


insert

protected void insert(int offset,
                      DefaultStyledDocument.ElementSpec[] data)
               throws BadLocationException
批量插入新元素。这有助于在取消锁定状态下对文档进行解析并为元素结构修改做准备。此方法使用一个描述如何更新元素结构的标记数组,这样在异步更新的情况下写锁定的时间得到显著降低。

虽然大多数 Swing 方法不是线程安全的,但此方法是线程安全的。有关更多信息,请参阅 Threads and Swing

参数:
offset - 起始偏移量,该偏移量 >= 0
data - 元素数据
抛出:
BadLocationException - 无效的起始偏移量

addStyle

public Style addStyle(String nm,
                      Style parent)
向逻辑样式层次结构中添加新样式。样式属性自下向上进行解析,所以在子级中指定的属性将重写父级中指定的属性。

指定者:
接口 StyledDocument 中的 addStyle
参数:
nm - 样式的名称(在命名样式集合中必须是惟一的)。如果样式未命名,则此名称可能为 null,但是调用方要负责管理返回的引用,因为未命名的样式不能通过其名称获取。未命名的样式可以用于诸如字符属性重写这样的情况(例如在样式运行中)。
parent - 父样式。如果未指定的属性不需要以其他样式解析,则此值可以为 null。
返回:
样式