All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.text.JDocument

java.lang.Object
   |
   +----com.sun.java.swing.text.JDocument

public class JDocument
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.


Variable Index

 o BAD_LOCATION
 o ContentElementName
Name of elements used to represent content
 o lineMap
 o observers
 o ParagraphElementName
Name of elements used to represent paragraphs
 o SectionElementName
Name of elements used to hold sections (lines/paragraphs).

Constructor Index

 o JDocument(JDocument. Content)

Method Index

 o addDocumentListener(DocumentListener)
 o checkinStickyPosition(Position)
 o checkoutStickyPosition(Position, int)
 o createBranchElement(JDocument. ElementBase, JDocument. ElementBase)
 o createLeafElement(JDocument. ElementBase, JDocument. ElementBase, Range)
Hook through which elements are created to represent the document structure.
 o createLineMap()
Create the root element to be used to represent the line/paragraph map.
 o dump(PrintStream)
 o externalNotifyChange(DocumentEvent)
Notify external listeners of a document attribute change.
 o externalNotifyInsert(DocumentEvent)
Notify external listeners of a document insertion.
 o externalNotifyRemove(DocumentEvent)
Notify external listeners of a document removal.
 o getAttributes()
 o getCurrentWriter()
Fetch the current writing thread if there is one.
 o getDefaultRootElement()
 o getEndPosition()
This method grabs a read lock.
 o getLength()
This method grabs a read lock.
 o getLineCount()
This method grabs a read lock.
 o getRootElement(String)
 o getStartPosition()
 o getText(Range)
This method grabs a read lock.
 o insertString(int, String, Attributes)
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.
 o insertString(Position, String, Attributes)
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.
 o insertUpdate(JDocumentEvent, Attributes)
Update document structure as a result of text insertion.
 o internalGetText(Range)
Internal text access that bypasses locking
 o internalInsertString(int, String, Attributes)
 o internalNotifyRemove(int, int)
 o lineToRange(int)
This method grabs a read lock.
 o notifyUnlock()
Release the notification lock.
 o positionToLine(Position)
This method grabs a read lock.
 o readLock()
Acquire a lock to begin reading some state from the document.
 o readUnlock()
One of the readers is done.
 o remove(int, int)
Removing 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.
 o remove(Range)
Removing 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.
 o removeDocumentListener(DocumentListener)
 o removeRootElement(Element)
 o removeUpdate(JDocumentEvent)
Update any document structure as a result of text removal.
 o setAttributes(Range, Attributes, boolean)
Change the character style used for the given range of existing content in the document.
 o untrackedPosition(Position, int)
 o writeAbandoned()
Release the write/notify lock held because the write operation is being aborted.
 o writeLock()
Acquire a lock to begin mutating the document this lock protects.
 o writeUnlockNotifyLock()
Release 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.

Variables

 o lineMap
 protected JDocument. BranchElement lineMap
 o observers
 protected transient Vector observers
 o BAD_LOCATION
 protected static final String BAD_LOCATION
 o ParagraphElementName
 public static final String ParagraphElementName
Name of elements used to represent paragraphs

 o ContentElementName
 public static final String ContentElementName
Name of elements used to represent content

 o SectionElementName
 public static final String SectionElementName
Name of elements used to hold sections (lines/paragraphs).

Constructors

 o JDocument
 public JDocument(JDocument. Content data)

Methods

 o getLength
 public int getLength()
This method grabs a read lock. If there is currently a writer, then this call is blocked until the writer is finished making changes.

See Also:
getLength
 o addDocumentListener
 public synchronized void addDocumentListener(DocumentListener listener)
See Also:
addDocumentListener
 o removeDocumentListener
 public synchronized void removeDocumentListener(DocumentListener listener)
See Also:
removeDocumentListener
 o getAttributes
 public Attributes getAttributes()
See Also:
getAttributes
 o remove
 public void remove(Range rng) throws BadLocation
Removing 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.

Throws: BadLocation
The given remove position is not a valid position within the document.
See Also:
remove
 o remove
 public void remove(int offs,
                    int len) throws BadLocation
Removing 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.

Throws: BadLocation
The given remove position is not a valid position within the document.
See Also:
remove
 o insertString
 public void insertString(Position pos,
                          String str,
                          Attributes a) throws BadLocation
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.

Throws: BadLocation
The given insert position is not a valid position within the document.
See Also:
insertString
 o insertString
 public void insertString(int offs,
                          String str,
                          Attributes a) throws BadLocation
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.

Throws: BadLocation
The given insert position is not a valid position within the document.
See Also:
insertString
 o getText
 public String getText(Range rng) throws BadLocation
This method grabs a read lock. If there is currently a writer, then this call is blocked until the writer is finished making changes.

