|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.text.AbstractDocument | +--javax.swing.text.DefaultStyledDocument
Safe: 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 java.beans.XMLEncoder
.
Document
,
AbstractDocument
,
Serialized FormField Summary | |
protected javax.swing.text.DefaultStyledDocument.ElementBuffer |
buffer
|
static int |
BUFFER_SIZE_DEFAULT
Enabled: The default size of the initial content buffer. |
private Vector |
listeningStyles
Styles listening to. |
private ChangeListener |
styleChangeListener
Listens to Styles. |
private ChangeListener |
styleContextChangeListener
Listens to Styles. |
private javax.swing.text.DefaultStyledDocument.ChangeUpdateRunnable |
updateRunnable
Run to create a change event for the document |
Fields inherited from class javax.swing.text.AbstractDocument |
AsyncLoadPriority, BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, I18NProperty, listenerList, MultiByteProperty, ParagraphElementName, SectionElementName |
Fields inherited from interface javax.swing.text.Document |
StreamDescriptionProperty, TitleProperty |
Constructor Summary | |
DefaultStyledDocument()
Enabled: Constructs a default styled document. |
|
DefaultStyledDocument(javax.swing.text.AbstractDocument.Content c,
StyleContext styles)
Suppressed: Constructs a styled document. |
|
DefaultStyledDocument(StyleContext styles)
Enabled: Constructs a styled document with the default content storage implementation and a shared set of styles. |
Method Summary | |
void |
addDocumentListener(DocumentListener listener)
Enabled: Adds a document listener for notification of any changes. |
Style |
addStyle(String nm,
Style parent)
Enabled: Adds a new style into the logical style hierarchy. |
protected void |
create(javax.swing.text.DefaultStyledDocument.ElementSpec[] data)
Initialize the document to reflect the given element structure (i.e. |
protected javax.swing.text.AbstractDocument.AbstractElement |
createDefaultRoot()
Creates the root element to be used to represent the default document structure. |
(package private) short |
createSpecsForInsertAfterNewline(Element paragraph,
Element pParagraph,
AttributeSet pattr,
Vector parseBuffer,
int offset,
int endOffset)
This is called by insertUpdate when inserting after a new line. |
(package private) ChangeListener |
createStyleChangeListener()
Returns a new instance of StyleChangeHandler. |
(package private) ChangeListener |
createStyleContextChangeListener()
Returns a new instance of StyleContextChangeHandler. |
Color |
getBackground(AttributeSet attr)
Enabled: Gets the background color from an attribute set. |
Element |
getCharacterElement(int pos)
Enabled: Gets a character element based on a position. |
Element |
getDefaultRootElement()
Enabled: Gets the default root element. |
Font |
getFont(AttributeSet attr)
Enabled: Gets the font from an attribute set. |
Color |
getForeground(AttributeSet attr)
Enabled: Gets the foreground color from an attribute set. |
Style |
getLogicalStyle(int p)
Enabled: Fetches the logical style assigned to the paragraph represented by the given position. |
Element |
getParagraphElement(int pos)
Enabled: Gets the paragraph element at the offset pos . |
Style |
getStyle(String nm)
Enabled: Fetches a named style previously added. |
Enumeration |
getStyleNames()
Enabled: Fetches the list of of style names. |
protected void |
insert(int offset,
javax.swing.text.DefaultStyledDocument.ElementSpec[] data)
Inserts new elements in bulk. |
protected void |
insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent chng,
AttributeSet attr)
Updates document structure as a result of text insertion. |
private void |
readObject(ObjectInputStream s)
|
void |
removeDocumentListener(DocumentListener listener)
Enabled: Removes a document listener. |
void |
removeStyle(String nm)
Enabled: Removes a named style previously added to the document. |
protected void |
removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent chng)
Updates document structure as a result of text removal. |
void |
setCharacterAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
Enabled: Sets attributes for some part of the document. |
void |
setLogicalStyle(int pos,
Style s)
Enabled: Sets the logical style to use for the paragraph at the given position. |
void |
setParagraphAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
Enabled: Sets attributes for a paragraph. |
protected void |
styleChanged(Style style)
Called when any of this document's styles have changed. |
(package private) void |
updateStylesListeningTo()
Adds a ChangeListener to new styles, and removes ChangeListener from old styles. |
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 javax.swing.text.DefaultStyledDocument.ElementBuffer buffer
private transient Vector listeningStyles
private transient ChangeListener styleChangeListener
private transient ChangeListener styleContextChangeListener
private transient javax.swing.text.DefaultStyledDocument.ChangeUpdateRunnable updateRunnable
Constructor Detail |
public DefaultStyledDocument(javax.swing.text.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 stylespublic DefaultStyledDocument()
Method Detail |
public Element getDefaultRootElement()
getDefaultRootElement
in interface Document
getDefaultRootElement
in class AbstractDocument
Document.getDefaultRootElement()
protected void create(javax.swing.text.DefaultStyledDocument.ElementSpec[] data)
getDefaultRootElement
method. If the
document contained any data it will first be removed.
protected void insert(int offset, javax.swing.text.DefaultStyledDocument.ElementSpec[] data) throws BadLocationException
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
offset
- the starting offset >= 0data
- the element data
BadLocationException
public Style addStyle(String nm, Style parent)
addStyle
in interface StyledDocument
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.
public void removeStyle(String nm)
removeStyle
in interface StyledDocument
nm
- the name of the style to removepublic Style getStyle(String nm)
getStyle
in interface StyledDocument
nm
- the name of the style
public Enumeration getStyleNames()
public void setLogicalStyle(int pos, Style s)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
setLogicalStyle
in interface StyledDocument
pos
- the offset from the start of the document >= 0s
- the logical style to assign to the paragraph, null if nonepublic Style getLogicalStyle(int p)
getLogicalStyle
in interface StyledDocument
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 void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
setCharacterAttributes
in interface StyledDocument
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 setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
setParagraphAttributes
in interface StyledDocument
offset
- the offset into the paragraph >= 0length
- the number of characters affected >= 0s
- the attributesreplace
- whether to replace existing attributes, or merge thempublic Element getParagraphElement(int pos)
pos
.
A paragraph consists of at least one child Element, which is usually
a leaf.
getParagraphElement
in interface StyledDocument
getParagraphElement
in class AbstractDocument
pos
- the starting offset >= 0
public Element getCharacterElement(int pos)
getCharacterElement
in interface StyledDocument
pos
- the position in the document >= 0
protected void insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
insertUpdate
in class AbstractDocument
chng
- a description of the document changeattr
- the attributesshort createSpecsForInsertAfterNewline(Element paragraph, Element pParagraph, AttributeSet pattr, Vector parseBuffer, int offset, int endOffset)
parseBuffer
, ElementSpecs that will
position the stack in paragraph
.It returns the direction the last StartSpec should have (this don't necessarily create the last start spec).
protected void removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent chng)
removeUpdate
in class AbstractDocument
chng
- a description of the document changeprotected javax.swing.text.AbstractDocument.AbstractElement createDefaultRoot()
public Color getForeground(AttributeSet attr)
getForeground
in interface StyledDocument
attr
- the attribute set
public Color getBackground(AttributeSet attr)
getBackground
in interface StyledDocument
attr
- the attribute set
public Font getFont(AttributeSet attr)
getFont
in interface StyledDocument
attr
- the attribute set
protected void styleChanged(Style style)
style
- The Style that has changed.public void addDocumentListener(DocumentListener listener)
addDocumentListener
in interface Document
addDocumentListener
in class AbstractDocument
listener
- the listenerDocument.addDocumentListener(javax.swing.event.DocumentListener)
public void removeDocumentListener(DocumentListener listener)
removeDocumentListener
in interface Document
removeDocumentListener
in class AbstractDocument
listener
- the listenerDocument.removeDocumentListener(javax.swing.event.DocumentListener)
ChangeListener createStyleChangeListener()
ChangeListener createStyleContextChangeListener()
void updateStylesListeningTo()
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException
ClassNotFoundException
IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |