| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
DefaultStyledDocument doc = new DefaultStyledDocument();
Based on 10 examples
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 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 {@link java.beans.XMLEncoder}.
Nested Class Summary | |
---|---|
static class |
An UndoableEdit used to remember AttributeSet changes to an Element. |
class |
Class to manage changes to the element hierarchy. |
static class |
Specification for building elements. |
protected class |
Default root element for a document... |
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 | |
---|---|
protected DefaultStyledDocument.ElementBuffer |
buffer
|
static int |
BUFFER_SIZE_DEFAULT
The default size of the initial content buffer. |
Fields inherited from class javax.swing.text.AbstractDocument |
---|
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName |
Constructor Summary | |
---|---|
Constructs a default styled document. |
|
Constructs a styled document. |
|
DefaultStyledDocument(StyleContext styles) Constructs a styled document with the default content storage implementation and a shared set of styles. |
Method Summary | |
---|---|
void |
addDocumentListener(DocumentListener listener) Adds a document listener for notification of any changes. |
Style |
Adds a new style into the logical style hierarchy. |
protected void |
Initialize the document to reflect the given element structure (i.e. |
protected AbstractDocument.AbstractElement |
Creates the root element to be used to represent the default document structure. |
Color |
getBackground(AttributeSet attr) Gets the background color from an attribute set. |
Element |
getCharacterElement(int pos) Gets a character element based on a position. |
Element |
Gets the default root element. |
Font |
getFont(AttributeSet attr) Gets the font from an attribute set. |
Color |
getForeground(AttributeSet attr) Gets the foreground color from an attribute set. |
Style |
getLogicalStyle(int p) Fetches the logical style assigned to the paragraph represented by the given position. |
Element |
getParagraphElement(int pos) Gets the paragraph element at the offset pos .
|
Style |
Fetches a named style previously added. |
Enumeration |
Fetches the list of of style names. |
protected void |
insert(int offset, DefaultStyledDocument.ElementSpec[] data) Inserts new elements in bulk. |
protected void |
Updates document structure as a result of text insertion. |
void |
removeDocumentListener(DocumentListener listener) Removes a document listener. |
void |
removeStyle(String nm) Removes a named style previously added to the document. |
protected void |
Updates document structure as a result of text removal. |
void |
setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace) Sets attributes for some part of the document. |
void |
setLogicalStyle(int pos, Style s) Sets the logical style to use for the paragraph at the given position. |
void |
setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace) Sets attributes for a paragraph. |
protected void |
styleChanged(Style style) Called when any of this document's styles have changed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected DefaultStyledDocument.ElementBuffer buffer
public static final int BUFFER_SIZE_DEFAULT
Constructor Detail |
---|
public DefaultStyledDocument()
public DefaultStyledDocument(AbstractDocument.Content c, StyleContext styles)
c
- the container for the contentstyles
- resources and style definitions which may
be shared across documentspublic DefaultStyledDocument(StyleContext styles)
styles
- the stylesMethod Detail |
---|
public void addDocumentListener(DocumentListener listener)
addDocumentListener
in class AbstractDocument
listener
- the listenerpublic Style addStyle(String nm, Style 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.protected void create(DefaultStyledDocument.ElementSpec[] data)
getDefaultRootElement
method. If the
document contained any data it will first be removed.
data
protected AbstractDocument.AbstractElement createDefaultRoot()
public Color getBackground(AttributeSet attr)
attr
- the attribute setpublic Element getCharacterElement(int pos)
pos
- the position in the document >= 0public Element getDefaultRootElement()
getDefaultRootElement
in class AbstractDocument
public Font getFont(AttributeSet attr)
attr
- the attribute setpublic Color getForeground(AttributeSet attr)
attr
- the attribute setpublic Style getLogicalStyle(int p)
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.public Element getParagraphElement(int pos)
pos
.
A paragraph consists of at least one child Element, which is usually
a leaf.
getParagraphElement
in class AbstractDocument
pos
- the starting offset >= 0public Style getStyle(String nm)
nm
- the name of the stylepublic Enumeration getStyleNames()
protected void insert(int offset, DefaultStyledDocument.ElementSpec[] data) throws BadLocationException
This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.
offset
- the starting offset >= 0data
- the element dataBadLocationException
- for an invalid starting offsetprotected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
insertUpdate
in class AbstractDocument
chng
- a description of the document changeattr
- the attributespublic void removeDocumentListener(DocumentListener listener)
removeDocumentListener
in class AbstractDocument
listener
- the listenerpublic void removeStyle(String nm)
nm
- the name of the style to removeprotected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
removeUpdate
in class AbstractDocument
chng
- a description of the document changepublic void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)
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 >= 0length
- the length >= 0s
- the attributesreplace
- true if the previous attributes should be replaced
before setting the new attributespublic void setLogicalStyle(int pos, Style s)
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 >= 0s
- the logical style to assign to the paragraph, null if nonepublic void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)
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 >= 0length
- the number of characters affected >= 0s
- the attributesreplace
- whether to replace existing attributes, or merge themprotected void styleChanged(Style style)
style
- The Style that has changed.
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |