Home » openjdk-7 » javax » swing » text » [javadoc | source]
javax.swing.text
public class: DefaultStyledDocument [javadoc | source]
java.lang.Object
   javax.swing.text.AbstractDocument
      javax.swing.text.DefaultStyledDocument

All Implemented Interfaces:
    StyledDocument, Document, Serializable

Direct Known Subclasses:
    HTMLDocument, BasicDocument

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 .

Nested Class Summary:
protected class  DefaultStyledDocument.SectionElement  Default root element for a document... maps out the paragraphs/lines contained.

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}. 

public static class  DefaultStyledDocument.ElementSpec  Specification for building elements.

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}. 

public class  DefaultStyledDocument.ElementBuffer  Class to manage changes to the element hierarchy.

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}. 

public static class  DefaultStyledDocument.AttributeUndoableEdit  An UndoableEdit used to remember AttributeSet changes to an Element. 
static class  DefaultStyledDocument.StyleChangeUndoableEdit  UndoableEdit for changing the resolve parent of an Element. 
abstract static class  DefaultStyledDocument.AbstractChangeHandler  Base class for style change handlers with support for stale objects detection. 
static class  DefaultStyledDocument.StyleChangeHandler  Added to all the Styles. When instances of this receive a stateChanged method, styleChanged is invoked. 
static class  DefaultStyledDocument.StyleContextChangeHandler  Added to the StyleContext. When the StyleContext changes, this invokes updateStylesListeningTo
class  DefaultStyledDocument.ChangeUpdateRunnable  When run this creates a change event for the complete document and fires it. 
Field Summary
public static final  int BUFFER_SIZE_DEFAULT    The default size of the initial content buffer. 
protected  ElementBuffer buffer     
Fields inherited from javax.swing.text.AbstractDocument:
listenerList,  BAD_LOCATION,  ParagraphElementName,  ContentElementName,  SectionElementName,  BidiElementName,  ElementNameAttribute,  I18NProperty,  MultiByteProperty,  AsyncLoadPriority
Constructor:
 public 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
 public DefaultStyledDocument(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
Method from javax.swing.text.DefaultStyledDocument Summary:
addDocumentListener,   addStyle,   create,   createDefaultRoot,   createSpecsForInsertAfterNewline,   createStyleChangeListener,   createStyleContextChangeListener,   getBackground,   getCharacterElement,   getDefaultRootElement,   getFont,   getForeground,   getLogicalStyle,   getParagraphElement,   getStyle,   getStyleNames,   insert,   insertUpdate,   removeDocumentListener,   removeElement,   removeStyle,   removeUpdate,   setCharacterAttributes,   setLogicalStyle,   setParagraphAttributes,   styleChanged,   updateStylesListeningTo
Methods from javax.swing.text.AbstractDocument:
addDocumentListener,   addUndoableEditListener,   createBranchElement,   createLeafElement,   createPosition,   dump,   fireChangedUpdate,   fireInsertUpdate,   fireRemoveUpdate,   fireUndoableEditUpdate,   getAsynchronousLoadPriority,   getAttributeContext,   getBidiRootElement,   getContent,   getCurrentWriter,   getDefaultRootElement,   getDocumentFilter,   getDocumentListeners,   getDocumentProperties,   getEndPosition,   getLength,   getListeners,   getParagraphElement,   getProperty,   getRootElements,   getStartPosition,   getText,   getText,   getUndoableEditListeners,   handleInsertString,   handleRemove,   insertString,   insertUpdate,   isLeftToRight,   postRemoveUpdate,   putProperty,   readLock,   readUnlock,   remove,   removeDocumentListener,   removeUndoableEditListener,   removeUpdate,   render,   replace,   setAsynchronousLoadPriority,   setDocumentFilter,   setDocumentProperties,   updateBidi,   writeLock,   writeUnlock
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.text.DefaultStyledDocument Detail:
 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. Style attributes resolve from bottom up so an attribute specified in a child will override an attribute specified in the parent.
 protected  void create(ElementSpec[] data) 
    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.
 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<ElementSpec> parseBuffer,
    int offset,
    int endOffset) 
    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).

 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.
 public Element getParagraphElement(int pos) 
    Gets the paragraph element at the offset pos. A paragraph consists of at least one child Element, which is usually a leaf.
 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) throws BadLocationException 
    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.

 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.
 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. If the element isn't associated with the document, {@code 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 {@code DocumentEvent} for changes in element structure and {@code UndoableEditEvent} for changes in document content.

    If the element contains end-of-content mark (the last {@code "\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 {@code "\n",} it is included in content removal.

    If the element is {@code null,} {@code NullPointerException} is thrown. If the element structure would become invalid after the removal, for example if the element is the document root element, {@code IllegalArgumentException} is thrown. If the current element structure is invalid, {@code IllegalStateException} is thrown.

 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. Please see How to Use Threads for more information.

 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.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 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. Please see How to Use Threads for more information.

 protected  void styleChanged(Style style) 
    Called when any of this document's styles have changed. Subclasses may wish to be intelligent about what gets damaged.
  void updateStylesListeningTo() 
    Adds a ChangeListener to new styles, and removes ChangeListener from old styles.