1 package org.wcb.gui.dialog.filter;
2
3 import java.io.File;
4
5 /**
6 * <small>
7 * Copyright (c) 2006 wbogaardt.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * <p/>
22 * $File: $ <br>
23 * $Change: $ submitted by $Author: wbogaardt $ at $DateTime: Apr 3, 2006 11:28:57 AM $ <br>
24 * </small>
25 *
26 * @author wbogaardt
27 * @version 1
28 * Date: Apr 3, 2006
29 * Time: 11:28:57 AM
30 */
31
32 public class CSVFileExtensionFilter extends javax.swing.filechooser.FileFilter {
33
34 /**
35 * This determinse if the passed in file should be displayed.
36 * @param f File path and name
37 * @return true indicates display file
38 */
39 public boolean accept(File f) {
40 boolean accept = f.isDirectory();
41 if (!accept)
42 {
43 String suffix = getSuffix(f);
44 if (suffix != null)
45 {
46 accept = suffix.equals("csv");
47 }
48 }
49 return accept;
50 }
51
52 /**
53 * Gets the description of the filter for display in the
54 * file open dialog
55 * @return String of the displayable filter description
56 */
57 public String getDescription() {
58 return "CSV (Comma delimited) (*.csv)";
59 }
60
61 /**
62 * Gets the suffix of the file.
63 * @param f The file name
64 * @return String after the period.
65 */
66 private String getSuffix(File f) {
67 String s = f.getPath(), suffix = null;
68 int i = s.lastIndexOf('.');
69 if (i > 0 && i < s.length() - 1)
70 {
71 suffix = s.substring(i + 1).toLowerCase();
72 }
73 return suffix;
74 }
75 }