All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface com.sun.java.swing.text.Document

public interface Document

Container for text that supports editing and provides notification of changes (serves as the model in an MVC relationship). Support is provided to mark up the text with structure that tracks changes. The unit of structure is called an element. Views will typically be built from an element structure. Each element can have an arbitrary set of attributes associated with it. The interface itself is intended to be free of any policy for structure that is provided, as the nature of the document structure should be determined by the implementation.

Typically there will be only one document structure, but the interface supports building an arbitrary number of structural projections over the text data. The document can have multiple root elements to support multiple document structures. Some examples might be:

See Also:
DocumentEvent, DocumentListener, Element, Position, AttributeSet

Variable Index

 o StreamDescriptionProperty
The property name for the description of the stream used to initialize the document.
 o TitleProperty
The property name for the title of the document, if there is one.

Method Index

 o addDocumentListener(DocumentListener)
Registers the given observer to begin receiving notifications when changes are made to the document.
 o addUndoableEditListener(UndoableEditListener)
Registers the given observer to begin receiving notifications when undoable edits are made to the document.
 o createPosition(int)
Returns a position that will track change as the document is altered.
 o getDefaultRootElement()
Returns the root element that views should be based upon unless some other mechanism for assigning views to element structures is provided.
 o getEndPosition()
Returns a position that represents the end of the document.
 o getLength()
Returns number of characters of content currently in the document.
 o getProperty(Object)
Gets properties associated with the document.
 o getRootElements()
Returns all of the root elements defined.
 o getStartPosition()
Returns a position that represents the start of the document.
 o getText(int, int)
Fetches the text contained within the given portion of the document.
 o getText(int, int, Segment)
Fetches the text contained within the given portion of the document.
 o insertString(int, String, AttributeSet)
Inserts a string of content.
 o putProperty(Object, Object)
Puts a new property on the list.
 o remove(int, int)
Removes a portion of the content of the document.
 o removeDocumentListener(DocumentListener)
Unregisters the given observer from the notification list so it will no longer receive change updates.
 o removeUndoableEditListener(UndoableEditListener)
Unregisters the given observer from the notification list so it will no longer receive updates.
 o render(Runnable)
This allows the model to be safely rendered in the presence of currency, if the model supports being updated asynchronously.

Variables

 o StreamDescriptionProperty
 public static final String StreamDescriptionProperty
The property name for the description of the stream used to initialize the document. This should be used if the document was initialized from a stream and anything is known about the stream.

 o TitleProperty
 public static final String TitleProperty
The property name for the title of the document, if there is one.

Methods

 o getLength
 public abstract int getLength()
Returns number of characters of content currently in the document.

Returns:
number of characters
 o addDocumentListener
 public abstract void addDocumentListener(DocumentListener listener)
Registers the given observer to begin receiving notifications when changes are made to the document.

Parameters:
listener - the observer to register
See Also:
removeDocumentListener
 o removeDocumentListener
 public abstract void removeDocumentListener(DocumentListener listener)
Unregisters the given observer from the notification list so it will no longer receive change updates.

Parameters:
listener - the observer to register
See Also:
addDocumentListener
 o addUndoableEditListener
 public abstract void addUndoableEditListener(UndoableEditListener listener)
Registers the given observer to begin receiving notifications when undoable edits are made to the document.

Parameters:
listener - the observer to register
See Also:
UndoableEditEvent
 o removeUndoableEditListener
 public abstract void removeUndoableEditListener(UndoableEditListener listener)
Unregisters the given observer from the notification list so it will no longer receive updates.

Parameters:
listener - the observer to register
See Also:
UndoableEditEvent
 o getProperty
 public abstract Object getProperty(Object key)
Gets properties associated with the document. Allows one to store things like the document title, author, etc.

Parameters:
key - a property
Returns:
the properties
 o putProperty
 public abstract void putProperty(Object key,
                                  Object value)
Puts a new property on the list.

Parameters:
key - the property key
value - the property value
 o remove
 public abstract void remove(int offs,
                             int len) throws BadLocationException
Removes a portion of the content of the document. This will cause notification to be sent to the observers of the document (unless an exception is thrown).

Parameters:
offs - the offset from the begining
len - the number of characters to remove
Throws: BadLocationException
some portion of the removal range was not a valid part of the document. The location in the exception is the first bad position encountered.
See Also:
DocumentEvent, DocumentListener
 o insertString
 public abstract void insertString(int offset,
                                   String str,
                                   AttributeSet a) throws BadLocationException
Inserts a string of content. This will cause the observers of the the document to be notified, unless an exception is thrown. A position marks a location in the document between items. If the attributes that have been defined exactly match the current attributes defined at the position, the element representing the content at that position will simply be expanded. If the attributes defined are different, a new content element will be created that matches the attributes.

Parameters:
offset - the offset into the document to insert the content. All positions that track change at or after the given location will move.
str - the string to insert
a - the attributes to associate with the inserted content. This may be null if there are no attributes.
Throws: BadLocationException
the given insert position is not a valid position within the document
See Also:
DocumentEvent, DocumentListener
 o getText
 public abstract String getText(int offset,
                                int length) throws BadLocationException
Fetches the text contained within the given portion of the document.

Parameters:
offset - the offset into the document representing the desired start of the text
length - the length of the desired string
Returns:
the text
Throws: BadLocationException
some portion of the given range was not a valid part of the document. The location in the exception is the first bad position encountered.
 o getText
 public abstract void getText(int offset,
                              int length,
                              Segment txt) throws BadLocationException
Fetches the text contained within the given portion of the document.

Parameters:
offset - the offset into the document representing the desired start of the text
length - the length of the desired string
txt - the Segment object to return the text in
Throws: BadLocationException
Some portion of the given range was not a valid part of the document. The location in the exception is the first bad position encountered.
 o getStartPosition
 public abstract Position getStartPosition()
Returns a position that represents the start of the document. The position returned can be counted on to track change and stay located at the beginning of the document.

Returns:
the position
 o getEndPosition
 public abstract Position getEndPosition()
Returns a position that represents the end of the document. The position returned can be counted on to track change and stay located at the end of the document.

Returns:
the position
 o createPosition
 public abstract Position createPosition(int offs) throws BadLocationException
Returns a position that will track change as the document is altered. If the relative position pos is null, the start of the document will be used.

Parameters:
offs - the offset from the start of the document
Returns:
the position
Throws: BadLocationException
if the given position does not represent a valid location in the associated document
 o getRootElements
 public abstract Element[] getRootElements()
Returns all of the root elements defined.

Returns:
the root element
 o getDefaultRootElement
 public abstract Element getDefaultRootElement()
Returns the root element that views should be based upon unless some other mechanism for assigning views to element structures is provided.

Returns:
the root element
 o render
 public abstract void render(Runnable r)
This allows the model to be safely rendered in the presence of currency, if the model supports being updated asynchronously. The given runnable will be executed in a way that allows it to safely read the model with no changes while the runnable is being executed. The runnable itself may not make any mutations.


All Packages  Class Hierarchy  This Package  Previous  Next  Index