APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.text

public Class DefaultStyledDocument

extends AbstractDocument
implements StyledDocument
Class Inheritance
All Implemented Interfaces
javax.swing.text.StyledDocument, javax.swing.text.Document
Known Direct Subclasses
javax.swing.text.html.HTMLDocument
Annotations
@SuppressWarnings:serial
Imports
java.awt.Color, .Font, java.awt.font.TextAttribute, java.io.Serial, .IOException, .ObjectInputStream, .Serializable, java.lang.ref.ReferenceQueue, .WeakReference, java.util.Enumeration, .HashMap, .List, .Map, .Stack, .Vector, .ArrayList, .Arrays, javax.swing.event.*, javax.swing.undo.AbstractUndoableEdit, .CannotRedoException, .CannotUndoException, .UndoableEdit, javax.swing.SwingUtilities

A document that can be marked up with character and paragraph styles in a manner similar to the Rich Text Format. The element structure for this document represents style crossings for style runs. These style runs are mapped into a paragraph element structure (which may reside in some other structure). The style runs break at paragraph boundaries since logical styles are assigned to paragraph boundaries.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
Timothy Prinzing
See Also
Document, AbstractDocument

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
DefaultStyledDocument.AbstractChangeHandler

Base class for style change handlers with support for stale objects detection.

public static class
DefaultStyledDocument.AttributeUndoableEdit

An UndoableEdit used to remember AttributeSet changes to an Element.

pack-priv class
DefaultStyledDocument.ChangeUpdateRunnable

When run this creates a change event for the complete document and fires it.

public class
DefaultStyledDocument.ElementBuffer

Class to manage changes to the element hierarchy.

public static class
DefaultStyledDocument.ElementSpec

Specification for building elements.

protected class
DefaultStyledDocument.SectionElement

Default root element for a document...

pack-priv static class
pack-priv static class
DefaultStyledDocument.StyleChangeUndoableEdit

UndoableEdit for changing the resolve parent of an Element.

pack-priv static class

Field Summary

Modifier and TypeField and Description
protected DefaultStyledDocument.ElementBuffer
buffer

The element buffer.

public static final int
BUFFER_SIZE_DEFAULT

The default size of the initial content buffer.

private transient Vector<Style>
listeningStyles

Styles listening to.

private transient ChangeListener
styleChangeListener

Listens to Styles.

private transient ChangeListener
styleContextChangeListener

Listens to Styles.

private transient DefaultStyledDocument.ChangeUpdateRunnable
updateRunnable

Run to create a change event for the document

Inherited from javax.swing.text.AbstractDocument:
AsyncLoadPriorityBAD_LOCATIONBidiElementNameContentElementNameElementNameAttributeI18NPropertylistenerListMultiBytePropertyParagraphElementNameSectionElementName

Constructor Summary

AccessConstructor and Description
public
DefaultStyledDocument(AbstractDocument.Content
the container for the content
c
,
StyleContext
resources and style definitions which may be shared across documents
styles
)

Constructs a styled document.

public
DefaultStyledDocument(StyleContext
the styles
styles
)

Constructs a styled document with the default content storage implementation and a shared set of styles.

public
DefaultStyledDocument()

Constructs a default styled document.

Method Summary

Modifier and TypeMethod and Description
public void
addDocumentListener(DocumentListener
the listener
listener
)

Overrides javax.swing.text.AbstractDocument.addDocumentListener.

Implements javax.swing.text.Document.addDocumentListener.

Adds a document listener for notification of any changes.

public Style

Returns:

the style
addStyle
(String
the name of the style (must be unique within the collection of named styles). The name may be null if the style is unnamed, but the caller is responsible for managing the reference returned as an unnamed style can't be fetched by name. An unnamed style may be useful for things like character attribute overrides such as found in a style run.
nm
,
Style
the parent style. This may be null if unspecified attributes need not be resolved in some other style.
parent
)

Implements javax.swing.text.StyledDocument.addStyle.

Adds a new style into the logical style hierarchy.

protected void
create(DefaultStyledDocument.ElementSpec[]
the element data
data
)

