Skip to content

Commit f0f3e59

Browse files
GerdPGerdP
authored andcommitted
fix #23728: First geotagged image not fully selected
- remove code in GeoImageLayer constructor which more or less randomly opens the ImageViewerDialog - fix layer actions "Jump to next marker" and "Jump to previous marker" so that they open or update the image viewer dialog - new code to check if a new geoimage layer was added by any open file or drag/drop action and - if so - to open the first image of the topmost new geoimage layer. If ImageViewerDialog is already open a new tab is added. git-svn-id: https://josm.openstreetmap.de/svn/trunk@19123 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent da7de91 commit f0f3e59

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

src/org/openstreetmap/josm/actions/OpenFileAction.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.openstreetmap.josm.tools.I18n.tr;
77
import static org.openstreetmap.josm.tools.I18n.trn;
88

9+
import java.awt.GraphicsEnvironment;
910
import java.awt.event.ActionEvent;
1011
import java.awt.event.KeyEvent;
1112
import java.io.BufferedReader;
@@ -42,6 +43,8 @@
4243
import org.openstreetmap.josm.gui.io.importexport.AllFormatsImporter;
4344
import org.openstreetmap.josm.gui.io.importexport.FileImporter;
4445
import org.openstreetmap.josm.gui.io.importexport.Options;
46+
import org.openstreetmap.josm.gui.layer.Layer;
47+
import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
4548
import org.openstreetmap.josm.gui.util.GuiHelper;
4649
import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
4750
import org.openstreetmap.josm.gui.widgets.FileChooserManager;
@@ -273,6 +276,7 @@ protected void alertFilesWithUnknownImporter(Collection<File> files) {
273276
@Override
274277
protected void realRun() throws SAXException, IOException, OsmTransferException {
275278
if (Utils.isEmpty(files)) return;
279+
List<Layer> oldLayers = MainApplication.getLayerManager().getLayers();
276280

277281
/*
278282
* Find the importer with the chosen file filter
@@ -377,6 +381,27 @@ protected void realRun() throws SAXException, IOException, OsmTransferException
377381
int maxsize = Math.max(0, Config.getPref().getInt("file-open.history.max-size", 15));
378382
PreferencesUtils.putListBounded(Config.getPref(), "file-open.history", maxsize, new ArrayList<>(fileHistory));
379383
}
384+
if (!canceled && !GraphicsEnvironment.isHeadless()) {
385+
checkNewLayers(oldLayers);
386+
}
387+
}
388+
389+
private static void checkNewLayers(List<Layer> oldLayers) {
390+
// We do have to wrap the EDT call in a worker call, since layers may be created in the EDT.
391+
// And the layer(s) must be added to the layer list in order for the dialog to work properly.
392+
MainApplication.worker.execute(() -> GuiHelper.runInEDT(() -> {
393+
List<Layer> newLayers = MainApplication.getLayerManager().getLayers();
394+
// see #23728: open first image of topmost new image layer
395+
for (Layer l : newLayers) {
396+
if (oldLayers.contains(l))
397+
return;
398+
if (l instanceof GeoImageLayer) {
399+
GeoImageLayer imageLayer = (GeoImageLayer) l;
400+
imageLayer.jumpToNextMarker();
401+
return;
402+
}
403+
}
404+
}));
380405
}
381406

382407
/**

src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker;
6565
import org.openstreetmap.josm.gui.layer.Layer;
6666
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
67-
import org.openstreetmap.josm.gui.util.GuiHelper;
6867
import org.openstreetmap.josm.gui.util.imagery.Vector3D;
6968
import org.openstreetmap.josm.tools.ImageProvider;
7069
import org.openstreetmap.josm.tools.ListenerList;
@@ -191,19 +190,6 @@ public GeoImageLayer(final List<ImageEntry> data, GpxData gpxData, final String
191190
this.useThumbs = useThumbs;
192191
this.data.addImageDataUpdateListener(this);
193192
this.data.setLayer(this);
194-
if (!ImageViewerDialog.hasInstance()) {
195-
GuiHelper.runInEDTAndWait(() -> {
196-
if (!ImageViewerDialog.hasInstance()) {
197-
ImageViewerDialog.createInstance();
198-
}
199-
});
200-
}
201-
if (getInvalidGeoImages().size() == data.size()) {
202-
this.data.setSelectedImage(this.data.getFirstImage());
203-
// We do have to wrap the EDT call in a worker call, since layers may be created in the EDT.
204-
// And the layer must be added to the layer list in order for the dialog to work properly.
205-
MainApplication.worker.execute(() -> GuiHelper.runInEDT(() -> ImageViewerDialog.getInstance().displayImages(this.getSelection())));
206-
}
207193
}
208194

209195
private final class ImageMouseListener extends MouseAdapter {
@@ -517,7 +503,6 @@ public void paint(Graphics2D g, MapView mv, Bounds bounds) {
517503
}
518504
}
519505

520-
final IImageEntry<?> currentImage = ImageViewerDialog.getCurrentImage();
521506
for (ImageEntry e: data.getSelectedImages()) {
522507
if (e != null && e.getPos() != null) {
523508
Point p = mv.getPoint(e.getPos());
@@ -532,7 +517,7 @@ public void paint(Graphics2D g, MapView mv, Bounds bounds) {
532517
if (useThumbs && e.hasThumbnail()) {
533518
g.setColor(new Color(128, 0, 0, 122));
534519
g.fillRect(p.x - imgDim.width / 2, p.y - imgDim.height / 2, imgDim.width, imgDim.height);
535-
} else if (e.equals(currentImage)) {
520+
} else if (e.equals(ImageViewerDialog.getCurrentImage())) {
536521
selectedIcon.paintIcon(mv, g,
537522
p.x - imgDim.width / 2,
538523
p.y - imgDim.height / 2);
@@ -919,11 +904,16 @@ public synchronized GpxData getFauxGpxData() {
919904
@Override
920905
public void jumpToNextMarker() {
921906
data.setSelectedImage(data.getNextImage());
907+
if (data.getSelectedImage() != null)
908+
ImageViewerDialog.getInstance().displayImages(Collections.singletonList(data.getSelectedImage()));
909+
922910
}
923911

924912
@Override
925913
public void jumpToPreviousMarker() {
926914
data.setSelectedImage(data.getPreviousImage());
915+
if (data.getSelectedImage() != null)
916+
ImageViewerDialog.getInstance().displayImages(Collections.singletonList(data.getSelectedImage()));
927917
}
928918

929919
/**

0 commit comments

Comments
 (0)