svn-gvsig-desktop / tags / v1_0_RELEASE / libraries / libIverUtiles / src / com / iver / utiles / GenericFileFilter.java @ 9167
History | View | Annotate | Download (2.73 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.utiles; |
42 |
|
43 |
import java.io.File; |
44 |
|
45 |
import javax.swing.filechooser.FileFilter; |
46 |
|
47 |
|
48 |
/**
|
49 |
* Filtro de fichero gen?rico para los JFileChooser
|
50 |
*
|
51 |
* @author Fernando Gonz?lez Cort?s
|
52 |
*/
|
53 |
public class GenericFileFilter extends FileFilter { |
54 |
private String[] extensiones=new String[1]; |
55 |
private String description; |
56 |
private boolean dirs = true; |
57 |
|
58 |
/**
|
59 |
* Crea un nuevo GenericFileFilter.
|
60 |
*
|
61 |
* @param ext DOCUMENT ME!
|
62 |
* @param desc DOCUMENT ME!
|
63 |
*/
|
64 |
public GenericFileFilter(String[] ext, String desc) { |
65 |
extensiones = ext; |
66 |
description = desc; |
67 |
} |
68 |
/**
|
69 |
* Crea un nuevo GenericFileFilter.
|
70 |
*
|
71 |
* @param ext DOCUMENT ME!
|
72 |
* @param desc DOCUMENT ME!
|
73 |
*/
|
74 |
public GenericFileFilter(String ext, String desc) { |
75 |
extensiones[0] = ext;
|
76 |
description = desc; |
77 |
} |
78 |
|
79 |
/**
|
80 |
* Crea un nuevo GenericFileFilter.
|
81 |
*
|
82 |
* @param ext DOCUMENT ME!
|
83 |
* @param desc DOCUMENT ME!
|
84 |
* @param dirs DOCUMENT ME!
|
85 |
*/
|
86 |
public GenericFileFilter(String ext, String desc, boolean dirs) { |
87 |
extensiones[0] = ext;
|
88 |
description = desc; |
89 |
this.dirs = dirs;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
94 |
*/
|
95 |
public boolean accept(File f) { |
96 |
if (f.isDirectory()) {
|
97 |
if (dirs) {
|
98 |
return true; |
99 |
} else {
|
100 |
return false; |
101 |
} |
102 |
} |
103 |
boolean endsWith=false; |
104 |
for (int i=0;i<extensiones.length;i++){ |
105 |
if (f.getName().toUpperCase().endsWith(extensiones[i].toUpperCase())){
|
106 |
endsWith=true;
|
107 |
} |
108 |
} |
109 |
|
110 |
return endsWith;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
115 |
*/
|
116 |
public String getDescription() { |
117 |
return description;
|
118 |
} |
119 |
} |