Initialize the document to reflect the given element structure (i.e. the structure reported by the getDefaultRootElement method.

protected AbstractDocument.AbstractElement

Returns:

the element base
createDefaultRoot
()

Creates the root element to be used to represent the default document structure.

pack-priv short
createSpecsForInsertAfterNewline(Element paragraph, Element pParagraph, AttributeSet pattr, Vector<DefaultStyledDocument.ElementSpec> parseBuffer, int offset, int endOffset)

This is called by insertUpdate when inserting after a new line.

pack-priv ChangeListener
createStyleChangeListener()

Returns a new instance of StyleChangeHandler.

pack-priv ChangeListener
createStyleContextChangeListener()

Returns a new instance of StyleContextChangeHandler.

public Color

Returns:

the color
getBackground
(AttributeSet
the attribute set
attr
)

Implements javax.swing.text.StyledDocument.getBackground.

Gets the background color from an attribute set.

public Element

Returns:

the element
getCharacterElement
(int
the position in the document >= 0
pos
)

Implements javax.swing.text.StyledDocument.getCharacterElement.

Gets a character element based on a position.

public Element

Returns:

the root
getDefaultRootElement
()

Implements abstract javax.swing.text.AbstractDocument.getDefaultRootElement.

Implements javax.swing.text.Document.getDefaultRootElement.

Gets the default root element.

public Font

Returns:

the font
getFont
(AttributeSet
the attribute set
attr
)

Implements javax.swing.text.StyledDocument.getFont.

Gets the font from an attribute set.

public Color

Returns:

the color
getForeground
(AttributeSet
the attribute set
attr
)

Implements javax.swing.text.StyledDocument.getForeground.

Gets the foreground color from an attribute set.

public Style

Returns:

the style, null if none
getLogicalStyle
(int
the location to translate to a paragraph and determine the logical style assigned >= 0. This is an offset from the start of the document.
p
)

Implements javax.swing.text.StyledDocument.getLogicalStyle.

Fetches the logical style assigned to the paragraph represented by the given position.

public Element

Returns:

the element
getParagraphElement
(int
the starting offset >= 0
pos
)

Implements abstract javax.swing.text.AbstractDocument.getParagraphElement.

Implements javax.swing.text.StyledDocument.getParagraphElement.

Gets the paragraph element at the offset pos.

public Style

Returns:

the style
getStyle
(String
the name of the style
nm
)

Implements javax.swing.text.StyledDocument.getStyle.

Fetches a named style previously added.

public Enumeration<?>

Returns:

all the style names
getStyleNames
()

Fetches the list of style names.

protected void
insert(int
the starting offset >= 0
offset
,
DefaultStyledDocument.ElementSpec[]
the element data
data
)

Inserts new elements in bulk.

protected void
insertUpdate(AbstractDocument.DefaultDocumentEvent
a description of the document change
chng
,
AttributeSet
the attributes
attr
)

Overrides javax.swing.text.AbstractDocument.insertUpdate.

Updates document structure as a result of text insertion.

private void
public void
public void
removeElement(Element
the element to remove
elem
)

Removes an element from this document.

private void
public void
removeStyle(String
the name of the style to remove
nm
)

Implements javax.swing.text.StyledDocument.removeStyle.

Removes a named style previously added to the document.

protected void
removeUpdate(AbstractDocument.DefaultDocumentEvent
a description of the document change
chng
)

Overrides javax.swing.text.AbstractDocument.removeUpdate.

Updates document structure as a result of text removal.

public void
setCharacterAttributes(int
the offset in the document >= 0
offset
,
int
the length > 0
length
,
AttributeSet
the attributes
s
,
boolean
true if the previous attributes should be replaced before setting the new attributes
replace
)

Implements javax.swing.text.StyledDocument.setCharacterAttributes.

Sets attributes for some part of the document.

public void
setLogicalStyle(int
the offset from the start of the document >= 0
pos
,
Style
the logical style to assign to the paragraph, null if none
s
)

Implements javax.swing.text.StyledDocument.setLogicalStyle.

Sets the logical style to use for the paragraph at the given position.

public void
setParagraphAttributes(int
the offset into the paragraph >= 0
offset
,
int
the number of characters affected >= 0
length
,
AttributeSet
the attributes
s
,
boolean
whether to replace existing attributes, or merge them
replace
)

Implements javax.swing.text.StyledDocument.setParagraphAttributes.

Sets attributes for a paragraph.

protected void
styleChanged(Style
The Style that has changed.
style
)

Called when any of this document's styles have changed.

pack-priv void
updateStylesListeningTo()

Adds a ChangeListener to new styles, and removes ChangeListener from old styles.

Inherited from javax.swing.text.AbstractDocument:
addUndoableEditListenercreateBranchElementcreateLeafElementcreatePositiondumpfireChangedUpdatefireInsertUpdatefireRemoveUpdatefireUndoableEditUpdategetAsynchronousLoadPrioritygetAttributeContextgetBidiRootElementgetContentgetCurrentWritergetDocumentFiltergetDocumentListenersgetDocumentPropertiesgetEndPositiongetLengthgetListenersgetPropertygetRootElementsgetStartPositiongetTextgetTextgetUndoableEditListenershandleRemoveinsertStringisLeftToRightpostRemoveUpdateputPropertyreadLockreadUnlockremoveremoveUndoableEditListenerrenderreplacesetAsynchronousLoadPrioritysetDocumentFiltersetDocumentPropertiesupdateBidiwriteLockwriteUnlock