Java Platform 1.2
Beta 4

Class com.sun.java.swing.text.html.HTMLDocument

java.lang.Object
  |
  +--com.sun.java.swing.text.AbstractDocument
        |
        +--com.sun.java.swing.text.DefaultStyledDocument
              |
              +--com.sun.java.swing.text.html.HTMLDocument

public class HTMLDocument
extends DefaultStyledDocument
A document that models html.

See Also:
Serialized Form

Inner Class Summary
  HTMLDocument.BlockElement
          An element that represents a structual block of html.
  HTMLDocument.HTMLReader
          An html reader to load an html document with an html element structure.
static  HTMLDocument.Iterator
          An iterator to iterate over a particular type of tag.
  HTMLDocument.RunElement
          An element that represents a chunk of text that has a set of html character level attributes assigned to it.
 
Inner classes inherited from class com.sun.java.swing.text.DefaultStyledDocument
DefaultStyledDocument.ElementBuffer , DefaultStyledDocument.ElementSpec , DefaultStyledDocument.SectionElement
 
Inner classes inherited from class com.sun.java.swing.text.AbstractDocument
AbstractDocument.AbstractElement , AbstractDocument.AttributeContext , AbstractDocument.BranchElement , AbstractDocument.Content , AbstractDocument.DefaultDocumentEvent , AbstractDocument.ElementEdit , AbstractDocument.LeafElement
 
Fields inherited from class com.sun.java.swing.text.DefaultStyledDocument
BUFFER_SIZE_DEFAULT
 
Fields inherited from class com.sun.java.swing.text.AbstractDocument
BAD_LOCATION , BidiElementName , ContentElementName , ElementNameAttribute , listenerList , ParagraphElementName , SectionElementName
 
Constructor Summary
HTMLDocument()
          Constructs an html document.
HTMLDocument(AbstractDocument.Content c, StyleSheet styles)
          Constructs an html document with the given content storage implementation and the given style/attribute storage mechanism.
HTMLDocument(StyleSheet styles)
          Constructs an html document with the default content storage implementation and the given style/attribute storage mechanism.
 
Method Summary
protected  void create(DefaultStyledDocument.ElementSpec[] data)
          Replaces the contents of the document with the given element specifications.
protected  Element createBranchElement(Element parent, AttributeSet a)
          Creates a document branch element, that can contain other elements.
protected  AbstractDocument.AbstractElement createDefaultRoot()
          Creates the root element to be used to represent the default document structure.
