| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.layer.geoimage;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.event.ActionEvent;
|
|---|
| 7 | import java.awt.event.ItemEvent;
|
|---|
| 8 | import java.awt.event.ItemListener;
|
|---|
| 9 | import java.awt.event.KeyEvent;
|
|---|
| 10 | import java.util.List;
|
|---|
| 11 | import java.util.Objects;
|
|---|
| 12 |
|
|---|
| 13 | import javax.swing.event.ChangeEvent;
|
|---|
| 14 | import javax.swing.event.ChangeListener;
|
|---|
| 15 |
|
|---|
| 16 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 17 | import org.openstreetmap.josm.data.gpx.GpxImageCorrelation;
|
|---|
| 18 | import org.openstreetmap.josm.data.gpx.GpxImageCorrelationSettings;
|
|---|
| 19 | import org.openstreetmap.josm.data.gpx.TimeSource;
|
|---|
| 20 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
|---|
| 21 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 22 | import org.openstreetmap.josm.gui.layer.geoimage.CorrelateGpxWithImages.RepaintTheMapListener;
|
|---|
| 23 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 24 |
|
|---|
| 25 | /**
|
|---|
| 26 | * Edit a sequence of geo-located images.
|
|---|
| 27 | * @since 18065
|
|---|
| 28 | */
|
|---|
| 29 | public class EditImagesSequenceAction extends JosmAction {
|
|---|
| 30 |
|
|---|
| 31 | private final transient GeoImageLayer yLayer;
|
|---|
| 32 | private final ImageDirectionPositionPanel pDirectionPosition;
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * Constructs a new {@code EditImagesSequenceAction}.
|
|---|
| 36 | * @param layer The image layer
|
|---|
| 37 | */
|
|---|
| 38 | public EditImagesSequenceAction(GeoImageLayer layer) {
|
|---|
| 39 | super(tr("Edit images sequence"), "dialogs/geoimage/gpx2img", "geoimage_editsequence",
|
|---|
| 40 | Shortcut.registerShortcut("geoimage:editsequence", tr("Edit images sequence"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
|
|---|
| 41 | false);
|
|---|
| 42 | this.yLayer = Objects.requireNonNull(layer);
|
|---|
| 43 | this.pDirectionPosition = ImageDirectionPositionPanel.forImageSequence();
|
|---|
| 44 |
|
|---|
| 45 | Updater updater = new Updater();
|
|---|
| 46 | pDirectionPosition.addFocusListenerOnComponent(new RepaintTheMapListener(yLayer));
|
|---|
| 47 | pDirectionPosition.addChangeListenerOnComponents(updater);
|
|---|
| 48 | pDirectionPosition.addItemListenerOnComponents(updater);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | @Override
|
|---|
| 52 | public void actionPerformed(ActionEvent e) {
|
|---|
| 53 | ExtendedDialog ed = new ExtendedDialog(
|
|---|
| 54 | MainApplication.getMainFrame(), tr("Edit images sequence"), tr("Apply"), tr("Cancel"))
|
|---|
| 55 | .setContent(pDirectionPosition).setButtonIcons("ok", "cancel");
|
|---|
| 56 | ed.setResizable(false);
|
|---|
| 57 | if (ed.showDialog().getValue() == 1) {
|
|---|
| 58 | yLayer.applyTmp();
|
|---|
| 59 | } else {
|
|---|
| 60 | yLayer.discardTmp();
|
|---|
| 61 | }
|
|---|
| 62 | yLayer.updateBufferAndRepaint();
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | class Updater implements ChangeListener, ItemListener {
|
|---|
| 66 |
|
|---|
| 67 | @Override
|
|---|
| 68 | public void stateChanged(ChangeEvent e) {
|
|---|
| 69 | matchAndUpdate();
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | @Override
|
|---|
| 73 | public void itemStateChanged(ItemEvent e) {
|
|---|
| 74 | matchAndUpdate();
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void matchAndUpdate() {
|
|---|
| 78 | // The selection of images we are about to correlate may have changed.
|
|---|
| 79 | // So reset all images.
|
|---|
| 80 | yLayer.discardTmp();
|
|---|
| 81 | // Construct a list of images that have a date, and sort them on the date.
|
|---|
| 82 | List<ImageEntry> dateImgLst = yLayer.getSortedImgList(true, true, TimeSource.EXIFCAMTIME);
|
|---|
| 83 | // Create a temporary copy for each image
|
|---|
| 84 | dateImgLst.forEach(ie -> ie.createTmp().unflagNewGpsData());
|
|---|
| 85 | GpxImageCorrelation.matchGpxTrack(dateImgLst, yLayer.getFauxGpxData(),
|
|---|
| 86 | new GpxImageCorrelationSettings(0, false, TimeSource.EXIFCAMTIME, pDirectionPosition.getSettings()));
|
|---|
| 87 | yLayer.updateBufferAndRepaint();
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|