svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / GenericFileFilter.java @ 40561
History | View | Annotate | Download (2.48 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.utils; |
25 |
|
26 |
import java.io.File; |
27 |
|
28 |
import javax.swing.filechooser.FileFilter; |
29 |
|
30 |
|
31 |
/**
|
32 |
* Filtro de fichero gen?rico para los JFileChooser
|
33 |
*
|
34 |
* @author Fernando Gonz?lez Cort?s
|
35 |
*/
|
36 |
public class GenericFileFilter extends FileFilter { |
37 |
private String[] extensiones=new String[1]; |
38 |
private String description; |
39 |
private boolean dirs = true; |
40 |
|
41 |
/**
|
42 |
* Crea un nuevo GenericFileFilter.
|
43 |
*
|
44 |
* @param ext DOCUMENT ME!
|
45 |
* @param desc DOCUMENT ME!
|
46 |
*/
|
47 |
public GenericFileFilter(String[] ext, String desc) { |
48 |
extensiones = ext; |
49 |
description = desc; |
50 |
} |
51 |
/**
|
52 |
* Crea un nuevo GenericFileFilter.
|
53 |
*
|
54 |
* @param ext DOCUMENT ME!
|
55 |
* @param desc DOCUMENT ME!
|
56 |
*/
|
57 |
public GenericFileFilter(String ext, String desc) { |
58 |
extensiones[0] = ext;
|
59 |
description = desc; |
60 |
} |
61 |
|
62 |
/**
|
63 |
* Crea un nuevo GenericFileFilter.
|
64 |
*
|
65 |
* @param ext DOCUMENT ME!
|
66 |
* @param desc DOCUMENT ME!
|
67 |
* @param dirs DOCUMENT ME!
|
68 |
*/
|
69 |
public GenericFileFilter(String ext, String desc, boolean dirs) { |
70 |
extensiones[0] = ext;
|
71 |
description = desc; |
72 |
this.dirs = dirs;
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
77 |
*/
|
78 |
public boolean accept(File f) { |
79 |
if (f.isDirectory()) {
|
80 |
if (dirs) {
|
81 |
return true; |
82 |
} else {
|
83 |
return false; |
84 |
} |
85 |
} |
86 |
boolean endsWith=false; |
87 |
for (int i=0;i<extensiones.length;i++){ |
88 |
if (f.getName().toUpperCase().endsWith(extensiones[i].toUpperCase())){
|
89 |
endsWith=true;
|
90 |
} |
91 |
} |
92 |
|
93 |
return endsWith;
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
98 |
*/
|
99 |
public String getDescription() { |
100 |
return description;
|
101 |
} |
102 |
} |