Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
RomFilter |
|
| 2.3333333333333335;2.333 |
1 | /* |
|
2 | * RomFilter.java |
|
3 | * |
|
4 | * This file is part of JavaGear. |
|
5 | * |
|
6 | * JavaGear is free software; you can redistribute it and/or modify |
|
7 | * it under the terms of the GNU General Public License as published by |
|
8 | * the Free Software Foundation; either version 2 of the License, or |
|
9 | * (at your option) any later version. |
|
10 | * |
|
11 | * JavaGear 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 JavaGear; if not, write to the Free Software |
|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
19 | */ |
|
20 | ||
21 | package uk.co.javagear; |
|
22 | ||
23 | import java.io.File; |
|
24 | import javax.swing.filechooser.FileFilter; |
|
25 | ||
26 | /** |
|
27 | * JavaGear File Filters (Code from "Core Java Volume #1"). |
|
28 | * |
|
29 | * @author Copyright (C) 2002 Chris White |
|
30 | * @version 17th March 2002 |
|
31 | * @see "JavaGear Final Project Report" |
|
32 | */ |
|
33 | 0 | public class RomFilter extends FileFilter { |
34 | ||
35 | /** |
|
36 | * Returns <code>true</code> if the file given is accepted and <code>false</code> otherwise. |
|
37 | * This filter accepts all directories and files with extension <code>sms</code>, |
|
38 | * <code>gg</code> or <code>zip</code>. |
|
39 | * |
|
40 | * @param f the instance of <code>File</code> to accept or reject. |
|
41 | * @return <code>true</code> if the file given is accepted and <code>false</code> otherwise. |
|
42 | */ |
|
43 | public boolean accept(File f) { |
|
44 | // Allow directories |
|
45 | 0 | if (f.isDirectory()) { |
46 | 0 | return true; |
47 | } |
|
48 | ||
49 | 0 | String extension = getExtension(f); |
50 | ||
51 | 0 | return extension.equals(Setup.System.SMS.getRomFileExtension()) |
52 | || extension.equals(Setup.System.GG.getRomFileExtension()) |
|
53 | || extension.equals(Setup.ZIP_FILE_EXTENSION); |
|
54 | } |
|
55 | ||
56 | /** |
|
57 | * Returns a description of this filter, <code>"All ROMs (*.SMS, *.GG, *.ZIP)"</code>. |
|
58 | * |
|
59 | * @return a description of this filter, <code>"All ROMs (*.SMS, *.GG, *.ZIP)"</code>. |
|
60 | */ |
|
61 | public String getDescription() { |
|
62 | 0 | return "All ROMs (*." + Setup.System.SMS.getRomFileExtension().toUpperCase() |
63 | + ", *." + Setup.System.GG.getRomFileExtension().toUpperCase() |
|
64 | + ", *." + Setup.ZIP_FILE_EXTENSION.toUpperCase() + ")"; |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * Returns a file's extension in lowercase characters. |
|
69 | * |
|
70 | * @param f a non-null instance of <code>File</code>. |
|
71 | * @return the file's extension in lowercase characters. |
|
72 | */ |
|
73 | protected static String getExtension(File f) { |
|
74 | 0 | String s = f.getName(); |
75 | 0 | int i = s.lastIndexOf('.'); |
76 | 0 | if (i > 0 && i < s.length() - 1) { |
77 | 0 | return s.substring(i + 1).toLowerCase(); |
78 | } |
|
79 | 0 | return ""; |
80 | } |
|
81 | ||
82 | } |