java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.PlainDocument
- All Implemented Interfaces:
- Serializable,- Document
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 XMLEncoder.
- See Also:
- 
Nested Class SummaryNested classes/interfaces declared in class javax.swing.text.AbstractDocumentAbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringName of the attribute that specifies the maximum length of a line, if there is a maximum length.static final StringName of the attribute that specifies the tab size for tabs contained in the content.Fields declared in class javax.swing.text.AbstractDocumentBAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementNameFields declared in interface javax.swing.text.DocumentStreamDescriptionProperty, TitleProperty
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs a plain text document.Constructs a plain text document.
- 
Method SummaryModifier and TypeMethodDescriptionprotected AbstractDocument.AbstractElementCreates the root element to be used to represent the default document structure.Gets the default root element for the document model.getParagraphElement(int pos) Get the paragraph element containing the given position.voidinsertString(int offs, String str, AttributeSet a) Inserts some content into the document.protected voidUpdates document structure as a result of text insertion.protected voidUpdates any document structure as a result of text removal.Methods declared in class javax.swing.text.AbstractDocumentaddDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
- 
Field Details- 
tabSizeAttributeName of the attribute that specifies the tab size for tabs contained in the content. The type for the value is Integer.- See Also:
 
- 
lineLimitAttributeName of the attribute that specifies the maximum length of a line, if there is a maximum length. The type for the value is Integer.- See Also:
 
 
- 
- 
Constructor Details- 
PlainDocumentpublic PlainDocument()Constructs a plain text document. A default model usingGapContentis constructed and set.
- 
PlainDocumentConstructs a plain text document. A default root element is created, and the tab size set to 8.- Parameters:
- c- the container for the content
 
 
- 
- 
Method Details- 
insertStringInserts 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. - Specified by:
- insertStringin interface- Document
- Overrides:
- insertStringin class- AbstractDocument
- Parameters:
- offs- the starting offset >= 0
- str- the string to insert; does nothing with null/empty strings
- a- the attributes for the inserted content
- Throws:
- BadLocationException- the given insert position is not a valid position within the document
- See Also:
 
- 
getDefaultRootElementGets the default root element for the document model.- Specified by:
- getDefaultRootElementin interface- Document
- Specified by:
- getDefaultRootElementin class- AbstractDocument
- Returns:
- the root
- See Also:
 
- 
createDefaultRootCreates the root element to be used to represent the default document structure.- Returns:
- the element base
 
- 
getParagraphElementGet the paragraph element containing the given position. Since this document only models lines, it returns the line instead.- Specified by:
- getParagraphElementin class- AbstractDocument
- Parameters:
- pos- the starting offset >= 0
- Returns:
- the element
 
- 
insertUpdateUpdates 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.- Overrides:
- insertUpdatein class- AbstractDocument
- Parameters:
- chng- the change event describing the dit
- attr- the set of attributes for the inserted text
 
- 
removeUpdateUpdates 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.- Overrides:
- removeUpdatein class- AbstractDocument
- Parameters:
- chng- the change event describing the edit
 
 
-