APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing.text

public Class PlainDocument

extends AbstractDocument
Class Inheritance
Known Direct Subclasses
javax.swing.text.html.HTMLDocument.FixedLengthDocument, javax.swing.text.html.TextAreaDocument
Annotations
@SuppressWarnings:serial
Imports
java.util.Vector

A plain document that maintains no character attributes. The default element structure for this document is a map of the lines in the text. The Element returned by getDefaultRootElement is a map of the lines, and each child element represents a line. This model does not maintain any character level attributes, but each line can be tagged with an arbitrary set of attributes. Line to offset, and offset to line translations can be quickly performed using the default root element. The structure information of the DocumentEvent's fired by edits will indicate the line structure changes.

The default content storage management is performed by a gapped buffer implementation (GapContent). It supports editing reasonably large documents with good efficiency when the edits are contiguous or clustered, as is typical.

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.beans.XMLEncoder.

Author
Timothy Prinzing
See Also
Document, AbstractDocument

Field Summary

Modifier and TypeField and Description
private Vector<Element>
private AbstractDocument.AbstractElement
public static final String
lineLimitAttribute

Name of the attribute that specifies the maximum length of a line, if there is a maximum length.

private Vector<Element>
private transient Segment
s

public static final String
tabSizeAttribute

Name of the attribute that specifies the tab size for tabs contained in the content.

Inherited from javax.swing.text.AbstractDocument:
AsyncLoadPriorityBAD_LOCATIONBidiElementNameContentElementNameElementNameAttributeI18NPropertylistenerListMultiBytePropertyParagraphElementNameSectionElementName

Constructor Summary

AccessConstructor and Description
public
PlainDocument()

Constructs a plain text document.

public
PlainDocument(AbstractDocument.Content
the container for the content
c
)

Constructs a plain text document.

Method Summary

Modifier and TypeMethod and Description
protected AbstractDocument.AbstractElement

Returns:

the element base
createDefaultRoot
()

Creates the root element to be used to represent the default document structure.

public Element

Returns:

the root
getDefaultRootElement
()

Implements abstract javax.swing.text.AbstractDocument.getDefaultRootElement.

Implements javax.swing.text.Document.getDefaultRootElement.

Gets the default root element for the document model.

public Element
getParagraphElement(int pos)

Implements abstract javax.swing.text.AbstractDocument.getParagraphElement.

Get the paragraph element containing the given position.

private 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
)

Overrides javax.swing.text.AbstractDocument.insertString.

Implements javax.swing.text.Document.insertString.

Inserts some content into the document.

protected void
insertUpdate(AbstractDocument.DefaultDocumentEvent
the change event describing the dit
chng
,
AttributeSet
the set of attributes for the inserted text
attr
)

Overrides javax.swing.text.AbstractDocument.insertUpdate.

Updates document structure as a result of text insertion.

protected void
removeUpdate(AbstractDocument.DefaultDocumentEvent
the change event describing the edit
chng
)

Overrides javax.swing.text.AbstractDocument.removeUpdate.

Updates any document structure as a result of text removal.

Inherited from javax.swing.text.AbstractDocument:
addDocumentListeneraddUndoableEditListenercreateBranchElementcreateLeafElementcreatePositiondumpfireChangedUpdatefireInsertUpdatefireRemoveUpdatefireUndoableEditUpdategetAsynchronousLoadPrioritygetAttributeContextgetBidiRootElementgetContentgetCurrentWritergetDocumentFiltergetDocumentListenersgetDocumentPropertiesgetEndPositiongetLengthgetListenersgetPropertygetRootElementsgetStartPositiongetTextgetTextgetUndoableEditListenershandleRemoveisLeftToRightpostRemoveUpdateputPropertyreadLockreadUnlockremoveremoveDocumentListenerremoveUndoableEditListenerrenderreplacesetAsynchronousLoadPrioritysetDocumentFiltersetDocumentPropertiesupdateBidiwriteLockwriteUnlock

Field Detail

addedback to summary
private Vector<Element> added
defaultRootback to summary
private AbstractDocument.AbstractElement defaultRoot
lineLimitAttributeback to summary
public static final String lineLimitAttribute

Name of the attribute that specifies the maximum length of a line, if there is a maximum length. The type for the value is Integer.

removedback to summary
private Vector<Element> removed
sback to summary
private transient Segment s
tabSizeAttributeback to summary
public static final String tabSizeAttribute

Name of the attribute that specifies the tab size for tabs contained in the content. The type for the value is Integer.

Constructor Detail

PlainDocumentback to summary
public PlainDocument()

Constructs a plain text document. A default model using GapContent is constructed and set.

PlainDocumentback to summary
public PlainDocument(AbstractDocument.Content c)

Constructs a plain text document. A default root element is created, and the tab size set to 8.

Parameters
c:AbstractDocument.Content

the container for the content

Method Detail

createDefaultRootback to summary
protected AbstractDocument.AbstractElement createDefaultRoot()

Creates the root element to be used to represent the default document structure.

Returns:AbstractDocument.AbstractElement

the element base

getDefaultRootElementback to summary
public Element getDefaultRootElement()

Implements abstract javax.swing.text.AbstractDocument.getDefaultRootElement.

Implements javax.swing.text.Document.getDefaultRootElement.

Gets the default root element for the document model.

Returns:Element

the root

See Also
Document#getDefaultRootElement
getParagraphElementback to summary
public Element getParagraphElement(int pos)

Implements abstract javax.swing.text.AbstractDocument.getParagraphElement.

Get the paragraph element containing the given position. Since this document only models lines, it returns the line instead.

insertComposedTextUpdateback to summary
private void insertComposedTextUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
insertStringback to summary
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException

Overrides javax.swing.text.AbstractDocument.insertString.

Implements javax.swing.text.Document.insertString.

Inserts some content into the document. Inserting content causes a write lock to be held while the actual changes are taking place, followed by notification to the observers on the thread that grabbed the write lock.

This method is thread safe, although most Swing methods are not. Please see Concurrency in Swing for more information.

Parameters
offs:int

the starting offset >= 0

str:String

the string to insert; does nothing with null/empty strings

a:AttributeSet

the attributes for the inserted content

Exceptions
BadLocationException:
the given insert position is not a valid position within the document
See Also
Document#insertString
insertUpdateback to summary
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)

Overrides javax.swing.text.AbstractDocument.insertUpdate.

Updates document structure as a result of text insertion. This will happen within a write lock. Since this document simply maps out lines, we refresh the line map.

Parameters
chng:AbstractDocument.DefaultDocumentEvent

the change event describing the dit

attr:AttributeSet

the set of attributes for the inserted text

removeUpdateback to summary
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)

Overrides javax.swing.text.AbstractDocument.removeUpdate.

Updates any document structure as a result of text removal. This will happen within a write lock. Since the structure represents a line map, this just checks to see if the removal spans lines. If it does, the two lines outside of the removal area are joined together.

Parameters
chng:AbstractDocument.DefaultDocumentEvent

the change event describing the edit