Skip to content

Commit

Permalink
fix #15498 - Load folders containing pictures in separate layers if `…
Browse files Browse the repository at this point in the history
…geoimage.one-layer-per-folder` advanced property is set to true

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18248 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
don-vip committed Oct 5, 2021
1 parent 465413c commit b58516e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final Strin
* @since 18078
*/
public GeoImageLayer(final List<ImageEntry> data, GpxData gpxData, final String name, boolean useThumbs) {
super(name != null ? name : tr("Geotagged Images"));
super(!Utils.isBlank(name) ? name : tr("Geotagged Images"));
this.data = new ImageData(data);
this.gpxData = gpxData;
this.useThumbs = useThumbs;
Expand Down
21 changes: 16 additions & 5 deletions src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;

import javax.swing.JOptionPane;

import org.openstreetmap.josm.data.preferences.BooleanProperty;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.PleaseWaitRunnable;
import org.openstreetmap.josm.gui.io.importexport.ImageImporter;
Expand All @@ -33,12 +37,14 @@
final class ImagesLoader extends PleaseWaitRunnable {

private boolean canceled;
private GeoImageLayer layer;
private final List<GeoImageLayer> layers = new ArrayList<>();
private final Collection<File> selection;
private final Set<String> loadedDirectories = new HashSet<>();
private final Set<String> errorMessages;
private final GpxLayer gpxLayer;

private static final BooleanProperty PROP_ONE_LAYER_PER_FOLDER = new BooleanProperty("geoimage.one-layer-per-folder", false);

/**
* Constructs a new {@code ImagesLoader}.
* @param selection image files to load
Expand Down Expand Up @@ -72,7 +78,7 @@ protected void realRun() throws IOException {
progressMonitor.setTicksCount(files.size());

// read the image files
List<ImageEntry> entries = new ArrayList<>(files.size());
Map<String, List<ImageEntry>> entries = new TreeMap<>();

for (File f : files) {

Expand All @@ -85,9 +91,14 @@ protected void realRun() throws IOException {

ImageEntry e = new ImageEntry(f);
e.extractExif();
entries.add(e);
File parentFile = f.getParentFile();
entries.computeIfAbsent(parentFile != null ? parentFile.getName() : "", x -> new ArrayList<>()).add(e);
}
if (Boolean.TRUE.equals(PROP_ONE_LAYER_PER_FOLDER.get())) {
entries.entrySet().stream().map(e -> new GeoImageLayer(e.getValue(), gpxLayer, e.getKey())).forEach(layers::add);
} else {
layers.add(new GeoImageLayer(entries.values().stream().flatMap(List<ImageEntry>::stream).collect(Collectors.toList()), gpxLayer));
}
layer = new GeoImageLayer(entries, gpxLayer);
files.clear();
}

Expand Down Expand Up @@ -159,7 +170,7 @@ protected void finish() {
JOptionPane.ERROR_MESSAGE
);
}
if (layer != null) {
for (GeoImageLayer layer : layers) {
MainApplication.getLayerManager().addLayer(layer);

if (!canceled && !layer.getImageData().getImages().isEmpty()) {
Expand Down

0 comments on commit b58516e

Please sign in to comment.