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.
Since it is common for text documents to have lines or paragraphs, there
are methods to get this kind of information.

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:
- Logical document structure.
- View projections.
- Lexical token streams.
- Parse trees.
- Conversions to formats other than the native format.
- Modification specifications.
- Annotations.
- See Also:
- DocumentEvent, DocumentListener, Element, Position, AttributeSet
-
addDocumentListener(DocumentListener)
- Registers the given observer to begin receiving notifications
when changes are made to the document.
-
createPosition(int)
- Returns a position that will track change as the document
is altered.
-
getDefaultRootElement()
- Returns the root element that views should be based upon
unless some other mechanism for assigning views to element
structures is provided.
-
getEndPosition()
- Returns a position that represents the end of the document.
-
getLength()
- Returns number of characters of content currently
in the document.
-
getProperty(Object)
- Gets properties associated with the document.
-
getRootElement(String)
- Returns a root element of a document structure with the given name.
-
getStartPosition()
- Returns a position that represents the start of the document.
-
getText(int, int)
- Fetches the text contained within the given portion
of the document.
-
getText(int, int, Segment)
- Fetches the text contained within the given portion
of the document.
-
insertString(int, String, AttributeSet)
- Inserts a string of content.
-
putProperty(Object, Object)
- Puts a new property on the list.
-
remove(int, int)
- Removes a portion of the content of the document.
-
removeDocumentListener(DocumentListener)
- Unregisters the given observer from the notification list
so it will no longer receive change updates.
getLength
public abstract int getLength()
- Returns number of characters of content currently
in the document.
- Returns:
- number of characters
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
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
getProperty
public abstract Object getProperty(Object key)
- Gets properties associated with the document. Allows one to
store things like the document title, author, etc.
- Returns:
- the properties
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
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: BadLocation
- 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
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: BadLocation
- the given insert position is not a valid
position within the document
- See Also:
- DocumentEvent, DocumentListener
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: BadLocation
- 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.
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: BadLocation
- 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.
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
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
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: BadLocation
- if the given position does not represent a
valid location in the associated document
getRootElement
public abstract Element getRootElement(String nm)
- Returns a root element of a document structure with the given name.
- Parameters:
- nm - the name of the root element desired
- Returns:
- the root element
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
All Packages Class Hierarchy This Package Previous Next Index