Java Doc for DefaultStyledDocument.java in  » 6.0-JDK-Core » swing » javax » swing » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing.text 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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 :public static class AttributeUndoableEdit extends AbstractUndoableEdit
Inner Class :static class StyleChangeUndoableEdit extends AbstractUndoableEdit
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  intBUFFER_SIZE_DEFAULT
     The default size of the initial content buffer.
protected  ElementBufferbuffer
    

Constructor Summary
public  DefaultStyledDocument(Content c, StyleContext styles)
     Constructs a styled document.
public  DefaultStyledDocument(StyleContext styles)
     Constructs a styled document with the default content storage implementation and a shared set of styles.
public  DefaultStyledDocument()
     Constructs a default styled document.

Method Summary
public  voidaddDocumentListener(DocumentListener listener)
     Adds a document listener for notification of any changes.
public  StyleaddStyle(String nm, Style parent)
     Adds a new style into the logical style hierarchy.
protected  voidcreate(ElementSpec[] data)
     Initialize the document to reflect the given element structure (i.e.
protected  AbstractElementcreateDefaultRoot()
     Creates the root element to be used to represent the default document structure.
 shortcreateSpecsForInsertAfterNewline(Element paragraph, Element pParagraph, AttributeSet pattr, Vector parseBuffer, int offset, int endOffset)
     This is called by insertUpdate when inserting after a new line.
 ChangeListenercreateStyleChangeListener()
     Returns a new instance of StyleChangeHandler.
 ChangeListenercreateStyleContextChangeListener()
     Returns a new instance of StyleContextChangeHandler.
public  ColorgetBackground(AttributeSet attr)
     Gets the background color from an attribute set.
public  ElementgetCharacterElement(int pos)
     Gets a character element based on a position.
public  ElementgetDefaultRootElement()
     Gets the default root element.
public  FontgetFont(AttributeSet attr)
     Gets the font from an attribute set.
public  ColorgetForeground(AttributeSet attr)
     Gets the foreground color from an attribute set.
public  StylegetLogicalStyle(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  ElementgetParagraphElement(int pos)
     Gets the paragraph element at the offset pos.
public  StylegetStyle(String nm)
     Fetches a named style previously added.
public  EnumerationgetStyleNames()
     Fetches the list of of style names.
protected  voidinsert(int offset, ElementSpec[] data)
     Inserts new elements in bulk.
protected  voidinsertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
     Updates document structure as a result of text insertion.
public  voidremoveDocumentListener(DocumentListener listener)
     Removes a document listener.
public  voidremoveElement(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  voidremoveStyle(String nm)
     Removes a named style previously added to the document.
protected  voidremoveUpdate(DefaultDocumentEvent chng)
     Updates document structure as a result of text removal.
public  voidsetCharacterAttributes(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  voidsetLogicalStyle(int pos, Style s)
     Sets the logical style to use for the paragraph at the given position.
public  voidsetParagraphAttributes(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  voidstyleChanged(Style style)
     Called when any of this document's styles have changed.
 voidupdateStylesListeningTo()
     Adds a ChangeListener to new styles, and removes ChangeListener from old styles.

Field Detail
BUFFER_SIZE_DEFAULT
final public static int BUFFER_SIZE_DEFAULT(Code)
The default size of the initial content buffer.



buffer
protected ElementBuffer buffer(Code)




Constructor Detail
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.




Method Detail
addDocumentListener
public void addDocumentListener(DocumentListener listener)(Code)
Adds a document listener for notification of any changes.
Parameters:
  listener - the listener
See Also:   Document.addDocumentListener



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



getDefaultRootElement
public Element getDefaultRootElement()(Code)
Gets the default root element. the root
See Also:   Document.getDefaultRootElement



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



removeDocumentListener
public void removeDocumentListener(DocumentListener listener)(Code)
Removes a document listener.
Parameters:
  listener - the listener
See Also:   Document.removeDocumentListener



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.



Fields inherited from javax.swing.text.AbstractDocument
final static String AsyncLoadPriority(Code)(Java Doc)
final protected static String BAD_LOCATION(Code)(Java Doc)
final public static String BidiElementName(Code)(Java Doc)
final public static String ContentElementName(Code)(Java Doc)
final public static String ElementNameAttribute(Code)(Java Doc)
final static String I18NProperty(Code)(Java Doc)
final static Object MultiByteProperty(Code)(Java Doc)
final public static String ParagraphElementName(Code)(Java Doc)
final public static String SectionElementName(Code)(Java Doc)
protected EventListenerList listenerList(Code)(Java Doc)

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)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.