Resource Filters

  • Resouce filters allow the user to specify which resources appear in the list.
  • The default filter accepts all resources.
  • Kahuna implements on-the-fly filters such as "*.txt" with a regular expression filter.
  • Standard filters such as "*.script" are also implemented with a regular expression filter.
Interface
ResourceFilter
+ accept(Resource) : boolean
+ getDescription() : String
AcceptAllFilter
+ AcceptAllFilter()
+ accept(Resource) : boolean
RegExpFilter
+ RegExpFilter(Enumeration, String)
+ accept(Resource) : boolean
+ equals(Object) : boolean
+ getDescription() : String
+ getPerlRegExps() : String[]
class ResourceListModel extends AbstractListModel {
    private void redoList(Category category) {
        ...
        Resource[] resources = category.getResources();
        Arrays.sort(resources, resComp);
        for (int i = 0; i < resources.length; i++) {
            if (filter.accept(resources[i])) {
                listItems.add(resources[i]);
            }
        }
        ...
    }
}

public class AcceptAllFilter extends WildcardFilter
        implements ResourceFilter {

    public boolean accept(Resource resource) {
        return true;
    }
}


public class RegExpFilter implements ResourceFilter {
    private String description;
    private String[] perlRegExps;

    public boolean accept(Resource resource) {
        boolean acceptable = false;
        String resName = resource.getName();
        for (int i = 0; i < perlRegExps.length; i++) {
            if (Perl.match(perlRegExps[i], resName)) {
                acceptable = true;
                break;
            }
        }
        return acceptable;
    }

    public String getDescription() {
        return description;
    }
}