java.lang.Objectjavax.swing.text.AbstractDocument
javax.swing.text.DefaultStyledDocument
public class 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 JavaBeans TM has been added to the java.beans package. Please see XMLEncoder .
Nested Class Summary | |
---|---|
static class |
DefaultStyledDocument.AttributeUndoableEdit
An UndoableEdit used to remember AttributeSet changes to an Element. |
class |
DefaultStyledDocument.ElementBuffer
Class to manage changes to the element hierarchy. |
static class |
DefaultStyledDocument.ElementSpec
Specification for building elements. |
protected class |
DefaultStyledDocument.SectionElement
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 |
Fields inherited from interface javax.swing.text. Document |
---|
StreamDescriptionProperty , TitleProperty |
Constructor Summary | |
---|---|
DefaultStyledDocument
() Constructs a default styled document. |
|
DefaultStyledDocument
(
AbstractDocument.Content
c,
StyleContext
styles) 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 |
addStyle
(
String
nm,
Style
parent) Adds a new style into the logical style hierarchy. |
protected void |
create
(
DefaultStyledDocument.ElementSpec
[] data) Initialize the document to reflect the given element structure (i.e. |
protected AbstractDocument.AbstractElement |
createDefaultRoot
() 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 |
getDefaultRootElement
() 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 |
getStyle
(
String
nm) Fetches a named style previously added. |
Enumeration <?> |
getStyleNames
() Fetches the list of of style names. |
protected void |
insert
(int offset,
DefaultStyledDocument.ElementSpec
[] data) Inserts new elements in bulk. |
protected void |
insertUpdate
(
AbstractDocument.DefaultDocumentEvent
chng,
AttributeSet
attr) 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 |
removeUpdate
(
AbstractDocument.DefaultDocumentEvent
chng) 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 javax.swing.text. AbstractDocument |
---|
addUndoableEditListener , createBranchElement , createLeafElement , createPosition , dump , fireChangedUpdate , fireInsertUpdate , fireRemoveUpdate , fireUndoableEditUpdate , getAsynchronousLoadPriority , getAttributeContext , getBidiRootElement , getContent , getCurrentWriter , getDocumentFilter , getDocumentListeners , getDocumentProperties , getEndPosition , getLength , getListeners , getProperty , getRootElements , getStartPosition , getText , getText , getUndoableEditListeners , insertString , postRemoveUpdate , putProperty , readLock , readUnlock , remove , removeUndoableEditListener , render , replace , setAsynchronousLoadPriority , setDocumentFilter , setDocumentProperties , writeLock , writeUnlock |
Methods inherited from class java.lang. Object |
---|
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
Methods inherited from interface javax.swing.text. Document |
---|
addUndoableEditListener , createPosition , getEndPosition , getLength , getProperty , getRootElements , getStartPosition , getText , getText , insertString , putProperty , remove , removeUndoableEditListener , render |
Field Detail |
---|
public static final int BUFFER_SIZE_DEFAULT
protected DefaultStyledDocument.ElementBuffer buffer
Constructor Detail |
---|
public DefaultStyledDocument(AbstractDocument.Content c, StyleContext styles)
public DefaultStyledDocument(StyleContext styles)
public DefaultStyledDocument()
Method Detail |
---|
public Element getDefaultRootElement()
protected void create(DefaultStyledDocument.ElementSpec[] data)
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
Threads and Swing
for more information.
public Style addStyle(String nm, Style parent)
public void removeStyle(String nm)
public Style getStyle(String nm)
public Enumeration<?> getStyleNames()
public void setLogicalStyle(int pos, Style s)
This method is thread safe, although most Swing methods are not. Please see
How to Use Threads
Threads and Swing
for more information.
public Style getLogicalStyle(int p)
public 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
Threads and Swing
for more information.
public 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
Threads and Swing
for more information.
public Element getParagraphElement(int pos)
public Element getCharacterElement(int pos)
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
protected AbstractDocument.AbstractElement createDefaultRoot()
public Color getForeground(AttributeSet attr)
public Color getBackground(AttributeSet attr)
public Font getFont(AttributeSet attr)
protected void styleChanged(Style style)
public void addDocumentListener(DocumentListener listener)
public void removeDocumentListener(DocumentListener listener)