Changeset 19123 in josm for trunk


Ignore:
Timestamp:
2024-06-22T07:44:47+02:00 (10 months ago)
Author:
GerdP
Message:

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.
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java

    r19122 r19123  
    77import static org.openstreetmap.josm.tools.I18n.trn;
    88
     9import java.awt.GraphicsEnvironment;
    910import java.awt.event.ActionEvent;
    1011import java.awt.event.KeyEvent;
     
    4344import org.openstreetmap.josm.gui.io.importexport.FileImporter;
    4445import org.openstreetmap.josm.gui.io.importexport.Options;
     46import org.openstreetmap.josm.gui.layer.Layer;
     47import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
    4548import org.openstreetmap.josm.gui.util.GuiHelper;
    4649import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
     
    274277        protected void realRun() throws SAXException, IOException, OsmTransferException {
    275278            if (Utils.isEmpty(files)) return;
     279            List<Layer> oldLayers = MainApplication.getLayerManager().getLayers();
    276280
    277281            /*
     
    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
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r19080 r19123  
    6565import org.openstreetmap.josm.gui.layer.Layer;
    6666import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    67 import org.openstreetmap.josm.gui.util.GuiHelper;
    6867import org.openstreetmap.josm.gui.util.imagery.Vector3D;
    6968import org.openstreetmap.josm.tools.ImageProvider;
     
    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
     
    518504        }
    519505
    520         final IImageEntry<?> currentImage = ImageViewerDialog.getCurrentImage();
    521506        for (ImageEntry e: data.getSelectedImages()) {
    522507            if (e != null && e.getPos() != null) {
     
    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,
     
    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
     
    925913    public void jumpToPreviousMarker() {
    926914        data.setSelectedImage(data.getPreviousImage());
     915        if (data.getSelectedImage() != null)
     916            ImageViewerDialog.getInstance().displayImages(Collections.singletonList(data.getSelectedImage()));
    927917    }
    928918
Note: See TracChangeset for help on using the changeset viewer.