|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
java.lang.Objectjavax.swing.RowFilter<M,I>
M - モデルの型。PersonModel などI - 識別子の型。TableRowSorter の使用時は Integerpublic abstract class RowFilter<M,I>
RowFilter は、エントリをモデルから除去して、ビューに表示されないようにするために使用します。たとえば、JTable に関連付けられた RowFilter では、特定の文字列を持つ列が含まれている行しか許可されないことがあります。エントリの意味は、コンポーネントの型によって異なります。たとえば、フィルタが JTable に関連付けられている場合、エントリは行を意味します。フィルタが JTree に関連付けられている場合、エントリはノードを意味します。
サブクラスは、include メソッドをオーバーライドして、エントリをビューに表示するかどうかを指定する必要があります。エントリの各列の値を取得するには、Entry 引数を使用できます。次に、例として、文字列「a」で始まる値 (複数可) を含むエントリだけを許可する include メソッドを示します。
RowFilter<Object,Object> startsWithAFilter = new RowFilter<Object,Object>() {
public boolean include(Entry<? extends Object, ? extends Object> entry) {
for (int i = entry.getValueCount() - 1; i >= 0; i--) {
if (entry.getStringValue(i).startsWith("a")) {
// The value starts with "a", include it
return true;
}
}
// None of the columns start with "a"; return false so that this
// entry is not shown
return false;
}
};
RowFilter には、特定のモデルの RowFilter の作成を許可する 2 つの仮パラメータ型が用意されています。たとえば、次のコードは、Person 型のオブジェクトをラップする特定のモデルを示しています。20 歳以上の Person だけが表示されます。
RowFilter<PersonModel,Integer> ageFilter = new RowFilter<PersonModel,Integer>() {
public boolean include(Entry<? extends PersonModel, ? extends Integer> entry) {
PersonModel personModel = entry.getModel();
Person person = personModel.getPerson(entry.getIdentifier());
if (person.getAge() > 20) {
// Returning true indicates this row should be shown.
return true;
}
// Age is <= 20, don't show it.
return false;
}
};
PersonModel model = createPersonModel();
TableRowSorter<PersonModel> sorter = new TableRowSorter<PersonModel>(model);
sorter.setRowFilter(ageFilter);
TableRowSorter| 入れ子のクラスの概要 | |
|---|---|
static class |
RowFilter.ComparisonType
一部のデフォルトの RowFilter でサポートされる、値比較に使用される可能性がある値の列挙です。 |
static class |
RowFilter.Entry<M,I>
Entry オブジェクトが RowFilter のインスタンスに渡されると、フィルタはエントリのデータ値を取得し、エントリを表示するかどうかを判断することができます。 |
| コンストラクタの概要 | |
|---|---|
RowFilter()
|
|
| メソッドの概要 | ||
|---|---|---|
static
|
andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
指定されたすべてのフィルタがエントリを含める場合、エントリを含める RowFilter を返します。 |
|
static
|
dateFilter(RowFilter.ComparisonType type,
Date date,
int... indices)
指定された基準を満たす Date 値を少なくとも 1 つ以上持つエントリを含める RowFilter を返します。 |
|
abstract boolean |
include(RowFilter.Entry<? extends M,? extends I> entry)
指定されたエントリを表示する場合は true、表示しない場合は false を返します。 |
|
static
|
notFilter(RowFilter<M,I> filter)
指定されたフィルタがエントリを含めない場合、エントリを含める RowFilter を返します。 |
|
static
|
numberFilter(RowFilter.ComparisonType type,
Number number,
int... indices)
指定された基準を満たす Number 値を少なくとも 1 つ以上持つエントリを含める RowFilter を返します。 |
|
static
|
orFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
指定されたフィルタの中にエントリを含めるものがあった場合に、エントリを含める RowFilter を返します。 |
|
static
|
regexFilter(String regex,
int... indices)
正規表現を使って含めるエントリを特定する RowFilter を返します。 |
|
| クラス java.lang.Object から継承されたメソッド |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| コンストラクタの詳細 |
|---|
public RowFilter()
| メソッドの詳細 |
|---|
public static <M,I> RowFilter<M,I> regexFilter(String regex,
int... indices)
RowFilter を返します。一致する値を少なくとも 1 つ以上持つエントリが含められます。たとえば次のコードは、「a」で始まる値を少なくとも 1 つ以上持つエントリを含める RowFilter を作成します。
RowFilter.regexFilter("^a");
返されるフィルタは、Matcher.find() を使って取り込み内容を確認します。完全一致の有無を確認するには、文字列「^」と「$」を使って、文字列の先頭と末尾の文字を比較します。たとえば「^foo$」と指定した場合、「foo」と完全に一致する文字列のある行だけが含められます。「food」は一致とは見なされません。サポートされている正規表現の構文の詳細は、Pattern を参照してください。
regex - フィルタを適用する正規表現indices - 調べる値のインデックス。そうでない場合は、指定されたすべての値が 評価される
RowFilter
NullPointerException - regex が null の場合
IllegalArgumentException - indices に 0 より小さい値が含まれる場合
PatternSyntaxException - regex が 有効な正規表現でない場合Pattern
public static <M,I> RowFilter<M,I> dateFilter(RowFilter.ComparisonType type,
Date date,
int... indices)
Date 値を少なくとも 1 つ以上持つエントリを含める RowFilter を返します。たとえば次の RowFilter は、現在の日付よりあとの 1 つ以上の日付の値を持つエントリを含めます。
RowFilter.dateFilter(ComparisonType.AFTER, new Date());
type - 実行する比較の型date - 比較対象の日付indices - 調べる値のインデックス。そうでない場合は、指定されたすべての値が 評価される
RowFilter
NullPointerException - date が null の場合
IllegalArgumentException - indices に 0 より小さい値が含まれる場合、または type が null の場合Calendar,
Date
public static <M,I> RowFilter<M,I> numberFilter(RowFilter.ComparisonType type,
Number number,
int... indices)
Number 値を少なくとも 1 つ以上持つエントリを含める RowFilter を返します。たとえば次のフィルタは、10 と等しい値を少なくとも 1 つ以上持つエントリを含めます。
RowFilter.numberFilter(ComparisonType.EQUAL, 10);
type - 実行する比較の型indices - 調べる値のインデックス。そうでない場合は、指定されたすべての値が 評価される
RowFilter
IllegalArgumentException - indices に 0 より小さい値が含まれる場合、type が null の場合、または number が null の場合public static <M,I> RowFilter<M,I> orFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
RowFilter を返します。
次のサンプルコードは、文字列「foo」または「bar」があるエントリを含める RowFilter を作成します。
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter("foo"));
filters.add(RowFilter.regexFilter("bar"));
RowFilter<Object,Object> fooBarFilter = RowFilter.orFilter(filters);
filters - 判定する対象となる RowFilter
RowFilter
IllegalArgumentException - null のフィルタが 存在する場合
NullPointerException - filters が null の場合Arrays.asList(T...)public static <M,I> RowFilter<M,I> andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
RowFilter を返します。
次のサンプルコードは、文字列「foo」と「bar」があるエントリを含める RowFilter を作成します。
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter("foo"));
filters.add(RowFilter.regexFilter("bar"));
RowFilter<Object,Object> fooBarFilter = RowFilter.andFilter(filters);
filters - 判定する対象となる RowFilter
RowFilter
IllegalArgumentException - null のフィルタが 存在する場合
NullPointerException - filters が null の場合Arrays.asList(T...)public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter)
RowFilter を返します。
filter - 否定する RowFilter
RowFilter
IllegalArgumentException - filter が null の場合public abstract boolean include(RowFilter.Entry<? extends M,? extends I> entry)
entry 引数は、呼び出しの間にかぎり有効です。呼び出しの完了後に entry を使用した場合の動作は未定義です。
entry - 配下のモデルからのオブジェクトをラップする null 以外の オブジェクト
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。