public class DocumentFilter extends Object
DocumentFilter は、名前が示すように Document 変更メソッドのフィルタです。DocumentFilter を格納する Document が、insert または remove を介して変更されると、適当なメソッド呼び出しが DocumentFilter に転送されます。デフォルトの実装では、変更が可能です。サブクラスは、場合に応じてメソッドをスーパークラス上に呼び出すか、渡された FilterBypass に必要なメソッドを呼び出すことで、変更にフィルタを設定できます。サブクラスは、変更を Document にコールバックするのではなく、スーパークラスや FilterBypass への呼び出しを行う必要があります。
remove または insertString が DocumentFilter 上で呼び出されると、DocumentFilter は FilterBypass を複数回または異なる領域に対してコールバックできますが、remove または insertString メソッドから返されたあとに、FilterBypass へコールバックしてはいけません。
デフォルトでは、AbstractDocument の insertString、replace、remove などのテキスト関連のドキュメント変更メソッドは、使用可能な場合に DocumentFilter を使用し、DefaultStyledDocument の create、insert、removeElement などの Element 関連の変更メソッドは DocumentFilter を使用しません。メソッドがこれらのデフォルトに従わない場合、メソッドドキュメンテーションに明示的に記載する必要があります。
Document, AbstractDocument, DefaultStyledDocument| 修飾子と型 | クラスと説明 |
|---|---|
static class |
DocumentFilter.FilterBypass
Document へのコールバックを回避して、Document を変更する場合に使用されます。
|
| コンストラクタと説明 |
|---|
DocumentFilter() |
| 修飾子と型 | メソッドと説明 |
|---|---|
void |
insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)
指定した Document にテキストを挿入する前に呼び出されます。
|
void |
remove(DocumentFilter.FilterBypass fb, int offset, int length)
指定した Document の指定した範囲を削除する前に呼び出されます。
|
void |
replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
指定した Document でテキストの範囲を置き換える前に呼び出されます。
|
public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException
FilterBypass を必要に応じて直接呼び出します。fb - Document の変更に使用する FilterBypassoffset - 先頭からのオフセット >= 0length - 削除対象の文字数 >= 0BadLocationException - 削除範囲の一部がドキュメントの有効な部分でなかった場合。例外内の位置は、最初に検出された不正な位置。public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException
fb - Document の変更に使用する FilterBypassoffset - コンテンツを挿入するドキュメント内のオフセット。0 以上。指定位置やその後ろの変更を追跡するすべての位置が移動します。string - 挿入する文字列attr - 挿入されたコンテンツに関連付ける属性。属性がない場合は null も可。BadLocationException - 指定された挿入位置がドキュメント内の有効な位置でない場合public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException
fb - Document の変更に使用する FilterBypassoffset - Document での位置length - 削除するテキストの長さtext - 挿入するテキスト。null の場合、テキストは挿入されないattrs - 挿入されたテキストの属性を示す AttributeSet。null も可。BadLocationException - 指定された挿入位置がドキュメント内の有効な位置でない場合 バグまたは機能を送信
詳細な API リファレンスおよび開発者ドキュメントについては、Java SE のドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.