- java.lang.Object
-
- javax.swing.text.AbstractDocument
-
- javax.swing.text.PlainDocument
-
- All Implemented Interfaces:
- Serializable, Document
public class PlainDocument extends AbstractDocument
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 JavaBeansTM has been added to the
java.beans
package. Please seeXMLEncoder
.- See Also:
Document
,AbstractDocument
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
-
-
Field Summary
Fields Modifier and Type Field and Description static String
lineLimitAttribute
Name of the attribute that specifies the maximum length of a line, if there is a maximum length.static String
tabSizeAttribute
Name of the attribute that specifies the tab size for tabs contained in the content.-
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
-
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
-
-
Constructor Summary
Constructors Constructor and Description PlainDocument()
Constructs a plain text document.PlainDocument(AbstractDocument.Content c)
Constructs a plain text document.
-
Method Summary
Methods Modifier and Type Method and Description protected AbstractDocument.AbstractElement
createDefaultRoot()
Creates the root element to be used to represent the default document structure.Element
getDefaultRootElement()
Gets the default root element for the document model.Element
getParagraphElement(int pos)
Get the paragraph element containing the given position.void
insertString(int offs, String str, AttributeSet a)
Inserts some content into the document.protected void
insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
Updates document structure as a result of text insertion.protected void
removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
Updates any document structure as a result of text removal.-
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, 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 Detail
-
tabSizeAttribute
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.- See Also:
- Constant Field Values
-
lineLimitAttribute
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.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PlainDocument
public PlainDocument()
Constructs a plain text document. A default model usingGapContent
is constructed and set.
-
PlainDocument
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
- the container for the content
-
-
Method Detail
-
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 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 How to Use Threads for more information.
- Specified by:
insertString
in interfaceDocument
- Overrides:
insertString
in classAbstractDocument
- Parameters:
offs
- the starting offset >= 0str
- the string to insert; does nothing with null/empty stringsa
- the attributes for the inserted content- Throws:
BadLocationException
- the given insert position is not a valid position within the document- See Also:
Document.insertString(int, java.lang.String, javax.swing.text.AttributeSet)
-
getDefaultRootElement
public Element getDefaultRootElement()
Gets the default root element for the document model.- Specified by:
getDefaultRootElement
in interfaceDocument
- Specified by:
getDefaultRootElement
in classAbstractDocument
- Returns:
- the root
- See Also:
Document.getDefaultRootElement()
-
createDefaultRoot
protected AbstractDocument.AbstractElement createDefaultRoot()
Creates the root element to be used to represent the default document structure.- Returns:
- the element base
-
getParagraphElement
public Element getParagraphElement(int pos)
Get the paragraph element containing the given position. Since this document only models lines, it returns the line instead.- Specified by:
getParagraphElement
in classAbstractDocument
- Parameters:
pos
- the starting offset >= 0- Returns:
- the element
-
insertUpdate
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
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.- Overrides:
insertUpdate
in classAbstractDocument
- Parameters:
chng
- the change event describing the ditattr
- the set of attributes for the inserted text
-
removeUpdate
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
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.- Overrides:
removeUpdate
in classAbstractDocument
- Parameters:
chng
- the change event describing the edit
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/swing/text/PlainDocument.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.