All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.text.JStyledDocument

java.lang.Object
   |
   +----com.sun.java.swing.text.JDocument
           |
           +----com.sun.java.swing.text.JStyledDocument

public class JStyledDocument
extends JDocument
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 the standard line/paragraph element structure that is managed by the JDocument class since logical styles are assigned to paragraph boundries.

See Also:
Document, JDocument

Variable Index

 o BUFFER_SIZE_DEFAULT
 o styles

Constructor Index

 o JStyledDocument()
Construct a default styled document.
 o JStyledDocument(JDocument. Content, StyleContext)
Construct a styled document.

Method Index

 o addStyle(String, Style)
Add a new style into the logical style hierarchy.
 o characterStyleElement(Position)
 o createBranchElement(JDocument. ElementBase, JDocument. ElementBase)
 o createLargeDocument(StyleContext)
Create a styled text model that supports undo/redo and supports relatively large amounts of content.
 o createLeafElement(JDocument. ElementBase, JDocument. ElementBase, Range)
Hook through which elements are created to represent the document structure.
 o createLineMap()
Create the root element to be used to represent the line/paragraph map.
 o createSmallDocument(StyleContext)
Create a styled text model that does not support undo/redo and stores content as a simple string.
 o getLogicalStyle(Position)
Fetch the logical style assigned to the paragraph represented by the given position.
 o getStyle(String)
Fetch a named style previously added.
 o paragraphStyleElement(Position)
 o positionToStyle(Position)
Fetch the style represented by the given location.
 o removeStyle(String)
Remove a named style previously added to the document.
 o setLogicalStyle(Position, Style)
Set the logical style to use for the paragraph at the given position.

Variables

 o BUFFER_SIZE_DEFAULT
 public static final int BUFFER_SIZE_DEFAULT
 o styles
 protected StyleContext styles

Constructors

 o JStyledDocument
 public JStyledDocument(JDocument. Content c,
                        StyleContext styles)
Construct a styled document.

Parameters:
c - The container for the content.
styles - Resources and style definitions which may be shared across documents.
 o JStyledDocument
 public JStyledDocument()
Construct 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.

Methods

 o createSmallDocument
 public static final Document createSmallDocument(StyleContext sc)
Create a styled text model that does not support undo/redo and stores content as a simple string.

 o createLargeDocument
 public static final Document createLargeDocument(StyleContext sc)
Create a styled text model that supports undo/redo and supports relatively large amounts of content.

 o addStyle
 public Style addStyle(String nm,
                       Style parent)
Add 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 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.
 o removeStyle
 public void removeStyle(String nm)
Remove a named style previously added to the document.

Parameters:
nm - The name of the style to remove
 o getStyle
 public Style getStyle(String nm)
Fetch a named style previously added.

Parameters:
nm - The name of the style
 o setLogicalStyle
 public void setLogicalStyle(Position p,
                             Style s)
Set the logical style to use for the paragraph at the given position. If attributes aren't explicity set for character and paragraph attributes they will resolve through the logical style assigned to the paragraph, which in term may resolve through some hierarchy completely independant of the element hierarchy in the document.

Parameters:
s - The logical style to assign to the paragraph.
 o getLogicalStyle
 public Style getLogicalStyle(Position p)
Fetch the logical style assigned to the paragraph represented by the given position.

Parameters:
p - The location to translate to a paragraph and determine the logical style assigned.
 o positionToStyle
 public Style positionToStyle(Position pos)
Fetch the style represented by the given location. This style overrides the logical style settings. This method aquires a read lock on the document for the duration of the method call.

Parameters:
pos - The location in the document.
 o paragraphStyleElement
 public Element paragraphStyleElement(Position pos)
 o characterStyleElement
 public Element characterStyleElement(Position pos)
 o createLineMap
 protected JDocument. BranchElement createLineMap()
Create the root element to be used to represent the line/paragraph map.

Overrides:
createLineMap in class JDocument
 o createLeafElement
 protected JDocument. LeafElement createLeafElement(JDocument. ElementBase parent,
                                                    JDocument. ElementBase prototype,
                                                    Range rng)
Hook through which elements are created to represent the document structure. Because this implementation keeps structure and content seperate, elements grow automatically when content is extended so splits of existing elements follow. The document itself gets to decide how to generate elements to give flexibility in the type of elements used.

Overrides:
createLeafElement in class JDocument
 o createBranchElement
 protected JDocument. BranchElement createBranchElement(JDocument. ElementBase parent,
                                                        JDocument. ElementBase prototype)
Overrides:
createBranchElement in class JDocument

All Packages  Class Hierarchy  This Package  Previous  Next  Index