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:
- 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
-
StreamDescriptionProperty
- The property name for the description of the stream
used to initialize the document.
-
TitleProperty
- The property name for the title of the document, if
there is one.
-
addDocumentListener(DocumentListener)
- Registers the given observer to begin receiving notifications
when changes are made to the document.
-
addUndoableEditListener(UndoableEditListener)
- Registers the given observer to begin receiving notifications
when undoable edits 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.
-
getRootElements()
- Returns all of the root elements defined.
-
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.
-
removeUndoableEditListener(UndoableEditListener)
- Unregisters the given observer from the notification list
so it will no longer receive updates.
-
render(Runnable)
- This allows the model to be safely rendered in the presence
of currency, if the model supports being updated asynchronously.
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.
TitleProperty
public static final String TitleProperty
- The property name for the title of the document, if
there is one.
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
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
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
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
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: 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
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
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.
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.
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: BadLocationException
- if the given position does not represent a
valid location in the associated document
getRootElements
public abstract Element[] getRootElements()
- Returns all of the root elements defined.
- 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
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