java.lang.Object | ||
↳ | javax.swing.text.AbstractDocument | |
↳ | javax.swing.text.DefaultStyledDocument |
![]() |
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 JavaBeansTM
has been added to the java.beans
package.
Please see XMLEncoder
.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DefaultStyledDocument.AttributeUndoableEdit | An UndoableEdit used to remember AttributeSet changes to an Element. | ||||||||||
DefaultStyledDocument.ElementBuffer | Class to manage changes to the element hierarchy. | ||||||||||
DefaultStyledDocument.ElementSpec | Specification for building elements. | ||||||||||
DefaultStyledDocument.SectionElement | Default root element for a document... |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | BUFFER_SIZE_DEFAULT | The default size of the initial content buffer. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
buffer |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a styled document.
| |||||||||||
Constructs a styled document with the default content
storage implementation and a shared set of styles.
| |||||||||||
Constructs a default styled document.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a document listener for notification of any changes.
| |||||||||||
Adds a new style into the logical style hierarchy.
| |||||||||||
Gets the background color from an attribute set.
| |||||||||||
Gets a character element based on a position.
| |||||||||||
Gets the default root element.
| |||||||||||
Gets the font from an attribute set.
| |||||||||||
Gets the foreground color from an attribute set.
| |||||||||||
Fetches the logical style assigned to the paragraph
represented by the given position.
| |||||||||||
Gets the paragraph element at the offset
pos . | |||||||||||
Fetches a named style previously added.
| |||||||||||
Fetches the list of of style names.
| |||||||||||
Removes a document listener.
| |||||||||||
Removes a named style previously added to the document.
| |||||||||||
Sets attributes for some part of the document.
| |||||||||||
Sets the logical style to use for the paragraph at the
given position.
| |||||||||||
Sets attributes for a paragraph.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Initialize the document to reflect the given element
structure (i.e.
| |||||||||||
Creates the root element to be used to represent the
default document structure.
| |||||||||||
Inserts new elements in bulk.
| |||||||||||
Updates document structure as a result of text insertion.
| |||||||||||
Updates document structure as a result of text removal.
| |||||||||||
Called when any of this document's styles have changed.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
The default size of the initial content buffer.
Constructs a styled document.
c | the container for the content |
---|---|
styles | resources and style definitions which may be shared across documents |
Constructs a styled document with the default content storage implementation and a shared set of styles.
styles | the styles |
---|
Constructs a default styled document. This buffers input content by a size of BUFFER_SIZE_DEFAULT and has a style context that is scoped by the lifetime of the document and is not shared with other documents.
Adds a document listener for notification of any changes.
listener | the listener |
---|
Adds a new style into the logical style hierarchy. Style attributes resolve from bottom up so an attribute specified in a child will override an attribute specified in the parent.
nm | 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. |
---|---|
parent | the parent style. This may be null if unspecified attributes need not be resolved in some other style. |
Gets the background color from an attribute set.
attr | the attribute set |
---|
Gets a character element based on a position.
pos | the position in the document >= 0 |
---|
Gets the font from an attribute set.
attr | the attribute set |
---|
Gets the foreground color from an attribute set.
attr | the attribute set |
---|
Fetches the logical style assigned to the paragraph represented by the given position.
p | the location to translate to a paragraph and determine the logical style assigned >= 0. This is an offset from the start of the document. |
---|
Gets the paragraph element at the offset pos
.
A paragraph consists of at least one child Element, which is usually
a leaf.
pos | the starting offset >= 0 |
---|
Fetches a named style previously added.
nm | the name of the style |
---|
Fetches the list of of style names.
Removes a document listener.
listener | the listener |
---|
Removes a named style previously added to the document.
nm | the name of the style to remove |
---|
Sets attributes for some part of the document. A write lock is held by this operation while changes are being made, and a DocumentEvent is sent to the listeners after the change has been successfully completed.
This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.
offset | the offset in the document >= 0 |
---|---|
length | the length >= 0 |
s | the attributes |
replace | true if the previous attributes should be replaced before setting the new attributes |
Sets the logical style to use for the paragraph at the given position. If attributes aren't explicitly set for character and paragraph attributes they will resolve through the logical style assigned to the paragraph, which in turn may resolve through some hierarchy completely independent of the element hierarchy in the document.
This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.
pos | the offset from the start of the document >= 0 |
---|---|
s | the logical style to assign to the paragraph, null if none |
Sets attributes for a paragraph.
This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.
offset | the offset into the paragraph >= 0 |
---|---|
length | the number of characters affected >= 0 |
s | the attributes |
replace | whether to replace existing attributes, or merge them |
Initialize the document to reflect the given element
structure (i.e. the structure reported by the
getDefaultRootElement
method. If the
document contained any data it will first be removed.
Creates the root element to be used to represent the default document structure.
Inserts new elements in bulk. This is useful to allow parsing with the document in an unlocked state and prepare an element structure modification. This method takes an array of tokens that describe how to update an element structure so the time within a write lock can be greatly reduced in an asynchronous update situation.
This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.
offset | the starting offset >= 0 |
---|---|
data | the element data |
BadLocationException | for an invalid starting offset |
---|
Updates document structure as a result of text insertion. This will happen within a write lock. This implementation simply parses the inserted content for line breaks and builds up a set of instructions for the element buffer.
chng | a description of the document change |
---|---|
attr | the attributes |
Updates document structure as a result of text removal.
chng | a description of the document change |
---|
Called when any of this document's styles have changed. Subclasses may wish to be intelligent about what gets damaged.
style | The Style that has changed. |
---|