DocumentFilter, as the name implies, is a filter for the
Document mutation methods. When a Document
containing a DocumentFilter is modified (either through
insert or remove), it forwards the appropriate
method invocation to the DocumentFilter. The
default implementation allows the modification to
occur. Subclasses can filter the modifications by conditionally invoking
methods on the superclass, or invoking the necessary methods on
the passed in FilterBypass. Subclasses should NOT call back
into the Document for the modification
instead call into the superclass or the FilterBypass.
When remove or insertString is invoked
on the DocumentFilter, the DocumentFilter
may callback into the
FilterBypass multiple times, or for different regions, but
it should not callback into the FilterBypass after returning
from the remove or insertString method.
By default, text related document mutation methods such as
insertString, replace and remove
in AbstractDocument use DocumentFilter when
available, and Element related mutation methods such as
create, insert and removeElement in
DefaultStyledDocument do not use DocumentFilter.
If a method doesn't follow these defaults, this must be explicitly stated
in the method documentation.
javax.swing.text.Document , javax.swing.text.AbstractDocument , javax.swing.text.DefaultStyledDocument
| Modifier and Type | Class and Description |
|---|---|
| public abstract static class | DocumentFilter.
Used as a way to circumvent calling back into the Document to change it. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | insertString(DocumentFilter.
FilterBypass that can be used to mutate Document fb,the offset into the document to insert the content >= 0.
All positions that track change at or after the given location
will move. offset, String the string to insert string, AttributeSet the attributes to associate with the inserted
content. This may be null if there are no attributes. attr)Invoked prior to insertion of text into the specified Document. |
| public void | remove(DocumentFilter.
FilterBypass that can be used to mutate Document fb,the offset from the beginning >= 0 offset, int the number of characters to remove >= 0 length)Invoked prior to removal of the specified region in the specified Document. |
| public void | replace(DocumentFilter.
FilterBypass that can be used to mutate Document fb,Location in Document offset, int Length of text to delete length, String Text to insert, null indicates no text to insert text, AttributeSet AttributeSet indicating attributes of inserted text,
null is legal. attrs)Invoked prior to replacing a region of text in the specified Document. |
| DocumentFilter | back to summary |
|---|---|
| public DocumentFilter() Constructs a | |
| insertString | back to summary |
|---|---|
| public void insertString(DocumentFilter. Invoked prior to insertion of text into the specified Document. Subclasses that want to conditionally allow insertion should override this and only call supers implementation as necessary, or call directly into the FilterBypass.
| |
| remove | back to summary |
|---|---|
| public void remove(DocumentFilter. Invoked prior to removal of the specified region in the
specified Document. Subclasses that want to conditionally allow
removal should override this and only call supers implementation as
necessary, or call directly into the
| |
| replace | back to summary |
|---|---|
| public void replace(DocumentFilter. Invoked prior to replacing a region of text in the specified Document. Subclasses that want to conditionally allow replace should override this and only call supers implementation as necessary, or call directly into the FilterBypass.
| |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public abstract Document | Returns: Document that remove/insertString will operate onReturns the Document the mutation is occurring on. |
| public abstract void | insertString(int
the offset into the document to insert the
content >= 0. All positions that track change at or after the
given location will move. offset, String the string to insert string, AttributeSet the attributes to associate with the inserted
content. This may be null if there are no attributes. attr)Inserts the specified text, bypassing the DocumentFilter. |
| public abstract void | remove(int
the offset from the beginning >= 0 offset, int the number of characters to remove >= 0 length)Removes the specified region of text, bypassing the DocumentFilter. |
| public abstract void | replace(int
Location in Document offset, int Length of text to delete length, String Text to insert, null indicates no text to insert string, AttributeSet AttributeSet indicating attributes of inserted text,
null is legal. attrs)Deletes the region of text from |
| FilterBypass | back to summary |
|---|---|
| protected FilterBypass() Constructor for subclasses to call. | |
| getDocument | back to summary |
|---|---|
| public abstract Document getDocument() Returns the Document the mutation is occurring on.
| |
| insertString | back to summary |
|---|---|
| public abstract void insertString(int offset, String string, AttributeSet attr) throws BadLocationException Inserts the specified text, bypassing the DocumentFilter.
| |
| remove | back to summary |
|---|---|
| public abstract void remove(int offset, int length) throws BadLocationException Removes the specified region of text, bypassing the DocumentFilter.
| |
| replace | back to summary |
|---|---|
| public abstract void replace(int offset, int length, String string, AttributeSet attrs) throws BadLocationException Deletes the region of text from
| |