All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.swing.text.AbstractDocument
java.lang.Object
|
+----java.awt.swing.text.AbstractDocument
- public abstract class AbstractDocument
- extends Object
- implements Document, Serializable
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.
AbstractDocument.AbstractElement- Implements the abstract part of an element.
AbstractDocument.AttributeContext- An interface that can be used to allow MutableAttributeSet
implementations to use pluggable attribute compression
techniques.
AbstractDocument.BranchElement- Implements a composite element that contains other elements.
AbstractDocument.Content- Interface to describe a sequence of character content that
can be edited.
AbstractDocument.LeafElement- Implements an element that directly represents content of
some kind.
BAD_LOCATION- Error message to indicate a bad location.
ContentElementName- Name of elements used to represent content
ElementNameAttribute- Name of the attribute used to specify element
names.
listenerList- The event listener list for the document.
ParagraphElementName- Name of elements used to represent paragraphs
SectionElementName- Name of elements used to hold sections (lines/paragraphs).
AbstractDocument(AbstractDocument.Content)
- Constructs a new AbstractDocument, wrapped around some specified content.
addDocumentListener(DocumentListener)
- Adds a document listener for notification of any changes.
createBranchElement(Element, AttributeSet)
- Creates a document branch element, that can contain other elements.
createLeafElement(Element, AttributeSet, int, int)
- Creates a document leaf element.
createPosition(int)
- Returns a position that will track change as the document
is altered.
dump(PrintStream)
- Gives a diagnostic dump.
externalNotifyChange(DocumentEvent)
- Notifies external listeners of a document attribute change.
externalNotifyInsert(DocumentEvent)
- Notifies external listeners of a document insertion.
externalNotifyRemove(DocumentEvent)
- Notifies external listeners of a document removal.
fireChangedUpdate(DocumentEvent)
- Notifies all listeners that have registered interest for
notification on this event type.
fireInsertUpdate(DocumentEvent)
- Notifies all listeners that have registered interest for
notification on this event type.
fireRemoveUpdate(DocumentEvent)
- Notifies all listeners that have registered interest for
notification on this event type.
getAttributeContext()
- Fetch the context for managing attributes.
getContent()
- Gets the content for the document.
getCurrentWriter()
- Fetches the current writing thread if there is one.
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 the length of the data.
getProperty(Object)
- Gets a property for the document.
getRootElements()
- Gets all root elements defined.
getStartPosition()
- Returns a position that represents the start of the document.
getText(int, int)
- Gets a subsequence of text from the document.
getText(int, int, Segment)
- Gets some text from the document.
insertString(int, String, AttributeSet)
- Inserts some content into the document.
insertUpdate(DefaultDocumentEvent, AttributeSet)
- Updates document structure as a result of text insertion.
notifyUnlock()
- Releases the notification lock.
putProperty(Object, Object)
- Sets a property for the document.
readLock()
- Acquires a lock to begin reading some state from the
document.
readUnlock()
- Does a read unlock.
remove(int, int)
- Removes some content from the document.
removeDocumentListener(DocumentListener)
- Removes a document listener.
removeUpdate(DefaultDocumentEvent)
- Updates any document structure as a result of text removal.
writeAbandoned()
- Releases the write/notify lock held because the write
operation is being aborted.
writeLock()
- Acquires a lock to begin mutating the document this lock
protects.
writeUnlockNotifyLock()
- Releases the write lock indicating that there will be no
more mutations to the document, and acquire a lock for
notifying observers of the document of the mutations to
the document.
listenerList
protected EventListenerList listenerList
- The event listener list for the document.
BAD_LOCATION
protected static final String BAD_LOCATION
- Error message to indicate a bad location.
ParagraphElementName
public static final String ParagraphElementName
- Name of elements used to represent paragraphs
ContentElementName
public static final String ContentElementName
- Name of elements used to represent content
SectionElementName
public static final String SectionElementName
- Name of elements used to hold sections (lines/paragraphs).
ElementNameAttribute
public static final String ElementNameAttribute
- Name of the attribute used to specify element
names.
AbstractDocument
protected AbstractDocument(AbstractDocument.Content data)
- Constructs a new AbstractDocument, wrapped around some specified content.
- Parameters:
- data - the content
getLength
public int getLength()
- Returns the length of the data.
This method grabs a read lock. If there is currently a writer,
then this call is blocked until the writer is finished making
changes.
- Returns:
- the length
- See Also:
- getLength
addDocumentListener
public void addDocumentListener(DocumentListener listener)
- Adds a document listener for notification of any changes.
- Parameters:
- listener - the listener
- See Also:
- addDocumentListener
removeDocumentListener
public void removeDocumentListener(DocumentListener listener)
- Removes a document listener.
- Parameters:
- listener - the listener
- See Also:
- removeDocumentListener
fireInsertUpdate
protected void fireInsertUpdate(DocumentEvent e)
- Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
- Parameters:
- e - the event
- See Also:
- EventListenerList
fireChangedUpdate
protected void fireChangedUpdate(DocumentEvent e)
- Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
- Parameters:
- e - the event
- See Also:
- EventListenerList
fireRemoveUpdate
protected void fireRemoveUpdate(DocumentEvent e)
- Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
- Parameters:
- e - the event
- See Also:
- EventListenerList
getProperty
public Object getProperty(Object key)
- Gets a property for the document.
- Parameters:
- key - the property key
- Returns:
- the value
putProperty
public void putProperty(Object key,
Object value)
- Sets a property for the document.
- Parameters:
- key - the property key
- value - the property value
remove
public void remove(int offs,
int len) throws BadLocationException
- Removes some content from the document.
Removing content causes a write lock to be held while the
actual changes are taking place, followed by a read lock
which is held while observers are notified of the change.
- Parameters:
- offs - the starting offset
- len - the number of characters to remove
- Throws:
BadLocationException
- the given remove position is not a valid
position within the document
- See Also:
- remove
insertString
public void insertString(int offs,
String str,
AttributeSet a) throws BadLocationException
- Inserts some content into the document.
Inserting content causes a write lock to be held while the
actual changes are taking place, followed by a notification
lock (that allows reads but not writes) while observers are
notified of the change.
- Parameters:
- offs - the starting offset
- str - the string to insert
- a - the attributes for the inserted content
- Throws:
BadLocationException
- the given insert position is not a valid
position within the document
- See Also:
- insertString
getText
public String getText(int offset,
int length) throws BadLocationException
- Gets a subsequence of text from the document.
This method grabs a read lock. If there is currently a writer,
then this call is blocked until the writer is finished making
changes.
- Parameters:
- offset - the starting offset
- length - the number of characters to retrieve
- Returns:
- the text
- Throws:
BadLocationException
- the range given includes a position
that is not a valid position within the document
- See Also:
- getText
getText
public void getText(int offset,
int length,
Segment txt) throws BadLocationException
- Gets some text from the document.
- Parameters:
- offset - the starting offset
- length - the number of characters to retrieve
- txt - the Segment object to retrieve the text into
- Throws:
BadLocationException
- the range given includes a position
that is not a valid position within the document
getStartPosition
public Position getStartPosition()
- Returns a position that represents the start of the document.
- Returns:
- the position
- See Also:
- getStartPosition
getEndPosition
public Position getEndPosition()
- Returns a position that represents the end of the document.
This method grabs a read lock. If there is currently a writer,
then this call is blocked until the writer is finished making
changes.
- Returns:
- the position
- See Also:
- getEndPosition
createPosition
public Position createPosition(int offs) throws BadLocationException
- Returns a position that will track change as the document
is altered.
- Parameters:
- offs - the position
- Returns:
- the position
- Throws:
BadLocationException
- if the given position does not represent a
valid location in the associated document
- See Also:
- createPosition
getRootElements
public Element[] getRootElements()
- Gets all root elements defined. Typically, there
will only be one so the default implementation
is to return the default root element.
- 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
- See Also:
- getDefaultRootElement
getAttributeContext
protected AbstractDocument.AttributeContext getAttributeContext()
- Fetch the context for managing attributes. This
method effectively establishes the strategy used
for compressing AttributeSet information.
insertUpdate
protected void insertUpdate(DefaultDocumentEvent chng,
AttributeSet attr)
- Updates document structure as a result of text insertion. This
will happen within a write lock. If a subclass of
this class reimplements this method, it should delegate to the
superclass as well.
- Parameters:
- chng - a description of the change
- attr - the attributes for the change
removeUpdate
protected void removeUpdate(DefaultDocumentEvent chng)
- Updates any document structure as a result of text removal.
This will happen within a write lock. If a subclass
of this class reimplements this method, it should delegate to the
superclass as well.
- Parameters:
- chng - a description of the change
dump
public void dump(PrintStream out)
- Gives a diagnostic dump.
- Parameters:
- out - the output stream
getContent
protected final AbstractDocument.Content getContent()
- Gets the content for the document.
- Returns:
- the content
externalNotifyInsert
protected final void externalNotifyInsert(DocumentEvent e)
- Notifies external listeners of a document insertion. This removes
the write lock and grabs a notification lock that prevents
further writes, but allows reads. At the end of notification
the notification lock is removed and writes can resume if there
are no active readers.
- Parameters:
- e - the document event
externalNotifyChange
protected final void externalNotifyChange(DocumentEvent e)
- Notifies external listeners of a document attribute change. This
removes the write lock and grabs a notification lock that prevents
further writes, but allows reads. At the end of notification
the notification lock is removed and writes can resume if there
are no active readers.
- Parameters:
- e - the document event
externalNotifyRemove
protected final void externalNotifyRemove(DocumentEvent e)
- Notifies external listeners of a document removal. This removes
the write lock and grabs a notification lock that prevents
further writes, but allows reads. At the end of notification
the notification lock is removed and writes can resume if there
are no active readers.
- Parameters:
- e - the document event
createLeafElement
protected Element createLeafElement(Element parent,
AttributeSet a,
int p0,
int p1)
- Creates a document leaf element.
Hook through which elements are created to represent the
document structure. Because this implementation keeps
structure and content seperate, elements grow automatically
when content is extended so splits of existing elements
follow. The document itself gets to decide how to generate
elements to give flexibility in the type of elements used.
- Parameters:
- parent - the parent element
- a - the attributes for the element
- p0 - the beginning of the range
- p1 - the end of the range
- Returns:
- the new element
createBranchElement
protected Element createBranchElement(Element parent,
AttributeSet a)
- Creates a document branch element, that can contain other elements.
- Parameters:
- parent - the parent element
- a - the attributes
- Returns:
- the element
getCurrentWriter
protected final Thread getCurrentWriter()
- Fetches the current writing thread if there is one.
This can be used to distinguish whether a method is
being called as part of an existing modification or
if a lock needs to be acquired and a new transaction
started.
writeLock
protected final void writeLock()
- Acquires a lock to begin mutating the document this lock
protects. There can be no notification of changes or
reading going on in order to gain the lock.
writeUnlockNotifyLock
protected final void writeUnlockNotifyLock()
- Releases the write lock indicating that there will be no
more mutations to the document, and acquire a lock for
notifying observers of the document of the mutations to
the document. Readers are allowed in this state.
writeAbandoned
protected final void writeAbandoned()
- Releases the write/notify lock held because the write
operation is being aborted.
notifyUnlock
protected final void notifyUnlock()
- Releases the notification lock. This enables writing to
occur again.
readLock
protected final void readLock()
- Acquires a lock to begin reading some state from the
document. There can be multiple readers at the same time
and reading can occur while notification to the listeners
is going on, but writing blocks the readers. If the calling
thread is currently writing, it simply returns.
readUnlock
protected final void readUnlock()
- Does a read unlock.
One of the readers is done. If there are no more readers
then writing can begin again. If the calling thread is currently
writing, is simply returns.
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature