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