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.
-
BAD_LOCATION
-
-
ContentElementName
- Name of elements used to represent content
-
lineMap
-
-
observers
-
-
ParagraphElementName
- Name of elements used to represent paragraphs
-
SectionElementName
- Name of elements used to hold sections (lines/paragraphs).
-
JDocument(JDocument. Content)
-
-
addDocumentListener(DocumentListener)
-
-
checkinStickyPosition(Position)
-
-
checkoutStickyPosition(Position, int)
-
-
createBranchElement(JDocument. ElementBase, JDocument. ElementBase)
-
-
createLeafElement(JDocument. ElementBase, JDocument. ElementBase, Range)
- Hook through which elements are created to represent the
document structure.
-
createLineMap()
- Create the root element to be used to represent the
line/paragraph map.
-
dump(PrintStream)
-
-
externalNotifyChange(DocumentEvent)
- Notify external listeners of a document attribute change.
-
externalNotifyInsert(DocumentEvent)
- Notify external listeners of a document insertion.
-
externalNotifyRemove(DocumentEvent)
- Notify external listeners of a document removal.
-
getAttributes()
-
-
getCurrentWriter()
- Fetch the current writing thread if there is one.
-
getDefaultRootElement()
-
-
getEndPosition()
- This method grabs a read lock.
-
getLength()
- This method grabs a read lock.
-
getLineCount()
- This method grabs a read lock.
-
getRootElement(String)
-
-
getStartPosition()
-
-
getText(Range)
- This method grabs a read lock.
-
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.
-
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.
-
insertUpdate(JDocumentEvent, Attributes)
- Update document structure as a result of text insertion.
-
internalGetText(Range)
- Internal text access that bypasses locking
-
internalInsertString(int, String, Attributes)
-
-
internalNotifyRemove(int, int)
-
-
lineToRange(int)
- This method grabs a read lock.
-
notifyUnlock()
- Release the notification lock.
-
positionToLine(Position)
- This method grabs a read lock.
-
readLock()
- Acquire a lock to begin reading some state from the
document.
-
readUnlock()
- One of the readers is done.
-
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.
-
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.
-
removeDocumentListener(DocumentListener)
-
-
removeRootElement(Element)
-
-
removeUpdate(JDocumentEvent)
- Update any document structure as a result of text removal.
-
setAttributes(Range, Attributes, boolean)
- Change the character style used for the given range of
existing content in the document.
-
untrackedPosition(Position, int)
-
-
writeAbandoned()
- Release the write/notify lock held because the write
operation is being aborted.
-
writeLock()
- Acquire a lock to begin mutating the document this lock
protects.
-
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.
lineMap
protected JDocument. BranchElement lineMap
observers
protected transient Vector observers
BAD_LOCATION
protected static final String 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).
JDocument
public JDocument(JDocument. Content data)
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
addDocumentListener
public synchronized void addDocumentListener(DocumentListener listener)
- See Also:
- addDocumentListener
removeDocumentListener
public synchronized void removeDocumentListener(DocumentListener listener)
- See Also:
- removeDocumentListener
getAttributes
public Attributes getAttributes()
- See Also:
- getAttributes
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
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
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
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
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
getStartPosition
public Position getStartPosition()
- See Also:
- getStartPosition
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
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.
checkoutStickyPosition
public synchronized Position checkoutStickyPosition(Position pos,
int offs)
checkinStickyPosition
public synchronized void checkinStickyPosition(Position pos)
untrackedPosition
public Position untrackedPosition(Position pos,
int offs)
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
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
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
getRootElement
public synchronized Element getRootElement(String nm)
- See Also:
- getRootElement
getDefaultRootElement
public synchronized Element getDefaultRootElement()
- See Also:
- getDefaultRootElement
removeRootElement
public synchronized void removeRootElement(Element elem)
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.
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.
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.
dump
public void dump(PrintStream out)
internalInsertString
protected JDocumentEvent internalInsertString(int offs,
String str,
Attributes a) throws BadLocation
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.
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.
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.
internalNotifyRemove
protected DocumentEvent internalNotifyRemove(int offs,
int num) throws BadLocation
createLineMap
protected JDocument. BranchElement createLineMap()
- Create the root element to be used to represent the
line/paragraph map.
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.
createBranchElement
protected JDocument. BranchElement createBranchElement(JDocument. ElementBase parent,
JDocument. ElementBase prototype)
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.
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.
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.
writeAbandoned
protected final synchronized void writeAbandoned()
- Release the write/notify lock held because the write
operation is being aborted.
notifyUnlock
protected final synchronized void notifyUnlock()
- Release the notification lock. This enables writing to
occur again.
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.
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