Throws: BadLocation
The range given includes a position that is not a valid position within the document.
See Also:
getText
 o getStartPosition
 public Position getStartPosition()
See Also:
getStartPosition
 o getEndPosition
 public Position getEndPosition()
This method grabs a read lock. If there is currently a writer, then this call is blocked until the writer is finished making changes.

See Also:
getEndPosition
 o setAttributes
 public void setAttributes(Range rng,
                           Attributes s,
                           boolean replace)
Change the character style used for the given range of existing content in the document. All of the attributes defined in the given character style are applied to the given range. This method can be used to completely remove all character style attributes for the given range by giving a character style that has no attributes defined and setting replace to true. A write lock is held by this operation, and a DocumentEvent is sent to the listeners after the change has been successfully completed.

Parameters:
rng - The portion of the document to change
s - The style to change it to. Any attributes defined in the given character style will be applied to the text for the given range.
replace - Indicates whether or not the previous attributes should be cleared before the new attributes as set. If true, the operation will replace the previous attributes entirely. If false, the new attributes will be merged with the previous attributes.
 o checkoutStickyPosition
 public synchronized Position checkoutStickyPosition(Position pos,
                                                     int offs)
 o checkinStickyPosition
 public synchronized void checkinStickyPosition(Position pos)
 o untrackedPosition
 public Position untrackedPosition(Position pos,
                                   int offs)
 o positionToLine
 public int positionToLine(Position pos) throws BadLocation
This method grabs a read lock. If there is currently a writer, then this call is blocked until the writer is finished making changes.

Throws: BadLocation
If the given position does not represent a valid location in the associated document.
See Also:
positionToLine
 o lineToRange
 public Range lineToRange(int line)
This method grabs a read lock. If there is currently a writer, then this call is blocked until the writer is finished making changes.

See Also:
lineToRange
 o getLineCount
 public int getLineCount()
This method grabs a read lock. If there is currently a writer, then this call is blocked until the writer is finished making changes.

See Also:
getLineCount
 o getRootElement
 public synchronized Element getRootElement(String nm)
See Also:
getRootElement
 o getDefaultRootElement
 public synchronized Element getDefaultRootElement()
See Also:
getDefaultRootElement
 o removeRootElement
 public synchronized void removeRootElement(Element elem)
 o insertUpdate
 protected void insertUpdate(JDocumentEvent chng,
                             Attributes attr)
Update document structure as a result of text insertion. This will happen within a write lock. If an extension of this class reimplements this method, it should delegate to the superclass as well.

 o removeUpdate
 protected void removeUpdate(JDocumentEvent chng)
Update any document structure as a result of text removal. This will happen within a write lock. If an extension of this class reimplements this method, it should delegate to the superclass as well.

 o internalGetText
 protected String internalGetText(Range rng) throws BadLocation
Internal text access that bypasses locking

Throws: BadLocation
If the given position does not represent a valid location in the associated document.
 o dump
 public void dump(PrintStream out)
 o internalInsertString
 protected JDocumentEvent internalInsertString(int offs,
                                               String str,
                                               Attributes a) throws BadLocation
 o externalNotifyInsert
 protected final void externalNotifyInsert(DocumentEvent e)
Notify 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.

 o externalNotifyChange
 protected final void externalNotifyChange(DocumentEvent e)
Notify 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.

 o externalNotifyRemove
 protected final void externalNotifyRemove(DocumentEvent e)
Notify 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.

 o internalNotifyRemove
 protected DocumentEvent internalNotifyRemove(int offs,
                                              int num) throws BadLocation
 o createLineMap
 protected JDocument. BranchElement createLineMap()
Create the root element to be used to represent the line/paragraph map.

 o createLeafElement
 protected JDocument. LeafElement createLeafElement(JDocument. ElementBase parent,
                                                    JDocument. ElementBase prototype,
                                                    Range rng)
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.

 o createBranchElement
 protected JDocument. BranchElement createBranchElement(JDocument. ElementBase parent,
                                                        JDocument. ElementBase prototype)
 o getCurrentWriter
 protected synchronized Thread getCurrentWriter()
Fetch 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.

Returns:
s The thread actively modifying the document or null if there are no modifications in progress.
 o writeLock
 protected final synchronized void writeLock()
Acquire 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.

 o writeUnlockNotifyLock
 protected final synchronized void writeUnlockNotifyLock()
Release 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.

 o writeAbandoned
 protected final synchronized void writeAbandoned()
Release the write/notify lock held because the write operation is being aborted.

 o notifyUnlock
 protected final synchronized void notifyUnlock()
Release the notification lock. This enables writing to occur again.

 o readLock
 protected final synchronized void readLock()
Acquire 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.

 o readUnlock
 protected final synchronized void readUnlock()
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