public class DocumentFilter extends Object
DocumentFilter,顾名思义,是一种
Document诱变方法筛选。当一个
Document含有
DocumentFilter修改(通过
insert或
remove),提出了相应的方法调用的
DocumentFilter。默认的实现允许修改发生。子类可以过滤修改条件调用方法的类,或调用必要的方法对通过
FilterBypass。子类不能调用返回文件的修改而不是调用父类或
FilterBypass
当remove或insertString在DocumentFilter调用的回调,DocumentFilter可能进入FilterBypass多次,或为不同的区域,但它不应该回调到FilterBypass归来后remove或insertString方法。
默认情况下,文本文件insertString突变等方法,在AbstractDocument使用DocumentFilter可用时replace和remove,和Element相关突变的方法如create,在DefaultStyledDocument insert和removeElement不使用DocumentFilter。如果一个方法没有按照这些默认设置,必须在文档中明确说明的方法。
Document,
AbstractDocument,
DefaultStyledDocument
| Modifier and Type | Class and Description |
|---|---|
static class |
DocumentFilter.FilterBypass
用作为一种方法来规避调用回文档来改变它。
|
| Constructor and Description |
|---|
DocumentFilter() |
| Modifier and Type | Method and Description |
|---|---|
void |
insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)
在将文本插入到指定的文档之前调用。
|
void |
remove(DocumentFilter.FilterBypass fb, int offset, int length)
在指定文档中删除指定区域之前调用。
|
void |
replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
在替换指定文档中的文本区域之前调用的。
|
public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException
FilterBypass是必要的。
fb - filterbypass可用于变异文件
offset -从开始> = 0的偏移
length -字符数删除> = 0
BadLocationException -部分的切除范围是不是有效的文档部分。在异常的位置是遇到的第一个错误位置。
public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException
fb - filterbypass可用于变异文件
offset -偏移到文档中插入内容> = 0。在给定位置跟踪更改或在给定位置的所有位置都将移动。
string -插入字符串
attr -与插入的内容关联的属性。如果没有属性,这可能是空的。
BadLocationException -给定的插入位置不在有效的文档位置
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException
fb - filterbypass可用于变异文件
offset定位文档
length长度的文本删除
text文本插入,零表示没有文本插入
attrs - attributeset指示插入的文本属性,空是合法的。
BadLocationException -给定的插入位置不在有效的文档位置
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.