protected  Element createLeafElement(Element parent, AttributeSet a, int p0, int p1)
          Creates a document leaf element that directly represents text (doesn't have any children).
 URL getBase()
          Get the location to resolve relative url's against.
 HTMLDocument.Iterator getIterator(HTML.Tag t)
          Fetch an iterator for the following kind of html tag.
 HTMLEditorKit.ParserCallback getReader(int pos)
          Fetch the reader for the parser to use to load the document with html.
 StyleSheet getStyleSheet()
          Fetch the StyleSheet with the document-specific display rules(CSS) that were specified in the html document itself.
protected  void insert(int offset, DefaultStyledDocument.ElementSpec[] data)
          Inserts new elements in bulk.
 void setBase(URL u)
          Set the location to resolve relative url's against.
 
Methods inherited from class com.sun.java.swing.text.DefaultStyledDocument
addStyle , getBackground , getCharacterElement , getDefaultRootElement , getFont , getForeground , getLogicalStyle , getParagraphElement , getStyle , getStyleNames , insertUpdate , removeStyle , removeUpdate , setCharacterAttributes , setLogicalStyle , setParagraphAttributes
 
Methods inherited from class com.sun.java.swing.text.AbstractDocument
addDocumentListener , addUndoableEditListener , createPosition , dump , fireChangedUpdate , fireInsertUpdate , fireRemoveUpdate , fireUndoableEditUpdate , getAttributeContext , getBidiRootElement , getContent , getCurrentWriter , getDocumentProperties , getEndPosition , getLength , getProperty , getRootElements , getStartPosition , getText , getText , insertString , postRemoveUpdate , putProperty , readLock , readUnlock , remove , removeDocumentListener , removeUndoableEditListener , render , setDocumentProperties , writeLock , writeUnlock
 
Methods inherited from class java.lang.Object
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait
 

Constructor Detail

HTMLDocument

public HTMLDocument()
Constructs an html document.

HTMLDocument

public HTMLDocument(StyleSheet styles)
Constructs an html document with the default content storage implementation and the given style/attribute storage mechanism.
Parameters:
styles - the styles

HTMLDocument

public HTMLDocument(AbstractDocument.Content c,
                    StyleSheet styles)
Constructs an html document with the given content storage implementation and the given style/attribute storage mechanism.
Parameters:
c - the container for the content
styles - the styles
Method Detail

getReader

public HTMLEditorKit.ParserCallback getReader(int pos)
Fetch the reader for the parser to use to load the document with html. This is implemented to return an instance of HTMLDocument.HTMLReader. Subclasses can reimplement this method to change how the document get structured if desired (e.g. to handle custom tags, structurally represent character style elements, etc.).

getBase

public URL getBase()
Get the location to resolve relative url's against. By default this will be the documents url if the document was loaded from a url. If a base tag is found and can be parsed, it will be used as the reference location.

setBase

public void setBase(URL u)
Set the location to resolve relative url's against. By default this will be the documents url if the document was loaded from a url. If a base tag is found and can be parsed, it will be used as the reference location.

insert

protected void insert(int offset,
                      DefaultStyledDocument.ElementSpec[] data)
               throws BadLocationException
Inserts new elements in bulk. This is how elements get created in the document. The parsing determines what structure is needed and creates the specification as a set of tokens that describe the edit while leaving the document free of a write-lock. This method can then be called in bursts by the reader to acquire a write-lock for a shorter duration (i.e. while the document is actually being altered).
Parameters:
offset - the starting offset
Throws:
BadLocationException - for an invalid starting offset
BadLocationException - if the given position does not represent a valid location in the associated document.
Overrides:
insert in class DefaultStyledDocument
See Also:
StyledDocument#insert

create

protected void create(DefaultStyledDocument.ElementSpec[] data)
Replaces the contents of the document with the given element specifications. This is called before insert if the loading is done in bursts. This is the only method called if loading the document entirely in one burst.
Overrides:
create in class DefaultStyledDocument

getStyleSheet

public StyleSheet getStyleSheet()
Fetch the StyleSheet with the document-specific display rules(CSS) that were specified in the html document itself.

getIterator

public HTMLDocument.Iterator getIterator(HTML.Tag t)
Fetch an iterator for the following kind of html tag. This can be used for things like iterating over the set of anchors contained, iterating over the input elements, etc.

createLeafElement

protected Element createLeafElement(Element parent,
                                    AttributeSet a,
                                    int p0,
                                    int p1)
Creates a document leaf element that directly represents text (doesn't have any children). This is implemented to return an element of type HTMLDocument.RunElement.
Parameters:
parent - the parent element
a - the attributes for the element
p0 - the beginning of the range >= 0
p1 - the end of the range >= p0
Returns:
the new element
Overrides:
createLeafElement in class AbstractDocument

createBranchElement

protected Element createBranchElement(Element parent,
                                      AttributeSet a)
Creates a document branch element, that can contain other elements. This is implemented to return an element of type HTMLDocument.BlockElement.
Parameters:
parent - the parent element
a - the attributes
Returns:
the element
Overrides:
createBranchElement in class AbstractDocument

createDefaultRoot

protected AbstractDocument.AbstractElement createDefaultRoot()
Creates the root element to be used to represent the default document structure.
Returns:
the element base
Overrides:
createDefaultRoot in class DefaultStyledDocument

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.