| |
|
| java.lang.Object javax.swing.text.AbstractDocument javax.swing.text.DefaultStyledDocument
All known Subclasses: javax.swing.text.html.HTMLDocument,
DefaultStyledDocument | public class DefaultStyledDocument extends AbstractDocument implements StyledDocument(Code) | | 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 .
author: Timothy Prinzing version: 1.133 05/05/07 See Also: Document See Also: AbstractDocument |
Inner Class :protected class SectionElement extends BranchElement | |
Inner Class :public static class ElementSpec | |
Inner Class :public class ElementBuffer implements Serializable | |
Inner Class :abstract static class AbstractChangeHandler implements ChangeListener | |
Inner Class :static class StyleChangeHandler extends AbstractChangeHandler | |
Inner Class :static class StyleContextChangeHandler extends AbstractChangeHandler | |
Inner Class :class ChangeUpdateRunnable implements Runnable | |
Field Summary | |
final public static int | BUFFER_SIZE_DEFAULT The default size of the initial content buffer. | protected ElementBuffer | buffer |
Method Summary | |
public void | addDocumentListener(DocumentListener listener) Adds a document listener for notification of any changes. | public Style | addStyle(String nm, Style parent) Adds a new style into the logical style hierarchy. | protected void | create(ElementSpec[] data) Initialize the document to reflect the given element
structure (i.e. | protected AbstractElement | createDefaultRoot() Creates the root element to be used to represent the
default document structure. | 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. | ChangeListener | createStyleChangeListener() Returns a new instance of StyleChangeHandler. | ChangeListener | createStyleContextChangeListener() Returns a new instance of StyleContextChangeHandler. | public Color | getBackground(AttributeSet attr) Gets the background color from an attribute set. | public Element | getCharacterElement(int pos) Gets a character element based on a position. | public Element | getDefaultRootElement() Gets the default root element. | public Font | getFont(AttributeSet attr) Gets the font from an attribute set. | public Color | getForeground(AttributeSet attr) Gets the foreground color from an attribute set. | 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 paragraphand determine the logical style assigned >= 0. | public Element | getParagraphElement(int pos) Gets the paragraph element at the offset pos . | public Style | getStyle(String nm) Fetches a named style previously added. | public Enumeration> | getStyleNames() Fetches the list of of style names. | protected void | insert(int offset, ElementSpec[] data) Inserts new elements in bulk. | protected void | insertUpdate(DefaultDocumentEvent chng, AttributeSet attr) Updates document structure as a result of text insertion. | public void | removeDocumentListener(DocumentListener listener) Removes a document listener. | public void | removeElement(Element elem) Removes an element from this document.
The element is removed from its parent element, as well as
the text in the range identified by the element. | public void | removeStyle(String nm) Removes a named style previously added to the document. | protected void | removeUpdate(DefaultDocumentEvent chng) Updates document structure as a result of text removal. | 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.
This method is thread safe, although most Swing methods
are not. | public void | setLogicalStyle(int pos, Style s) Sets the logical style to use for the paragraph at the
given position. | public void | setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace) Sets attributes for a paragraph.
This method is thread safe, although most Swing methods
are not. | protected void | styleChanged(Style style) Called when any of this document's styles have changed. | void | updateStylesListeningTo() Adds a ChangeListener to new styles, and removes ChangeListener from
old styles. |
BUFFER_SIZE_DEFAULT | final public static int BUFFER_SIZE_DEFAULT(Code) | | The default size of the initial content buffer.
|
buffer | protected ElementBuffer buffer(Code) | | |
DefaultStyledDocument | public DefaultStyledDocument(Content c, StyleContext styles)(Code) | | Constructs a styled document.
Parameters: c - the container for the content Parameters: styles - resources and style definitions which maybe shared across documents |
DefaultStyledDocument | public DefaultStyledDocument(StyleContext styles)(Code) | | Constructs a styled document with the default content
storage implementation and a shared set of styles.
Parameters: styles - the styles |
DefaultStyledDocument | public DefaultStyledDocument()(Code) | | 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.
|
addStyle | public Style addStyle(String nm, Style parent)(Code) | | 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 thecollection of named styles). The name may be null if the style is unnamed, but the caller is responsiblefor managing the reference returned as an unnamed style can'tbe fetched by name. An unnamed style may be useful for thingslike character attribute overrides such as found in a style run. Parameters: parent - the parent style. This may be null if unspecifiedattributes need not be resolved in some other style. the style |
create | protected void create(ElementSpec[] data)(Code) | | Initialize the document to reflect the given element
structure (i.e. the structure reported by the
getDefaultRootElement method. If the
document contained any data it will first be removed.
|
createDefaultRoot | protected AbstractElement createDefaultRoot()(Code) | | Creates the root element to be used to represent the
default document structure.
the element base |
createSpecsForInsertAfterNewline | short createSpecsForInsertAfterNewline(Element paragraph, Element pParagraph, AttributeSet pattr, Vector parseBuffer, int offset, int endOffset)(Code) | | This is called by insertUpdate when inserting after a new line.
It generates, in 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).
|
createStyleChangeListener | ChangeListener createStyleChangeListener()(Code) | | Returns a new instance of StyleChangeHandler.
|
createStyleContextChangeListener | ChangeListener createStyleContextChangeListener()(Code) | | Returns a new instance of StyleContextChangeHandler.
|
getBackground | public Color getBackground(AttributeSet attr)(Code) | | Gets the background color from an attribute set.
Parameters: attr - the attribute set the color |
getCharacterElement | public Element getCharacterElement(int pos)(Code) | | Gets a character element based on a position.
Parameters: pos - the position in the document >= 0 the element |
getFont | public Font getFont(AttributeSet attr)(Code) | | Gets the font from an attribute set.
Parameters: attr - the attribute set the font |
getForeground | public Color getForeground(AttributeSet attr)(Code) | | Gets the foreground color from an attribute set.
Parameters: attr - the attribute set the color |
getLogicalStyle | public Style getLogicalStyle(int p)(Code) | | Fetches the logical style assigned to the paragraph
represented by the given position.
Parameters: p - the location to translate to a paragraphand determine the logical style assigned >= 0. Thisis an offset from the start of the document. the style, null if none |
getParagraphElement | public Element getParagraphElement(int pos)(Code) | | Gets the paragraph element at the offset pos .
A paragraph consists of at least one child Element, which is usually
a leaf.
Parameters: pos - the starting offset >= 0 the element |
getStyle | public Style getStyle(String nm)(Code) | | Fetches a named style previously added.
Parameters: nm - the name of the style the style |
getStyleNames | public Enumeration> getStyleNames()(Code) | | Fetches the list of of style names.
all the style names |
insert | protected void insert(int offset, ElementSpec[] data) throws BadLocationException(Code) | | Inserts new elements in bulk. This is useful to allow
parsing with the document in an unlocked state and
prepare an element structure modification. This method
takes an array of tokens that describe how to update an
element structure so the time within a write lock can
be greatly reduced in an asynchronous update situation.
This method is thread safe, although most Swing methods
are not. Please see
How
to Use Threads for more information.
Parameters: offset - the starting offset >= 0 Parameters: data - the element data exception: BadLocationException - for an invalid starting offset |
insertUpdate | protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)(Code) | | 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 Parameters: attr - the attributes |
removeElement | public void removeElement(Element elem)(Code) | | Removes an element from this document.
The element is removed from its parent element, as well as
the text in the range identified by the element. If the
element isn't associated with the document,
IllegalArgumentException is thrown.
As empty branch elements are not allowed in the document, if the
element is the sole child, its parent element is removed as well,
recursively. This means that when replacing all the children of a
particular element, new children should be added before
removing old children.
Element removal results in two events being fired, the
DocumentEvent for changes in element structure and
UndoableEditEvent for changes in document content.
If the element contains end-of-content mark (the last
"\n" character in document), this character is not removed;
instead, preceding leaf element is extended to cover the
character. If the last leaf already ends with
"\n", it is
included in content removal.
If the element is
null,
NullPointerException is
thrown. If the element structure would become invalid after the removal,
for example if the element is the document root element,
IllegalArgumentException is thrown. If the current element structure is
invalid,
IllegalStateException is thrown.
Parameters: elem - the element to remove throws: NullPointerException - if the element is null throws: IllegalArgumentException - if the element could not be removed throws: IllegalStateException - if the element structure is invalid since: 1.7 |
removeStyle | public void removeStyle(String nm)(Code) | | Removes a named style previously added to the document.
Parameters: nm - the name of the style to remove |
removeUpdate | protected void removeUpdate(DefaultDocumentEvent chng)(Code) | | Updates document structure as a result of text removal.
Parameters: chng - a description of the document change |
setCharacterAttributes | public void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)(Code) | | 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.
This method is thread safe, although most Swing methods
are not. Please see
How
to Use Threads for more information.
Parameters: offset - the offset in the document >= 0 Parameters: length - the length >= 0 Parameters: s - the attributes Parameters: replace - true if the previous attributes should be replacedbefore setting the new attributes |
setLogicalStyle | public void setLogicalStyle(int pos, Style s)(Code) | | 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.
This method is thread safe, although most Swing methods
are not. Please see
How
to Use Threads for more information.
Parameters: pos - the offset from the start of the document >= 0 Parameters: s - the logical style to assign to the paragraph, null if none |
setParagraphAttributes | public void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)(Code) | | Sets attributes for a paragraph.
This method is thread safe, although most Swing methods
are not. Please see
How
to Use Threads for more information.
Parameters: offset - the offset into the paragraph >= 0 Parameters: length - the number of characters affected >= 0 Parameters: s - the attributes Parameters: replace - whether to replace existing attributes, or merge them |
styleChanged | protected void styleChanged(Style style)(Code) | | Called when any of this document's styles have changed.
Subclasses may wish to be intelligent about what gets damaged.
Parameters: style - The Style that has changed. |
updateStylesListeningTo | void updateStylesListeningTo()(Code) | | Adds a ChangeListener to new styles, and removes ChangeListener from
old styles.
|
Methods inherited from javax.swing.text.AbstractDocument | public void addDocumentListener(DocumentListener listener)(Code)(Java Doc) public void addUndoableEditListener(UndoableEditListener listener)(Code)(Java Doc) protected Element createBranchElement(Element parent, AttributeSet a)(Code)(Java Doc) protected Element createLeafElement(Element parent, AttributeSet a, int p0, int p1)(Code)(Java Doc) public synchronized Position createPosition(int offs) throws BadLocationException(Code)(Java Doc) public void dump(PrintStream out)(Code)(Java Doc) protected void fireChangedUpdate(DocumentEvent e)(Code)(Java Doc) protected void fireInsertUpdate(DocumentEvent e)(Code)(Java Doc) protected void fireRemoveUpdate(DocumentEvent e)(Code)(Java Doc) protected void fireUndoableEditUpdate(UndoableEditEvent e)(Code)(Java Doc) public int getAsynchronousLoadPriority()(Code)(Java Doc) final protected AttributeContext getAttributeContext()(Code)(Java Doc) public Element getBidiRootElement()(Code)(Java Doc) final protected Content getContent()(Code)(Java Doc) final protected synchronized Thread getCurrentWriter()(Code)(Java Doc) abstract public Element getDefaultRootElement()(Code)(Java Doc) public DocumentFilter getDocumentFilter()(Code)(Java Doc) public DocumentListener[] getDocumentListeners()(Code)(Java Doc) public Dictionary<Object, Object> getDocumentProperties()(Code)(Java Doc) final public Position getEndPosition()(Code)(Java Doc) public int getLength()(Code)(Java Doc) public T[] getListeners(Class<T> listenerType)(Code)(Java Doc) abstract public Element getParagraphElement(int pos)(Code)(Java Doc) final public Object getProperty(Object key)(Code)(Java Doc) public Element[] getRootElements()(Code)(Java Doc) final public Position getStartPosition()(Code)(Java Doc) public String getText(int offset, int length) throws BadLocationException(Code)(Java Doc) public void getText(int offset, int length, Segment txt) throws BadLocationException(Code)(Java Doc) public UndoableEditListener[] getUndoableEditListeners()(Code)(Java Doc) void handleInsertString(int offs, String str, AttributeSet a) throws BadLocationException(Code)(Java Doc) void handleRemove(int offs, int len) throws BadLocationException(Code)(Java Doc) public void insertString(int offs, String str, AttributeSet a) throws BadLocationException(Code)(Java Doc) protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)(Code)(Java Doc) boolean isLeftToRight(int p0, int p1)(Code)(Java Doc) protected void postRemoveUpdate(DefaultDocumentEvent chng)(Code)(Java Doc) final public void putProperty(Object key, Object value)(Code)(Java Doc) final public synchronized void readLock()(Code)(Java Doc) final public synchronized void readUnlock()(Code)(Java Doc) public void remove(int offs, int len) throws BadLocationException(Code)(Java Doc) public void removeDocumentListener(DocumentListener listener)(Code)(Java Doc) public void removeUndoableEditListener(UndoableEditListener listener)(Code)(Java Doc) protected void removeUpdate(DefaultDocumentEvent chng)(Code)(Java Doc) public void render(Runnable r)(Code)(Java Doc) public void replace(int offset, int length, String text, AttributeSet attrs) throws BadLocationException(Code)(Java Doc) public void setAsynchronousLoadPriority(int p)(Code)(Java Doc) public void setDocumentFilter(DocumentFilter filter)(Code)(Java Doc) public void setDocumentProperties(Dictionary<Object, Object> x)(Code)(Java Doc) void updateBidi(DefaultDocumentEvent chng)(Code)(Java Doc) final protected synchronized void writeLock()(Code)(Java Doc) final protected synchronized void writeUnlock()(Code)(Java Doc)
|
|
|
|