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, 2014, Oracle and/or its affiliates. All rights reserved.