|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjavax.swing.RowFilter<M,I>
M - 模型的型別;例如 PersonModelI - 標識符的型別;使用 TableRowSorter 時,此型別將是 Integerpublic abstract class RowFilter<M,I>
RowFilter 用於從模型中過濾條目,使得這些條目不會在視圖中顯示。例如,一個與 JTable 關聯的 RowFilter 可能只允許包含帶指定字元串的列的那些行。條目 的含義取決於元件型別。例如,當過濾器與 JTable 關聯時,一個條目對應於一行;當過濾器與 JTree 關聯時,一個條目對應於一個節點。
子類別必須覆寫 include 方法指示是否應該在視圖中顯示該條目。Entry 參數可用於獲取該條目中每一列的值。下例顯示了一個 include 方法,該方法只允許包含以字元串“a”開頭的一個或多個值的條目。
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。例如,以下程式碼假定一個套件裝 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>
一個傳遞給 RowFilter 實例的 Entry 物件,允許過濾器獲取該條目的資料的值,以確定是否應該顯示該條目。 |
| 建構子摘要 | |
|---|---|
RowFilter()
|
|
| 方法摘要 | ||
|---|---|---|
static
|
andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
返回一個 RowFilter,它包含所有提供的過濾器所包含的條目。 |
|
static
|
dateFilter(RowFilter.ComparisonType type,
Date date,
int... indices)
返回一個 RowFilter,它包含至少具有一個符合指定標準的 Date 值的條目。 |
|
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)
返回一個 RowFilter,它包含至少具有一個符合指定標準的 Number 值的條目。 |
|
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,它使用正則表達式確定要包含哪些條目。只包含至少有一個比對值的條目。例如,以下程式碼創建了一個 RowFilter,它包含其值至少有一個以“a”開頭的條目。
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)
RowFilter,它包含至少具有一個符合指定標準的 Date 值的條目。例如,下面的 RowFilter 只包含至少具有一個當前日期之後的日期值的條目:
RowFilter.dateFilter(ComparisonType.AFTER, new Date());
type - 要執行的比較型別date - 要比較的日期indices - 要檢查的值的索引。如果沒有提供,則計算所有的值
RowFilter
NullPointerException - 如果 date 為 null
IllegalArgumentException - 如果任一 indices 值小於 0 或 type 為 nullCalendar,
Date
public static <M,I> RowFilter<M,I> numberFilter(RowFilter.ComparisonType type,
Number number,
int... indices)
RowFilter,它包含至少具有一個符合指定標準的 Number 值的條目。例如,下面的過濾器將只包含至少具有一個等於 10 的數值的條目:
RowFilter.numberFilter(ComparisonType.EQUAL, 10);
type - 要執行的比較型別indices - 要檢查的值的索引。如果沒有提供,則計算所有值
RowFilter
IllegalArgumentException - 如果任一 indices 值小於 0,type 為 null 或者 number 為 nullpublic static <M,I> RowFilter<M,I> orFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
RowFilter,它包含所有提供的過濾器所包含的條目。
下例創建了一個 RowFilter,它將包括所有套件含字元串“foo”或字元串“bar”的條目:
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 為 nullArrays.asList(T...)public static <M,I> RowFilter<M,I> andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
RowFilter,它包含所有提供的過濾器所包含的條目。
下例創建了一個 RowFilter,它將包括所有套件含字元串“foo”和字元串“bar”的條目:
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 為 nullArrays.asList(T...)public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter)
RowFilter,它包含提供的過濾器不包含的條目。
filter - 要求反 (negate) 的 RowFilter
RowFilter
IllegalArgumentException - 如果 filter 為 nullpublic abstract boolean include(RowFilter.Entry<? extends M,? extends I> entry)
entry 參數只在調用期間有效。在調用返回之後使用 entry 將導致不確定的行為。
entry - 一個非 null 物件,它包裹取自模型的底層物件
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。