1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import java.io.File;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Arrays;
|
---|
7 |
|
---|
8 | import javax.swing.filechooser.FileFilter;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.io.FileImporter;
|
---|
11 | import org.openstreetmap.josm.io.GpxImporter;
|
---|
12 | import org.openstreetmap.josm.io.NMEAImporter;
|
---|
13 | import org.openstreetmap.josm.io.OsmBzip2Importer;
|
---|
14 | import org.openstreetmap.josm.io.OsmGzipImporter;
|
---|
15 | import org.openstreetmap.josm.io.OsmImporter;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * A file filter that filters after the extension. Also includes a list of file
|
---|
19 | * filters used in JOSM.
|
---|
20 | *
|
---|
21 | * @author imi
|
---|
22 | */
|
---|
23 | public class ExtensionFileFilter extends FileFilter {
|
---|
24 | private final String extension;
|
---|
25 | private final String description;
|
---|
26 | public final String defaultExtension;
|
---|
27 |
|
---|
28 | public static ArrayList<FileImporter> importers = new ArrayList<FileImporter>(Arrays.asList(new OsmImporter(),
|
---|
29 | new OsmGzipImporter(), new OsmBzip2Importer(), new GpxImporter(), new NMEAImporter()));
|
---|
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 | }
|
---|