1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.File;
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.LinkedList;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.actions.ExtensionFileFilter;
|
---|
13 | import org.openstreetmap.josm.gui.layer.GpxLayer;
|
---|
14 | import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
|
---|
15 |
|
---|
16 | public class JpgImporter extends FileImporter {
|
---|
17 | private GpxLayer gpx;
|
---|
18 |
|
---|
19 | public JpgImporter() {
|
---|
20 | super(new ExtensionFileFilter("jpg", "jpg", tr("Image Files") + " (*.jpg, "+ tr("folder")+")"));
|
---|
21 | }
|
---|
22 |
|
---|
23 | public JpgImporter(GpxLayer gpx) {
|
---|
24 | this();
|
---|
25 | this.gpx = gpx;
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public boolean acceptFile(File pathname) {
|
---|
30 | return super.acceptFile(pathname) || pathname.isDirectory();
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void importData(List<File> sel) throws IOException, IllegalDataException {
|
---|
35 | if (sel == null || sel.size() == 0)
|
---|
36 | return;
|
---|
37 | LinkedList<File> files = new LinkedList<File>();
|
---|
38 | addRecursiveFiles(files, sel);
|
---|
39 | GeoImageLayer.create(files, gpx);
|
---|
40 | }
|
---|
41 |
|
---|
42 | private void addRecursiveFiles(LinkedList<File> files, List<File> sel) {
|
---|
43 | for (File f : sel) {
|
---|
44 | if (f.isDirectory()) {
|
---|
45 | addRecursiveFiles(files, Arrays.asList(f.listFiles()));
|
---|
46 | } else if (f.getName().toLowerCase().endsWith(".jpg")) {
|
---|
47 | files.add(f);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public boolean isBatchImporter() {
|
---|
54 | return true;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Needs to be the last, to avoid problems.
|
---|
59 | */
|
---|
60 | @Override
|
---|
61 | public double getPriority() {
|
---|
62 | return -1000;
|
---|
63 | }
|
---|
64 | }
|
---|