Skip to content

Commit 387f089

Browse files
committed
Update to JOSM r18613
Signed-off-by: Taylor Smock <tsmock@meta.com>
1 parent 8d94846 commit 387f089

File tree

13 files changed

+107
-67
lines changed

13 files changed

+107
-67
lines changed

.github/workflows/ant-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ jobs:
88
call-workflow:
99
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
1010
with:
11-
josm-revision: "r18531"
11+
josm-revision: "r18613"
1212

1313

.github/workflows/ant.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
call-workflow:
1919
strategy:
2020
matrix:
21-
josm-revision: ["", "r18531"]
21+
josm-revision: ["", "r18613"]
2222
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
2323
with:
2424
josm-revision: ${{ matrix.josm-revision }}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ josm {
178178
debugPort = 7051
179179
manifest {
180180
// See https://floscher.gitlab.io/gradle-josm-plugin/kdoc/latest/gradle-josm-plugin/org.openstreetmap.josm.gradle.plugin.config/-josm-manifest/old-version-download-link.html
181+
oldVersionDownloadLink(18531, "v2.0.2", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.2/Mapillary.jar"));
181182
oldVersionDownloadLink(17903, "v2.0.0-alpha.36", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.0-alpha.36/Mapillary.jar"))
182183
}
183184
i18n {

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ plugin.icon=images/mapillary-logo.svg
66
plugin.link=https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Mapillary
77
# Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible.
88
# You can check if the plugin compiles against this version by executing `./gradlew compileJava_minJosm`.
9-
plugin.main.version=18291
9+
plugin.main.version=18613
1010
# Version of JOSM against which the plugin is compiled
1111
# Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ .
1212
# If not, choose the next higher number that is available, or the gradle build will break.
13-
plugin.compile.version=18531
13+
plugin.compile.version=18613
1414
# The datepicker plugin is currently in the source tree. TODO fix
1515
plugin.requires=apache-commons
1616

src/main/java/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.awt.Component;
55
import java.util.ArrayList;
66
import java.util.Arrays;
7-
import java.util.Collections;
87
import java.util.List;
98

109
import javax.swing.JMenu;
@@ -17,8 +16,6 @@
1716
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
1817
import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
1918
import org.openstreetmap.josm.gui.layer.Layer;
20-
import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
21-
import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;
2219
import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
2320
import org.openstreetmap.josm.io.remotecontrol.RequestProcessor;
2421
import org.openstreetmap.josm.plugins.Plugin;
@@ -156,7 +153,6 @@ public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
156153

157154
this.dataMouseListener = new DataMouseListener();
158155
this.destroyables.add(this.dataMouseListener);
159-
ensureImageViewerDialogEnabled(newFrame);
160156
} else if (oldFrame != null && newFrame == null) { // map frame removed
161157
if (this.dataMouseListener != null) {
162158
this.destroyables.remove(this.dataMouseListener);
@@ -173,20 +169,6 @@ public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
173169
}
174170
}
175171

176-
/**
177-
* Ensure that the image viewer dialog is created
178-
*
179-
* @param map The mapframe that should have the ImageViewerDialog
180-
*/
181-
private static void ensureImageViewerDialogEnabled(MapFrame map) {
182-
if (map != null && map.getToggleDialog(ImageViewerDialog.class) == null) {
183-
// GeoImageLayer should do all the setup when hookUpMapView is called.
184-
final GeoImageLayer geoImageLayer = new GeoImageLayer(Collections.emptyList(), null);
185-
geoImageLayer.hookUpMapView();
186-
geoImageLayer.destroy();
187-
}
188-
}
189-
190172
@Override
191173
public PreferenceSetting getPreferenceSetting() {
192174
return new MapillaryPreferenceSetting();

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/ImageNavigationDialog.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
import java.awt.event.KeyEvent;
99
import java.awt.event.MouseEvent;
1010
import java.util.Collections;
11+
import java.util.List;
1112
import java.util.Objects;
12-
import java.util.function.BiConsumer;
1313

1414
import javax.swing.JComponent;
1515
import javax.swing.JLabel;
1616
import javax.swing.JPanel;
1717
import javax.swing.event.MouseInputAdapter;
1818

1919
import org.openstreetmap.josm.actions.JosmAction;
20+
import org.openstreetmap.josm.data.imagery.street_level.IImageEntry;
2021
import org.openstreetmap.josm.data.osm.INode;
2122
import org.openstreetmap.josm.data.osm.PrimitiveId;
2223
import org.openstreetmap.josm.data.vector.VectorDataSet;
2324
import org.openstreetmap.josm.gui.MainApplication;
2425
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
2526
import org.openstreetmap.josm.gui.layer.LayerManager;
27+
import org.openstreetmap.josm.gui.layer.geoimage.IGeoImageLayer;
2628
import org.openstreetmap.josm.gui.util.GuiHelper;
2729
import org.openstreetmap.josm.plugins.mapillary.data.mapillary.ImageNavigation;
2830
import org.openstreetmap.josm.plugins.mapillary.data.mapillary.MapillaryNode;
@@ -34,7 +36,7 @@
3436
* Create a new image navigation dialog
3537
*/
3638
public class ImageNavigationDialog extends ToggleDialog
37-
implements LayerManager.LayerChangeListener, BiConsumer<MapillaryLayer, MapillaryNode> {
39+
implements LayerManager.LayerChangeListener, IGeoImageLayer.ImageChangeListener {
3840
private static final Shortcut FORWARD = Shortcut.registerShortcut("mapillary:image_navigation:forward",
3941
tr("Mapillary: Image Navigation: Forward"), Shortcut.NONE, KeyEvent.CHAR_UNDEFINED);
4042
private static final Shortcut LEFT = Shortcut.registerShortcut("mapillary:image_navigation:left",
@@ -84,9 +86,17 @@ public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e) {
8486
}
8587

8688
@Override
87-
public void accept(MapillaryLayer layer, MapillaryNode node) {
88-
if (node != null && layer != null && layer.getData() != null && node.getSequence() != null) {
89-
this.imageNavigation = new ImageNavigation(layer.getData(), node);
89+
public void imageChanged(IGeoImageLayer source, List<? extends IImageEntry<?>> oldImages,
90+
List<? extends IImageEntry<?>> newImages) {
91+
if (source instanceof MapillaryLayer
92+
&& newImages.stream().filter(MapillaryNode.class::isInstance).count() == 1) {
93+
MapillaryLayer layer = (MapillaryLayer) source;
94+
MapillaryNode node = (MapillaryNode) newImages.get(0);
95+
if (node != null && layer.getData() != null && node.getSequence() != null) {
96+
this.imageNavigation = new ImageNavigation(layer.getData(), node);
97+
} else {
98+
this.imageNavigation = null;
99+
}
90100
} else {
91101
this.imageNavigation = null;
92102
}

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/OldVersionDialog.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// License: GPL. For details, see LICENSE file.
12
package org.openstreetmap.josm.plugins.mapillary.gui.dialog;
23

34
import static org.openstreetmap.josm.tools.I18n.tr;
45

56
import java.io.IOException;
67
import java.nio.charset.StandardCharsets;
78
import java.util.Objects;
9+
import java.util.Optional;
810

911
import javax.annotation.Nullable;
1012
import javax.json.Json;
@@ -74,7 +76,8 @@ static String latestMapillaryVersion() {
7476
latestMapillary.setMaxAge(60L * 15); // 15 minutes
7577
final JsonValue value = reader.read();
7678
final JsonObject object = value.asJsonObject();
77-
return object.getString("tag_name", null);
79+
return Optional.ofNullable(object.getString("tag_name", null)).map(s -> s.replaceFirst("^v", ""))
80+
.orElse(null);
7881
} catch (IOException | JsonException | IllegalStateException e) {
7982
Logging.error(e);
8083
}

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/layer/MapillaryLayer.java

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.awt.Color;
77
import java.awt.Composite;
88
import java.awt.Graphics2D;
9+
import java.awt.GraphicsEnvironment;
910
import java.awt.Image;
1011
import java.awt.Point;
1112
import java.awt.RenderingHints;
@@ -30,7 +31,6 @@
3031
import java.util.concurrent.TimeUnit;
3132
import java.util.concurrent.atomic.AtomicReference;
3233
import java.util.concurrent.locks.Lock;
33-
import java.util.function.BiConsumer;
3434
import java.util.stream.Collectors;
3535
import java.util.stream.Stream;
3636

@@ -73,6 +73,7 @@
7373
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
7474
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
7575
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
76+
import org.openstreetmap.josm.gui.layer.geoimage.IGeoImageLayer;
7677
import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;
7778
import org.openstreetmap.josm.gui.layer.imagery.MVTLayer;
7879
import org.openstreetmap.josm.gui.mappaint.Range;
@@ -96,7 +97,6 @@
9697
import org.openstreetmap.josm.plugins.mapillary.utils.MapillarySequenceUtils;
9798
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
9899
import org.openstreetmap.josm.plugins.mapillary.utils.OffsetUtils;
99-
import org.openstreetmap.josm.plugins.mapillary.utils.ReflectionUtils;
100100
import org.openstreetmap.josm.tools.ColorHelper;
101101
import org.openstreetmap.josm.tools.Geometry;
102102
import org.openstreetmap.josm.tools.I18n;
@@ -113,8 +113,9 @@
113113
*
114114
* @author nokutu
115115
*/
116-
public final class MapillaryLayer extends MVTLayer implements ActiveLayerChangeListener, LayerChangeListener,
117-
UploadHook, VectorDataSelectionListener, AbstractProperty.ValueChangeListener<Boolean>, HighlightUpdateListener {
116+
public final class MapillaryLayer extends MVTLayer
117+
implements ActiveLayerChangeListener, LayerChangeListener, UploadHook, VectorDataSelectionListener,
118+
AbstractProperty.ValueChangeListener<Boolean>, HighlightUpdateListener, IGeoImageLayer {
118119

119120
/** The radius of the image marker */
120121
private static final int IMG_MARKER_RADIUS = 7;
@@ -159,7 +160,7 @@ public final class MapillaryLayer extends MVTLayer implements ActiveLayerChangeL
159160
MapillaryProperties.UNSELECTED_OPACITY.get().floatValue());
160161
private static Point2D standardImageCentroid;
161162
private final ListenerList<MVTTile.TileListener> tileListeners = ListenerList.create();
162-
private final ListenerList<BiConsumer<MapillaryLayer, MapillaryNode>> imageChangeListeners = ListenerList.create();
163+
private final ListenerList<IGeoImageLayer.ImageChangeListener> imageChangeListeners = ListenerList.create();
163164
private MapillaryNode image;
164165
private boolean colorByCaptureDate;
165166

@@ -176,6 +177,9 @@ private MapillaryLayer() {
176177
this.getData().addHighlightUpdateListener(this);
177178
this.colorByCaptureDate = MapillaryProperties.COLOR_BY_CAPTURE_DATE.get();
178179
MapillaryProperties.COLOR_BY_CAPTURE_DATE.addListener(this);
180+
if (!GraphicsEnvironment.isHeadless() && !ImageViewerDialog.hasInstance()) {
181+
ImageViewerDialog.getInstance();
182+
}
179183
}
180184

181185
/**
@@ -732,32 +736,31 @@ public void setCurrentImage(final MapillaryNode image) {
732736
}
733737
this.image = image;
734738
this.invalidate();
735-
if (ReflectionUtils.hasImageViewerDialog()) {
739+
if (ImageViewerDialog.hasInstance()) {
736740
if (image == null) {
737741
GuiHelper.runInEDT(() -> ImageViewerDialog.getInstance().displayImage(null));
738742
} else {
739743
MapillaryImageEntry entry = MapillaryImageEntry.getCachedEntry(image);
740744
if (Objects.equals(entry, ImageViewerDialog.getCurrentImage())) {
741745
entry.reload();
742746
} else {
747+
IImageEntry<?> old = ImageViewerDialog.getCurrentImage();
743748
GuiHelper.runInEDT(() -> ImageViewerDialog.getInstance().displayImage(entry));
749+
MainApplication.worker.execute(() -> this.imageChangeListeners.fireEvent(f -> f.imageChanged(this,
750+
old instanceof MapillaryImageEntry ? Collections.singletonList(old) : Collections.emptyList(),
751+
Collections.singletonList(entry))));
744752
}
745753
}
746754
}
747-
MainApplication.worker.execute(() -> this.imageChangeListeners.fireEvent(f -> f.accept(this, image)));
748-
}
749-
750-
public MapillaryNode getImage() {
751-
return this.image;
752755
}
753756

754757
/**
755-
* Add an image change listener
758+
* Get the currently visible image
756759
*
757-
* @param listener The listener to notify of image changes
760+
* @return The image node
758761
*/
759-
public void addImageChangeListener(BiConsumer<MapillaryLayer, MapillaryNode> listener) {
760-
this.imageChangeListeners.addWeakListener(listener);
762+
public MapillaryNode getImage() {
763+
return this.image;
761764
}
762765

763766
@Override
@@ -766,8 +769,7 @@ public void selectionChanged(
766769
final Collection<VectorNode> nodes = Utils.filteredCollection(event.getSelection(), VectorNode.class);
767770
if (nodes.size() == 1) {
768771
final VectorNode node = nodes.iterator().next();
769-
final IImageEntry<?> displayImage = ReflectionUtils.hasImageViewerDialog()
770-
? ImageViewerDialog.getCurrentImage()
772+
final IImageEntry<?> displayImage = ImageViewerDialog.hasInstance() ? ImageViewerDialog.getCurrentImage()
771773
: null;
772774
final MapillaryNode currentImage = this.image;
773775
if (currentImage != null && displayImage instanceof MapillaryImageEntry
@@ -818,4 +820,44 @@ public void valueChanged(AbstractProperty.ValueChangeEvent<? extends Boolean> e)
818820
this.colorByCaptureDate = MapillaryProperties.COLOR_BY_CAPTURE_DATE.get();
819821
}
820822
}
823+
824+
@Override
825+
public void clearSelection() {
826+
this.setCurrentImage(null);
827+
}
828+
829+
@Override
830+
public List<? extends IImageEntry<?>> getSelection() {
831+
if (this.image instanceof IImageEntry) {
832+
return Collections.singletonList((IImageEntry<?>) this.image);
833+
} else if (this.image != null) {
834+
return Collections.singletonList(MapillaryImageEntry.getCachedEntry(this.image));
835+
}
836+
return Collections.emptyList();
837+
}
838+
839+
@Override
840+
public boolean containsImage(IImageEntry<?> imageEntry) {
841+
if (!(imageEntry instanceof MapillaryImageEntry)) {
842+
return false;
843+
}
844+
MapillaryImageEntry entry = (MapillaryImageEntry) imageEntry;
845+
if (Objects.equals(entry.getImage(), this.image)) {
846+
return true;
847+
}
848+
if (entry.getImage() instanceof VectorNode) {
849+
return this.getData().containsNode((VectorNode) entry.getImage());
850+
}
851+
return this.getData().getPrimitiveById(entry.getImage().getPrimitiveId()) != null;
852+
}
853+
854+
@Override
855+
public void addImageChangeListener(ImageChangeListener listener) {
856+
this.imageChangeListeners.addListener(listener);
857+
}
858+
859+
@Override
860+
public void removeImageChangeListener(ImageChangeListener listener) {
861+
this.imageChangeListeners.removeListener(listener);
862+
}
821863
}

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/layer/PointObjectLayer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryKeys;
9696
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryMapFeatureUtils;
9797
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryProperties;
98-
import org.openstreetmap.josm.plugins.mapillary.utils.ReflectionUtils;
9998
import org.openstreetmap.josm.tools.GBC;
10099
import org.openstreetmap.josm.tools.ImageProvider;
101100
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
@@ -308,7 +307,7 @@ private void paintAdditionalPanel(VectorPrimitive mapillaryObject, final MapView
308307
removeButton.setToolTipText(removeAction.getToolTip());
309308
addButton.setAction(addAction);
310309
removeButton.setAction(removeAction);
311-
displayedPanel = new AdditionalActionPanel(addButton/*, removeButton*/);
310+
displayedPanel = new AdditionalActionPanel(addButton/* , removeButton */);
312311
pTooltip = fixPanelSizeAndLocation(mv, displayedPanel, xl, xr, yt, yb);
313312
displayedWindow.setAutoRequestFocus(false);
314313
displayedWindow.add(displayedPanel);
@@ -457,8 +456,8 @@ public synchronized void destroy() {
457456
super.destroy();
458457
MainApplication.getMap().filterDialog.getFilterModel().removeTableModelListener(tableModelListener);
459458
List<? extends PointObjectLayer> layers = MainApplication.getLayerManager().getLayersOfType(this.getClass());
460-
if ((layers.isEmpty() || (layers.size() == 1 && this.equals(layers.get(0)))) &&
461-
MapPaintStyles.getStyles().getStyleSources().contains(mapcss)) {
459+
if ((layers.isEmpty() || (layers.size() == 1 && this.equals(layers.get(0))))
460+
&& MapPaintStyles.getStyles().getStyleSources().contains(mapcss)) {
462461
MapPaintStyles.removeStyle(mapcss);
463462
}
464463
VectorDataSet data = this.getData();
@@ -631,7 +630,7 @@ private void selectedMapFeatureChanged(
631630
this.getData().setSelected(selection);
632631
}
633632
}
634-
if (ReflectionUtils.hasImageViewerDialog()) {
633+
if (ImageViewerDialog.hasInstance()) {
635634
if (ImageViewerDialog.getInstance().hasImage()) {
636635
IImageEntry<?> entry = ImageViewerDialog.getCurrentImage();
637636
if (entry instanceof MapillaryImageEntry) {

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/layer/geoimage/MapillaryImageEntry.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,20 @@ public INode getImage() {
572572
return this.image;
573573
}
574574

575+
@Override
576+
public int hashCode() {
577+
return Objects.hashCode(this.image);
578+
}
579+
580+
@Override
581+
public boolean equals(Object obj) {
582+
if (this.getClass().isInstance(obj)) {
583+
MapillaryImageEntry other = this.getClass().cast(obj);
584+
return Objects.equals(this.image, other.image);
585+
}
586+
return false;
587+
}
588+
575589
private void updateImageEntry() {
576590
// Clone this entry. Needed to ensure that the image display refreshes.
577591
final MapillaryImageEntry temporaryImageEntry = new MapillaryImageEntry(this);

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/workers/MapillaryNodeDownloader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public MapillaryNodeDownloader(INode node, Consumer<MapillaryNode> onFinish) {
4040
*/
4141
public MapillaryNodeDownloader(long id, Consumer<MapillaryNode> onFinish) {
4242
Objects.requireNonNull(onFinish);
43+
if (id <= 0) {
44+
throw new IllegalArgumentException("Mapillary Image ids must be positive");
45+
}
4346
downloadList.add(this);
4447
this.node = id;
4548
this.onFinish = onFinish;

0 commit comments

Comments
 (0)