java.lang.Object | +----com.sun.java.swing.text.AbstractDocument
An implementation of the document interface to serve as a basis for implementing various kinds of documents. At this level there is very little policy, so there is a corresponding increase in difficulty of use.
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 aquired and released using the render
method. A write lock is aquired 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 DefaultTextUI may be safely updated
asynchronously. The rendering in DefaultTextUI occurs under
the protection of the
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 Swing1.0 applications. It will
not be possible to load serialized Swing1.0 objects with future releases
of Swing. The JDK1.2 release of Swing will be the compatibility
baseline for the serialized form of Swing objects.
This is implemented to aquire a read lock for the duration
of the runnables execution. There may be multiple runnables
executing at the same time, and all writers will be blocked
while there are active rendering runnables. If the runnable
throws an exception, it's lock will be safely released.
There is no protection against a runnable that never exits,
which will effectively leave the document locked for it's
lifetime.
If the given runnable attempts to make any mutations in
this implementation, a deadlock will occur. There is
no tracking of individual rendering threads to enable
detecting this situation, but a subclass could incur
the overhead of tracking them and throwing an error.
This method is thread safe, although most Swing methods
are not.
This method is thread safe, although most Swing methods
are not.
This method is thread safe, although most Swing methods
are not.
This method is thread safe, although most Swing methods
are not.
render
method, which makes
rendering safe if it is running on the event thread (which
happens if using repaint to schedule updates). The code path
for any DocumentListener implementation must not access the
component lock if trying to be safe from deadlocks.
The revalidate
methods
on JComponent are safe.
Variable Index
Constructor Index
Method Index
Variables
listenerList
protected EventListenerList listenerList
BAD_LOCATION
protected static final String BAD_LOCATION
ParagraphElementName
public static final String ParagraphElementName
ContentElementName
public static final String ContentElementName
SectionElementName
public static final String SectionElementName
ElementNameAttribute
public static final String ElementNameAttribute
Constructors
AbstractDocument
protected AbstractDocument(AbstractDocument. Content data)
AbstractDocument
protected AbstractDocument(AbstractDocument. Content data,
AbstractDocument. AttributeContext context)
Methods
getDocumentProperties
public Dictionary getDocumentProperties()
setDocumentProperties
public void setDocumentProperties(Dictionary x)
fireInsertUpdate
protected void fireInsertUpdate(DocumentEvent e)
fireChangedUpdate
protected void fireChangedUpdate(DocumentEvent e)
fireRemoveUpdate
protected void fireRemoveUpdate(DocumentEvent e)
fireUndoableEditUpdate
protected void fireUndoableEditUpdate(UndoableEditEvent e)
render
public void render(Runnable r)
getLength
public int getLength()
addDocumentListener
public void addDocumentListener(DocumentListener listener)
removeDocumentListener
public void removeDocumentListener(DocumentListener listener)
addUndoableEditListener
public void addUndoableEditListener(UndoableEditListener listener)
removeUndoableEditListener
public void removeUndoableEditListener(UndoableEditListener listener)
getProperty
public final Object getProperty(Object key)
putProperty
getDocumentProperties().get(key);
public final void putProperty(Object key,
Object value)
remove
getDocumentProperties().put(key, value);
If value is null this method will remove the property
public void remove(int offs,
int len) throws BadLocationException
insertString
public void insertString(int offs,
String str,
AttributeSet a) throws BadLocationException
getText
public String getText(int offset,
int length) throws BadLocationException
getText
public void getText(int offset,
int length,
Segment txt) throws BadLocationException
createPosition
Segment
should never be mutated.
This kind of access to the characters of the document
is provided to help make the rendering potentially more
efficient. The caller should make no assumptions about
the lifetime of the returned character array, which
should be copied if needed beyond the use for rendering.
public synchronized Position createPosition(int offs) throws BadLocationException
getStartPosition
public final Position getStartPosition()
getEndPosition
public final Position getEndPosition()
getRootElements
public Element[] getRootElements()
getDefaultRootElement
public abstract Element getDefaultRootElement()
getAttributeContext
protected final AbstractDocument. AttributeContext getAttributeContext()
insertUpdate
protected void insertUpdate(AbstractDocument. DefaultDocumentEvent chng,
AttributeSet attr)
removeUpdate
protected void removeUpdate(AbstractDocument. DefaultDocumentEvent chng)
dump
public void dump(PrintStream out)
getContent
protected final AbstractDocument. Content getContent()
createLeafElement
protected Element createLeafElement(Element parent,
AttributeSet a,
int p0,
int p1)
createBranchElement
protected Element createBranchElement(Element parent,
AttributeSet a)
getCurrentWriter
protected final synchronized Thread getCurrentWriter()
writeLock
protected final synchronized void writeLock()
writeUnlock
protected final synchronized void writeUnlock()
readLock
protected final synchronized void readLock()
readUnlock
protected final synchronized void readUnlock()