Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * Demetrix process modelling system | |
3 | * | |
4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
5 | * | |
6 | * This file is part of Demetrix. | |
7 | * | |
8 | * Demetrix is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2.1 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * Demetrix 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 | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with Demetrix; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | * For further information you may | |
23 | * | |
24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
25 | * - look at http://sourceforge.net/projects/demetrix/ | |
26 | * - look at http://demetrix.sourceforge.net/ | |
27 | * - look at http://members.inode.at/d.pissarenko/ | |
28 | * | |
29 | *****************************************************************************/ | |
30 | package net.sourceforge.demetrix.util; | |
31 | import java.io.File; | |
32 | import javax.swing.filechooser.FileFilter; | |
33 | public class SimpleFileFilter extends FileFilter { | |
34 | 7 | private boolean acceptDirectoriesOnly = false; |
35 | 7 | private boolean acceptFilesOnly = false; |
36 | 7 | private String description = ""; |
37 | 7 | private String extension = ""; |
38 | public SimpleFileFilter() { | |
39 | 3 | super(); |
40 | 3 | } |
41 | public SimpleFileFilter(String desc, String ext) { | |
42 | 4 | super(); |
43 | 4 | this.description = desc; |
44 | 4 | this.extension = ext; |
45 | 4 | } |
46 | public boolean accept(File file) { | |
47 | 160 | boolean extensionCorrect = false; |
48 | 160 | if (file |
49 | .getAbsolutePath() | |
50 | .toUpperCase() | |
51 | .endsWith(extension.toUpperCase())) { | |
52 | 2 | extensionCorrect = true; |
53 | } | |
54 | 160 | if (!acceptDirectoriesOnly && !acceptFilesOnly && extensionCorrect) { |
55 | 0 | return true; |
56 | 160 | } else if (acceptFilesOnly && file.isFile() && extensionCorrect) |
57 | { | |
58 | 1 | return true; |
59 | } | |
60 | 159 | else if (acceptDirectoriesOnly && file.isDirectory()) |
61 | { | |
62 | 1 | return true; |
63 | } | |
64 | else | |
65 | { | |
66 | 158 | return false; |
67 | } | |
68 | ||
69 | } | |
70 | public void setAcceptDirectoriesOnly(boolean ado) { | |
71 | 12 | this.acceptDirectoriesOnly = ado; |
72 | 12 | } |
73 | public String getDescription() { | |
74 | 57 | return this.description; |
75 | } | |
76 | public String getExtension() { | |
77 | 50 | return extension; |
78 | } | |
79 | public boolean isAcceptDirectoriesOnly() { | |
80 | 4 | return this.acceptDirectoriesOnly; |
81 | } | |
82 | public void setDescription(String description) { | |
83 | 5 | this.description = description; |
84 | 5 | } |
85 | public void setExtension(String ext) { | |
86 | 6 | this.extension = ext; |
87 | 6 | } |
88 | /* (non-Javadoc) | |
89 | * @see java.lang.Object#equals(java.lang.Object) | |
90 | */ | |
91 | public boolean equals(Object otherObject) { | |
92 | 30 | SimpleFileFilter otherFilter = null; |
93 | 30 | if (otherObject == null) { |
94 | 1 | return false; |
95 | } | |
96 | 29 | if (otherObject instanceof SimpleFileFilter) { |
97 | 25 | otherFilter = (SimpleFileFilter) otherObject; |
98 | 25 | if (ObjectComparator |
99 | .areEqual(this.getDescription(), otherFilter.getDescription()) | |
100 | && ObjectComparator.areEqual( | |
101 | this.getExtension(), | |
102 | otherFilter.getExtension()) | |
103 | && (this.acceptDirectoriesOnly | |
104 | == otherFilter.acceptDirectoriesOnly)) { | |
105 | 19 | return true; |
106 | } else { | |
107 | 6 | return false; |
108 | } | |
109 | } else { | |
110 | 4 | return false; |
111 | } | |
112 | } | |
113 | /** | |
114 | * @return | |
115 | */ | |
116 | public boolean isAcceptFilesOnly() { | |
117 | 2 | return acceptFilesOnly; |
118 | } | |
119 | /** | |
120 | * @param b | |
121 | */ | |
122 | public void setAcceptFilesOnly(boolean b) { | |
123 | 7 | acceptFilesOnly = b; |
124 | 7 | } |
125 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |