All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.text.DefaultStyledDocument

java.lang.Object
   |
   +----com.sun.java.swing.text.AbstractDocument
           |
           +----com.sun.java.swing.text.DefaultStyledDocument

public class DefaultStyledDocument
extends AbstractDocument
implements StyledDocument
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 boundries since logical styles are assigned to paragraph boundries.

See Also:
Document, AbstractDocument

Variable Index

 o BUFFER_SIZE_DEFAULT
The default size of the initial content buffer.
 o styles
The style context for the document.

Constructor Index

 o DefaultStyledDocument()
Constructs a default styled document.
 o DefaultStyledDocument(AbstractDocument. Content, StyleContext)
Constructs a styled document.
 o DefaultStyledDocument(StyleContext)
Constructs a styled document with the default content storage implementation and a shared set of styles.

Method Index

 o addStyle(String, Style)
Adds a new style into the logical style hierarchy.
 o createDefaultRoot()
Creates the root element to be used to represent the default document structure.
 o getBackground(AttributeSet)
Gets the background color from an attribute set.
 o getCharacterElement(int)
Gets a character element based on a position.
 o getDefaultRootElement()
 o getFont(AttributeSet)
Gets the font from an attribute set.
 o getForeground(AttributeSet)
Gets the foreground color from an attribute set.
 o getLogicalStyle(int)
Fetches the logical style assigned to the paragraph represented by the given position.
 o getParagraphElement(int)
Gets a paragraph element.
 o getStyle(String)
Fetches a named style previously added.
 o insert(int, DefaultStyledDocument. ElementSpec[])
Inserts new elements in bulk.
 o insertUpdate(DefaultDocumentEvent, AttributeSet)
Updates document structure as a result of text insertion.
 o removeStyle(String)
Removes a named style previously added to the document.
 o removeUpdate(DefaultDocumentEvent)
Updates document structure as a result of text removal.
 o setCharacterAttributes(int, int, AttributeSet, boolean)
Sets attributes for some part of the document.
 o setLogicalStyle(int, Style)
Sets the logical style to use for the paragraph at the given position.
 o setParagraphAttributes(int, int, AttributeSet, boolean)
Sets attributes for a paragraph.

Variables

 o BUFFER_SIZE_DEFAULT
 public static final int BUFFER_SIZE_DEFAULT
The default size of the initial content buffer.

 o styles
 protected StyleContext styles
The style context for the document.

Constructors

 o DefaultStyledDocument
 public DefaultStyledDocument(AbstractDocument. Content c,
                              StyleContext styles)
Constructs a styled document.

Parameters:
c - the container for the content
styles - resources and style definitions which may be shared across documents
 o DefaultStyledDocument
 public DefaultStyledDocument(StyleContext styles)
Constructs a styled document with the default content storage implementation and a shared set of styles.

Parameters:
styles - the styles
 o DefaultStyledDocument
 public DefaultStyledDocument()
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.

Methods

 o getDefaultRootElement
 public Element getDefaultRootElement()
Overrides:
getDefaultRootElement in class AbstractDocument
See Also:
getDefaultRootElement
 o insert
 protected void insert(int offset,
                       DefaultStyledDocument. ElementSpec data[]) throws BadLocationException
Inserts new elements in bulk.

Parameters:
offset - the starting offset
Throws: BadLocationException
for an invalid starting offset
Throws: BadLocationException
if the given position does not represent a valid location in the associated document.
See Also:
insert
 o addStyle
 public Style addStyle(String nm,
                       Style parent)
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.

Parameters:
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.
Returns:
the style
 o removeStyle
 public void removeStyle(String nm)
Removes a named style previously added to the document.

Parameters:
nm - the name of the style to remove
 o getStyle
 public Style getStyle(String nm)
Fetches a named style previously added.

Parameters:
nm - the name of the style
Returns:
the style
 o setLogicalStyle
 public void setLogicalStyle(int pos,
                             Style s)
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.

Parameters:
pos - the offset from the start of the document
s - the logical style to assign to the paragraph
 o getLogicalStyle
 public Style getLogicalStyle(int p)
Fetches the logical style assigned to the paragraph represented by the given position.

Parameters:
p - the location to translate to a paragraph and determine the logical style assigned. This is an offset from the start of the document.
Returns:
the style
 o setCharacterAttributes
 public void setCharacterAttributes(int offset,
                                    int length,
                                    AttributeSet s,
                                    boolean replace)
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.

Parameters:
offset - the offset in the document
length - the length
s - the attributes
replace - true if the previous attributes should be replaced before setting the new attributes
 o setParagraphAttributes
 public void setParagraphAttributes(int offset,
                                    int length,
                                    AttributeSet s,
                                    boolean replace)
Sets attributes for a paragraph.

Parameters:
offset - the offset into the paragraph
length - the number of characters affected
s - the attributes
replace - whether to replace existing attributes, or merge them
 o getParagraphElement
 public Element getParagraphElement(int pos)
Gets a paragraph element.

Parameters:
pos - the starting offset
Returns:
the element
 o getCharacterElement
 public Element getCharacterElement(int pos)
Gets a character element based on a position.

Parameters:
pos - the position in the document
Returns:
the element
 o insertUpdate
 protected void insertUpdate(DefaultDocumentEvent chng,
                             AttributeSet attr)
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.

Parameters:
chng - a description of the document change
Overrides:
insertUpdate in class AbstractDocument
 o removeUpdate
 protected void removeUpdate(DefaultDocumentEvent chng)
Updates document structure as a result of text removal.

Parameters:
chng - a description of the document change
Overrides:
removeUpdate in class AbstractDocument
 o createDefaultRoot
 protected AbstractDocument. AbstractElement createDefaultRoot()
Creates the root element to be used to represent the default document structure.

Returns:
the element base
 o getForeground
 public Color getForeground(AttributeSet attr)
Gets the foreground color from an attribute set.

Parameters:
attr - the attribute set
Returns:
the color
 o getBackground
 public Color getBackground(AttributeSet attr)
Gets the background color from an attribute set.

Parameters:
attr - the attribute set
Returns:
the color
 o getFont
 public Font getFont(AttributeSet attr)
Gets the font from an attribute set.

Parameters:
attr - the attribute set
Returns:
the font

All Packages  Class Hierarchy  This Package  Previous  Next  Index