Coverage details for ui.util.FileExtensionFilter

LineHitsSource
1 /*******************************************************************************
2  * InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20 package ui.util;
21  
22 import java.io.File;
23 import java.io.FilenameFilter;
24  
25 import javax.swing.filechooser.FileFilter;
26  
273public class FileExtensionFilter extends FileFilter implements FilenameFilter {
28  
29     /**
30      * Comment for <code>extension</code> The file's extension.
31      */
32     private final String extension;
33  
34     /**
35      * Comment for <code>description</code> The extension's descriptor, eg.
36      * "xml" = eXtensible MarkUp Language.
37      */
3819    private String description = ""; //$NON-NLS-1$
39  
40     /**
41      * Comment for <code>DOT</code> It stores the static value for the dot:
42      * ".".
43      */
4419    private static String DOT = "."; //$NON-NLS-1$
45  
46     /**
47      * @param extension
48      * The file's extension;
49      */
500    public FileExtensionFilter(String extension) {
510        this.extension = extension.toLowerCase();
520    }
53  
54     /**
55      * @param extension
56      * The file's extension;
57      * @param description
58      * The file extension's description.
59      */
6019    public FileExtensionFilter(String extension, String description) {
6119        this.extension = extension.toLowerCase();
6219        this.description = description;
6319    }
64  
65     /*
66      * (non-Javadoc)
67      *
68      * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
69      */
70     public boolean accept(File file, String extension) {
710        return extension.endsWith(this.extension.toLowerCase())
720                || extension.endsWith(this.extension.toUpperCase());
73     }
74  
75     public boolean validExtension(String extension) {
76180        return extension.startsWith(DOT)
7724                && (extension.endsWith(this.extension.toLowerCase()) || extension
7824                        .endsWith(this.extension.toUpperCase()));
79     }
80  
81     /**
82      * @return Returns the extension.
83      */
84     public String getExtension() {
850        return extension;
86     }
87  
88     /**
89      * This method just adds a DOT to the extension and returns it.
90      *
91      * @return Returns the dotted extension, eg. ".jpeg" or ".xml".
92      */
93     public String getDottedExtension() {
940        return DOT + extension;
95     }
96  
97     @Override
98     public boolean accept(File file) {
991404        if (file.isDirectory())
1001248            return true;
101156        if (!file.getName().contains(DOT))
1020            return false;
103156        int dotIndex = file.getName().indexOf(DOT);
104156        int length = file.getName().length();
105156        return validExtension(file.getName().substring(dotIndex, length));
106     }
107  
108     @Override
109     public String getDescription() {
11057        return description.equals("") ? extension.toUpperCase() : description; //$NON-NLS-1$
111     }
112  
113     /**
114      * @param description
115      * The description to set.
116      */
117     public void setDescription(String description) {
1180        this.description = description;
1190    }
120  
121 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.