javax.swing.text
public class DefaultStyledDocument extends AbstractDocument implements StyledDocument
Nested Class Summary | |
---|---|
static class | DefaultStyledDocument.AttributeUndoableEdit
An {@link UndoableEdit} that can undo attribute changes to an element.
|
class | DefaultStyledDocument.ElementBuffer
Performs all structural changes to the Element
hierarchy. |
static class | DefaultStyledDocument.ElementSpec
Carries specification information for new {@link Element}s that should be
created in {@link ElementBuffer}. |
protected class | DefaultStyledDocument.SectionElement
An element type for sections. |
Field Summary | |
---|---|
protected DefaultStyledDocument.ElementBuffer | buffer
The EditorBuffer that is used to manage to
Element hierarchy. |
static int | BUFFER_SIZE_DEFAULT
The default size to use for new content buffers. |
Constructor Summary | |
---|---|
DefaultStyledDocument()
Creates a new DefaultStyledDocument . | |
DefaultStyledDocument(StyleContext context)
Creates a new DefaultStyledDocument that uses the specified
{@link StyleContext}.
| |
DefaultStyledDocument(AbstractDocument.Content content, StyleContext context)
Creates a new DefaultStyledDocument that uses the specified
{@link StyleContext} and {@link Content} buffer.
|
Method Summary | |
---|---|
Style | addStyle(String nm, Style parent)
Adds a style into the style hierarchy. |
protected void | create(DefaultStyledDocument.ElementSpec[] data)
Initializes the DefaultStyledDocument with the specified
data.
|
protected AbstractDocument.AbstractElement | createDefaultRoot()
Create the default root element for this kind of Document .
|
Color | getBackground(AttributeSet attributes)
Extracts a background color from a set of attributes.
|
Element | getCharacterElement(int position)
Returns the Element that corresponds to the character at the
specified position.
|
Element | getDefaultRootElement()
Returns the default root element.
|
Font | getFont(AttributeSet attributes)
Extracts a font from a set of attributes.
|
Color | getForeground(AttributeSet attributes)
Extracts a foreground color from a set of attributes.
|
Style | getLogicalStyle(int position)
Returns the logical Style for the specified position.
|
Element | getParagraphElement(int position)
Returns the paragraph element for the specified position. |
Style | getStyle(String nm)
Looks up and returns a named Style .
|
Enumeration<?> | getStyleNames()
Returns an enumeration of all style names.
|
protected void | insert(int offset, DefaultStyledDocument.ElementSpec[] data)
Inserts a bulk of structured content at once.
|
protected void | insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
Called in response to content insert actions. |
void | removeStyle(String nm)
Removes a named Style from the style hierarchy.
|
protected void | removeUpdate(DefaultDocumentEvent ev)
Updates the document structure in response to text removal. |
void | setCharacterAttributes(int offset, int length, AttributeSet attributes, boolean replace)
Sets text attributes for the fragment specified by offset
and length .
|
void | setLogicalStyle(int position, Style style)
Sets the logical style for the paragraph at the specified position.
|
void | setParagraphAttributes(int offset, int length, AttributeSet attributes, boolean replace)
Sets text attributes for the paragraph at the specified fragment.
|
protected void | styleChanged(Style style)
Called when any of this document's styles changes.
|
EditorBuffer
that is used to manage to
Element
hierarchy.DefaultStyledDocument
.DefaultStyledDocument
that uses the specified
{@link StyleContext}.
Parameters: context
the StyleContext
to use
DefaultStyledDocument
that uses the specified
{@link StyleContext} and {@link Content} buffer.
Parameters: content
the Content
buffer to use context
the StyleContext
to use
parent
style, if one is specified. While it
is legal to add nameless styles (nm == null
Parameters: nm the name of the style or null
if the style should
be unnamed parent the parent in which unspecified style attributes are
resolved, or null
if that is not necessary
Returns: the newly created Style
DefaultStyledDocument
with the specified
data.
Parameters: data the specification of the content with which the document is initialized
Document
.
Returns: the default root element for this kind of Document
Parameters: attributes the attributes from which to get a background color
Returns: the background color that correspond to the attributes
Element
that corresponds to the character at the
specified position.
Parameters: position
the position of which we query the corresponding
Element
Returns: the Element
that corresponds to the character at the
specified position
Returns: the default root element
Parameters: attributes the attributes from which to get a font
Returns: the font that correspond to the attributes
Parameters: attributes the attributes from which to get a foreground color
Returns: the foreground color that correspond to the attributes
Style
for the specified position.
Parameters: position the position from which to query to logical style
Returns: the logical Style
for the specified position
position >= endIndex
or the first paragraph if
position < startIndex
.
Parameters: position the position for which to query the paragraph element
Returns: the paragraph element for the specified position
Style
.
Parameters: nm
the name of the Style
Returns: the found Style
of null
if no such
Style
exists
Returns: an enumeration of all style names
Parameters: offset the offset at which the content should be inserted data the actual content spec to be inserted
Parameters: ev
the DocumentEvent
describing the change attr
the attributes for the change
Style
from the style hierarchy.
Parameters: nm
the name of the Style
to be removed
Parameters: ev the document event that records the changes to the document
offset
and length
.
Parameters: offset
the start offset of the fragment length
the length of the fragment attributes
the text attributes to set replace
if true
, the attributes of the current selection
are overridden, otherwise they are merged
Parameters: position the position at which the logical style is added style the style to set for the current paragraph
Parameters: offset
the beginning of the fragment length
the length of the fragment attributes
the text attributes to set replace
if true
, the attributes of the current selection
are overridden, otherwise they are merged
Parameters: style the style that changed