|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjavax.swing.RowFilter<M,I>
M - 模型的类型;例如
PersonModel
I - 标识符的类型;使用
TableRowSorter 时,此类型将是
Integer
public 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 为
null
Calendar,
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 为
null
public 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 为 null
Arrays.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 为 null
Arrays.asList(T...)
public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter)
RowFilter,它包含提供的过滤器不包含的条目。
filter - 要求反 (negate) 的
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 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。