Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.DefaultStyledDocument
StyledDocument
. The document is
modeled as an Element
tree, which has a DefaultStyledDocument.SectionElement
as
single root, which has one or more AbstractDocument.BranchElement
s
as paragraph nodes and each paragraph node having one or more
AbstractDocument.LeafElement
s as content nodes.
Nested Class Summary | |
static class |
|
class |
|
static class |
|
protected class |
|
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument | |
AbstractDocument.AbstractElement , AbstractDocument.AttributeContext , AbstractDocument.BranchElement , AbstractDocument.Content , AbstractDocument.DefaultDocumentEvent , AbstractDocument.ElementEdit , AbstractDocument.LeafElement |
Field Summary | |
static int |
|
protected DefaultStyledDocument.ElementBuffer |
|
Fields inherited from class javax.swing.text.AbstractDocument | |
BAD_LOCATION , BidiElementName , ContentElementName , ElementNameAttribute , ParagraphElementName , SectionElementName , listenerList |
Fields inherited from interface javax.swing.text.Document | |
StreamDescriptionProperty , TitleProperty |
Constructor Summary | |
| |
| |
|
Method Summary | |
Style | |
protected void |
|
protected AbstractDocument.AbstractElement |
|
Color |
|
Element |
|
Element |
|
Font |
|
Color |
|
Style |
|
Element |
|
Style | |
Enumeration |
|
protected void |
|
protected void |
|
void |
|
protected void |
|
void |
|
void |
|
void |
|
protected void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final int BUFFER_SIZE_DEFAULT
The default size to use for new content buffers.
- Field Value:
- 4096
protected DefaultStyledDocument.ElementBuffer buffer
TheEditorBuffer
that is used to manage toElement
hierarchy.
public DefaultStyledDocument(AbstractDocument.Content content, StyleContext context)
Creates a newDefaultStyledDocument
that uses the specifiedStyleContext
andAbstractDocument.Content
buffer.
- Parameters:
content
- theContent
buffer to usecontext
- theStyleContext
to use
public DefaultStyledDocument(StyleContext context)
Creates a newDefaultStyledDocument
that uses the specifiedStyleContext
.
- Parameters:
context
- theStyleContext
to use
public Style addStyle(String nm, Style parent)
Adds a style into the style hierarchy. Unspecified style attributes can be resolved in theparent
style, if one is specified. While it is legal to add nameless styles (nm == null
- Specified by:
- addStyle in interface StyledDocument
- Parameters:
nm
- the name of the style ornull
if the style should be unnamedparent
- the parent in which unspecified style attributes are resolved, ornull
if that is not necessary
- Returns:
- the newly created
Style
protected void create(DefaultStyledDocument.ElementSpec[] data)
Initializes theDefaultStyledDocument
with the specified data.
- Parameters:
data
- the specification of the content with which the document is initialized
protected AbstractDocument.AbstractElement createDefaultRoot()
Create the default root element for this kind ofDocument
.
- Returns:
- the default root element for this kind of
Document
public Color getBackground(AttributeSet attributes)
Extracts a background color from a set of attributes.
- Specified by:
- getBackground in interface StyledDocument
- Parameters:
attributes
- the attributes from which to get a background color
- Returns:
- the background color that correspond to the attributes
public Element getCharacterElement(int position)
Returns theElement
that corresponds to the character at the specified position.
- Specified by:
- getCharacterElement in interface StyledDocument
- Parameters:
position
- the position of which we query the correspondingElement
- Returns:
- the
Element
that corresponds to the character at the specified position
public Element getDefaultRootElement()
Returns the default root element.
- Specified by:
- getDefaultRootElement in interface Document
- Overrides:
- getDefaultRootElement in interface AbstractDocument
- Returns:
- the default root element
public Font getFont(AttributeSet attributes)
Extracts a font from a set of attributes.
- Specified by:
- getFont in interface StyledDocument
- Parameters:
attributes
- the attributes from which to get a font
- Returns:
- the font that correspond to the attributes
public Color getForeground(AttributeSet attributes)
Extracts a foreground color from a set of attributes.
- Specified by:
- getForeground in interface StyledDocument
- Parameters:
attributes
- the attributes from which to get a foreground color
- Returns:
- the foreground color that correspond to the attributes
public Style getLogicalStyle(int position)
Returns the logicalStyle
for the specified position.
- Specified by:
- getLogicalStyle in interface StyledDocument
- Parameters:
position
- the position from which to query to logical style
- Returns:
- the logical
Style
for the specified position
public Element getParagraphElement(int position)
Returns the paragraph element for the specified position. If the position is outside the bounds of the document's root element, then the closest element is returned. That is the last paragraph ifposition >= endIndex
or the first paragraph ifposition <32startIndex
.
- Specified by:
- getParagraphElement in interface StyledDocument
- Overrides:
- getParagraphElement in interface AbstractDocument
- Parameters:
position
- the position for which to query the paragraph element
- Returns:
- the paragraph element for the specified position
public Style getStyle(String nm)
Looks up and returns a namedStyle
.
- Specified by:
- getStyle in interface StyledDocument
- Parameters:
nm
- the name of theStyle
- Returns:
- the found
Style
ofnull
if no suchStyle
exists
public Enumeration getStyleNames()
Returns an enumeration of all style names.
- Returns:
- an enumeration of all style names
protected void insert(int offset, DefaultStyledDocument.ElementSpec[] data) throws BadLocationException
Inserts a bulk of structured content at once.
- Parameters:
offset
- the offset at which the content should be inserteddata
- the actual content spec to be inserted
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent ev, AttributeSet attr)
Called in response to content insert actions. This is used to update the element structure.
- Overrides:
- insertUpdate in interface AbstractDocument
- Parameters:
ev
- theDocumentEvent
describing the changeattr
- the attributes for the change
public void removeStyle(String nm)
Removes a namedStyle
from the style hierarchy.
- Specified by:
- removeStyle in interface StyledDocument
- Parameters:
nm
- the name of theStyle
to be removed
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent ev)
Updates the document structure in response to text removal. This is forwarded to theDefaultStyledDocument.ElementBuffer
of this document. Any changes to the document structure are added to the specified document event and sent to registered listeners.
- Overrides:
- removeUpdate in interface AbstractDocument
- Parameters:
ev
- the document event that records the changes to the document
public void setCharacterAttributes(int offset, int length, AttributeSet attributes, boolean replace)
Sets text attributes for the fragment specified byoffset
andlength
.
- Specified by:
- setCharacterAttributes in interface StyledDocument
- Parameters:
offset
- the start offset of the fragmentlength
- the length of the fragmentattributes
- the text attributes to setreplace
- iftrue
, the attributes of the current selection are overridden, otherwise they are merged
public void setLogicalStyle(int position, Style style)
Sets the logical style for the paragraph at the specified position.
- Specified by:
- setLogicalStyle in interface StyledDocument
- Parameters:
position
- the position at which the logical style is addedstyle
- the style to set for the current paragraph
public void setParagraphAttributes(int offset, int length, AttributeSet attributes, boolean replace)
Sets text attributes for the paragraph at the specified fragment.
- Specified by:
- setParagraphAttributes in interface StyledDocument
- Parameters:
offset
- the beginning of the fragmentlength
- the length of the fragmentattributes
- the text attributes to setreplace
- iftrue
, the attributes of the current selection are overridden, otherwise they are merged
protected void styleChanged(Style style)
Called when any of this document's styles changes.
- Parameters:
style
- the style that changed