source: josm/trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java@ 1523

Last change on this file since 1523 was 1369, checked in by stoecker, 15 years ago

close #2129

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7
8import javax.swing.filechooser.FileFilter;
9
10/**
11 * A file filter that filters after the extension. Also includes a list of file
12 * filters used in JOSM.
13 *
14 * @author imi
15 */
16public class ExtensionFileFilter extends FileFilter {
17 private final String extension;
18 private final String description;
19 public final String defaultExtension;
20
21 public static final int OSM = 0;
22 public static final int GPX = 1;
23 public static final int NMEA = 2;
24
25 public static ExtensionFileFilter[] filters = {
26 new ExtensionFileFilter("osm,xml", "osm", tr("OSM Server Files")+ " (*.osm *.xml)"),
27 new ExtensionFileFilter("gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)"),
28 new ExtensionFileFilter("nmea,nme,nma,txt", "nmea", tr("NMEA-0183 Files") + " (*.nmea *.nme *.nma *.txt)"),
29 };
30
31 /**
32 * Construct an extension file filter by giving the extension to check after.
33 *
34 */
35 public ExtensionFileFilter(String extension, String defExt, String description) {
36 this.extension = extension;
37 defaultExtension = defExt;
38 this.description = description;
39 }
40
41 public boolean acceptName(String filename) {
42 String name = filename.toLowerCase();
43 for (String ext : extension.split(","))
44 if (name.endsWith("."+ext))
45 return true;
46 return false;
47 }
48
49 @Override public boolean accept(File pathname) {
50 if (pathname.isDirectory())
51 return true;
52 return acceptName(pathname.getName());
53 }
54
55 @Override public String getDescription() {
56 return description;
57 }
58}
Note: See TracBrowser for help on using the repository browser.