1/*
2
3   Licensed to the Apache Software Foundation (ASF) under one or more
4   contributor license agreements.  See the NOTICE file distributed with
5   this work for additional information regarding copyright ownership.
6   The ASF licenses this file to You under the Apache License, Version 2.0
7   (the "License"); you may not use this file except in compliance with
8   the License.  You may obtain a copy of the License at
9
10       http://www.apache.org/licenses/LICENSE-2.0
11
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17
18 */
19package components;
20
21import java.io.File;
22
23import javax.swing.filechooser.FileFilter;
24
25/**
26 * This class filters file for a given <tt>SquiggleInputHandler</tt>
27 *
28 * @author <a mailto="vincent.hardy@sun.com">Vincent Hardy</a>
29 * @version $Id: SquiggleInputHandlerFilter.java,v 1.1 2013/02/21 11:24:35 jschimpf Exp $
30 */
31public class SquiggleInputHandlerFilter extends FileFilter {
32    protected SquiggleInputHandler handler;
33
34    public SquiggleInputHandlerFilter(SquiggleInputHandler handler) {
35        this.handler = handler;
36    }
37
38    public boolean accept(File f) {
39        return f.isDirectory() || handler.accept(f);
40    }
41
42    public String getDescription() {
43        StringBuffer sb = new StringBuffer();
44        String[] extensions = handler.getHandledExtensions();
45        int n = extensions != null ? extensions.length : 0;
46        for (int i=0; i<n; i++) {
47            if (i > 0) {
48                sb.append(", ");
49            }
50            sb.append(extensions[i]);
51        }
52
53        if (n > 0) {
54            sb.append( ' ' );
55        }
56
57        sb.append(handler.getDescription());
58        return sb.toString();
59    }
60}
61