This class implements a locking mechanism for the document. It
allows multiple readers or one writer, and writers must wait until
all observers of the document have been notified of a previous
change before beginning another mutation to the document. The
read lock is acquired and released using the render
method. A write lock is acquired by the methods that mutate the
document, and are held for the duration of the method call.
Notification is done on the thread that produced the mutation,
and the thread has full read access to the document for the
duration of the notification, but other readers are kept out
until the notification has finished. The notification is a
beans event notification which does not allow any further
mutations until all listeners have been notified.
Any models subclassed from this class and used in conjunction
with a text component that has a look and feel implementation
that is derived from BasicTextUI may be safely updated
asynchronously, because all access to the View hierarchy
is serialized by BasicTextUI if the document is of type
AbstractDocument. The locking assumes that an
independent thread will access the View hierarchy only from
the DocumentListener methods, and that there will be only
one event thread active at a time.
If concurrency support is desired, there are the following
additional implications. The code path for any DocumentListener
implementation and any UndoListener implementation must be threadsafe,
and not access the component lock if trying to be safe from deadlocks.
The repaint and revalidate methods
on JComponent are safe.
AbstractDocument models an implied break at the end of the document.
Among other things this allows you to position the caret after the last
character. As a result of this, getLength returns one less
than the length of the Content. If you create your own Content, be
sure and initialize it to have an additional character. Refer to
StringContent and GapContent for examples of this. Another implication
of this is that Elements that model the implied end character will have
an endOffset == (getLength() + 1). For example, in DefaultStyledDocument
getParagraphElement(getLength()).getEndOffset() == getLength() + 1
.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Class and Description |
|---|---|
| public abstract class | AbstractDocument.
Implements the abstract part of an element. |
| public static interface | AbstractDocument.
An interface that can be used to allow MutableAttributeSet implementations to use pluggable attribute compression techniques. |
| pack-priv class | AbstractDocument.
Represents an element of the bidirectional element structure. |
| pack-priv class | AbstractDocument.
Represents the root element of the bidirectional element structure. |
| public class | AbstractDocument.
Implements a composite element that contains other elements. |
| public static interface | AbstractDocument.
Interface to describe a sequence of character content that can be edited. |
| public class | AbstractDocument.
Stores document changes as the document is being modified. |
| pack-priv class | |
| private class | |
| public static class | AbstractDocument.
An implementation of ElementChange that can be added to the document event. |
| public class | AbstractDocument.
Implements an element that directly represents content of some kind. |
| pack-priv class | AbstractDocument.
This event used when firing document changes while Undo/Redo operations. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final String | AsyncLoadPriority
Document property that indicates asynchronous loading is desired, with the thread priority given as the value. |
| protected static final String | BAD_LOCATION
Error message to indicate a bad location. |
| private static final String | |
| public static final String | BidiElementName
Name of elements used to hold a unidirectional run |
| private transient AbstractDocument. | bidiRoot
The root of the bidirectional structure for this document. |
| public static final String | ContentElementName
Name of elements used to represent content |
| private AbstractDocument. | context
Factory for the attributes. |
| private transient Thread | |
| private AbstractDocument. | data
Where the text is actually stored, and a set of marks that track change as the document is edited are managed. |
| private static Boolean | |
| private DocumentFilter | documentFilter
Filter for inserting/removing of text. |
| private Dictionary | documentProperties
Storage for document-wide properties. |
| public static final String | ElementNameAttribute
Name of the attribute used to specify element names. |
| private transient DocumentFilter. | filterBypass
Used by DocumentFilter to do actual insert/remove. |
| pack-priv static final String | I18NProperty
Document property that indicates whether internationalization functions such as text reordering or reshaping should be performed. |
| protected EventListenerList | listenerList
The event listener list for the document. |
| pack-priv static final Object | MultiByteProperty
Document property that indicates if a character has been inserted into the document that is more than one byte long. |
| private transient boolean | notifyingListeners
True will notifying listeners. |
| private transient int | |
| private transient int | numWriters
The number of writers, all obtained from |
| public static final String | ParagraphElementName
Name of elements used to represent paragraphs |
| public static final String | SectionElementName
Name of elements used to hold sections (lines/paragraphs). |
| Access | Constructor and Description |
|---|---|
| protected | AbstractDocument(AbstractDocument.
the content dataConstructs a new |
| protected | AbstractDocument(AbstractDocument.
the content data,the attribute context contextConstructs a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | addDocumentListener(DocumentListener
the listener)DocumentListener to addImplements javax. Adds a document listener for notification of any changes. |
| public void | addUndoableEditListener(UndoableEditListener
the listener)UndoableEditListener to addImplements javax. Adds an undo listener for notification of any changes. |
| private byte[] | calculateBidiLevels(int firstPStart, int lastPEnd)
Calculate the levels array for a range of paragraphs. |
| protected Element | Returns: the elementthe parent element parent, AttributeSet the attributes a)Creates a document branch element, that can contain other elements. |
| protected Element | Returns: the new elementthe parent element parent, AttributeSet the attributes for the element a, int the beginning of the range >= 0 p0, int the end of the range >= p0 p1)Creates a document leaf element. |
| public synchronized Position | Returns: the positionthe position in the model >= 0 offs)Implements javax. Returns a position that will track change as the document is altered. |
| public void | |
| protected void | fireChangedUpdate(DocumentEvent
the event e)Notifies all listeners that have registered interest for notification on this event type. |
| protected void | fireInsertUpdate(DocumentEvent
the event e)Notifies all listeners that have registered interest for notification on this event type. |
| protected void | fireRemoveUpdate(DocumentEvent
the event e)Notifies all listeners that have registered interest for notification on this event type. |
| protected void | fireUndoableEditUpdate(UndoableEditEvent
the event e)Notifies all listeners that have registered interest for notification on this event type. |
| public int | Returns: the asynchronous loading priority, or-1
if the document should not be loaded asynchronouslyGets the asynchronous loading priority. |
| protected final AbstractDocument. | |
| public Element | Returns: the root element of the bidirectional structure for this documentReturns the root element of the bidirectional structure for this document. |
| protected final AbstractDocument. | |
| protected final synchronized Thread | Returns: the thread actively modifying the document ornull if there are no modifications in progressFetches the current writing thread if there is one. |
| public abstract Element | Returns: the root elementRedeclares javax. Returns the root element that views should be based upon unless some other mechanism for assigning views to element structures is provided. |
| public DocumentFilter | Returns: the DocumentFilterReturns the |
| public DocumentListener[] | Returns: all of this document'sDocumentListeners
or an empty array if no document listeners are
currently registeredReturns an array of all the document listeners registered on this document. |
| public Dictionary | |
| public final Position | Returns: the positionImplements javax. Returns a position that represents the end of the document. |
| private DocumentFilter. | |
| public int | Returns: the length >= 0Implements javax. Returns the length of the data. |
| public < the listener type T extends EventListener> T[] | Returns: an array of all objects registered asFooListeners on this component,
or an empty array if no such
listeners have been addedthe type of listeners requested listenerType)Returns an array of all the objects currently registered
as |
| public abstract Element | Returns: the elementthe starting offset >= 0 pos)Get the paragraph element containing the given position. |
| public final Object | Returns: the value of this property ornullthe non- key)null property keyImplements javax. A convenience method for looking up a property value. |
| public Element[] | Returns: the root elementImplements javax. Gets all root elements defined. |
| public final Position | Returns: the positionImplements javax. Returns a position that represents the start of the document. |
| public String | Returns: the textthe starting offset >= 0 offset, int the number of characters to retrieve >= 0 length)Implements javax. Gets a sequence of text from the document. |
| public void | getText(int
the starting offset >= 0 offset, int the number of characters to retrieve >= 0 length, Segment the Segment object to retrieve the text into txt)Implements javax. Fetches the text contained within the given portion of the document. |
| public UndoableEditListener[] | Returns: all of this document'sUndoableEditListeners
or an empty array if no undoable edit listeners are
currently registeredReturns an array of all the undoable edit listeners registered on this document. |
| private void | handleInsertString(int offs, String str, AttributeSet a)
Performs the actual work of inserting the text; it is assumed the caller has obtained a write lock before invoking this. |
| pack-priv void | |
| public void | insertString(int
the starting offset >= 0 offs, String the string to insert; does nothing with null/empty strings str, AttributeSet the attributes for the inserted content a)Implements javax. Inserts some content into the document. |
| protected void | insertUpdate(AbstractDocument.
a description of the change chng,the attributes for the change attr)Updates document structure as a result of text insertion. |
| pack-priv static boolean | isLeftToRight(Document doc, int p0, int p1)
Returns true if the text in the range |
| protected void | postRemoveUpdate(AbstractDocument.
a description of the change chngUpdates any document structure as a result of text removal. |
| public final void | putProperty(Object
the non- key, Object null keythe property value value)Implements javax. A convenience method for storing up a property value. |
| public final synchronized void | |
| private void | |
| public final synchronized void | |
| public void | remove(int
the starting offset >= 0 offs, int the number of characters to remove >= 0 len)Implements javax. Removes some content from the document. |
| public void | removeDocumentListener(DocumentListener
the listener)DocumentListener to removeImplements javax. Removes a document listener. |
| public void | removeUndoableEditListener(UndoableEditListener
the listener)UndoableEditListener to removeImplements javax. Removes an undo listener. |
| protected void | removeUpdate(AbstractDocument.
a description of the change chngUpdates any document structure as a result of text removal. |
| public void | render(Runnable
the renderer to execute r)Implements javax. This allows the model to be safely rendered in the presence of concurrency, if the model supports being updated asynchronously. |
| public void | replace(int
index of child element offset, int length of text to delete, may be 0 indicating don't
delete anything length, String text to insert, text, AttributeSet null indicates no text to insertAttributeSet indicating attributes of inserted text,
attrs)null
is legal, and typically treated as an empty attributeset,
but exact interpretation is left to the subclassDeletes the region of text from |
| public void | setAsynchronousLoadPriority(int
the new asynchronous loading priority; a value
less than zero indicates that the document should not be
loaded asynchronously p)Sets the asynchronous loading priority. |
| public void | setDocumentFilter(DocumentFilter
the filter)DocumentFilter used to constrain textSets the |
| public void | setDocumentProperties(Dictionary<Object, Object>
the new dictionary x)Replaces the document properties dictionary for this document. |
| pack-priv void | updateBidi(AbstractDocument.
Update the bidi element structure as a result of the given change to the document. |
| protected final synchronized void | |
| protected final synchronized void |