Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Update to JOSM r18613
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Dec 13, 2022
1 parent 8d94846 commit 387f089
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ant-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
call-workflow:
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
with:
josm-revision: "r18531"
josm-revision: "r18613"


2 changes: 1 addition & 1 deletion .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
call-workflow:
strategy:
matrix:
josm-revision: ["", "r18531"]
josm-revision: ["", "r18613"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
with:
josm-revision: ${{ matrix.josm-revision }}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ josm {
debugPort = 7051
manifest {
// 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
oldVersionDownloadLink(18531, "v2.0.2", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.2/Mapillary.jar"));
oldVersionDownloadLink(17903, "v2.0.0-alpha.36", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.0-alpha.36/Mapillary.jar"))
}
i18n {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ plugin.icon=images/mapillary-logo.svg
plugin.link=https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Mapillary
# Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible.
# You can check if the plugin compiles against this version by executing `./gradlew compileJava_minJosm`.
plugin.main.version=18291
plugin.main.version=18613
# Version of JOSM against which the plugin is compiled
# Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ .
# If not, choose the next higher number that is available, or the gradle build will break.
plugin.compile.version=18531
plugin.compile.version=18613
# The datepicker plugin is currently in the source tree. TODO fix
plugin.requires=apache-commons

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import javax.swing.JMenu;
Expand All @@ -17,8 +16,6 @@
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
import org.openstreetmap.josm.gui.layer.Layer;
import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;
import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
import org.openstreetmap.josm.io.remotecontrol.RequestProcessor;
import org.openstreetmap.josm.plugins.Plugin;
Expand Down Expand Up @@ -156,7 +153,6 @@ public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {

this.dataMouseListener = new DataMouseListener();
this.destroyables.add(this.dataMouseListener);
ensureImageViewerDialogEnabled(newFrame);
} else if (oldFrame != null && newFrame == null) { // map frame removed
if (this.dataMouseListener != null) {
this.destroyables.remove(this.dataMouseListener);
Expand All @@ -173,20 +169,6 @@ public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
}
}

/**
* Ensure that the image viewer dialog is created
*
* @param map The mapframe that should have the ImageViewerDialog
*/
private static void ensureImageViewerDialogEnabled(MapFrame map) {
if (map != null && map.getToggleDialog(ImageViewerDialog.class) == null) {
// GeoImageLayer should do all the setup when hookUpMapView is called.
final GeoImageLayer geoImageLayer = new GeoImageLayer(Collections.emptyList(), null);
geoImageLayer.hookUpMapView();
geoImageLayer.destroy();
}
}

@Override
public PreferenceSetting getPreferenceSetting() {
return new MapillaryPreferenceSetting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.MouseInputAdapter;

import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.imagery.street_level.IImageEntry;
import org.openstreetmap.josm.data.osm.INode;
import org.openstreetmap.josm.data.osm.PrimitiveId;
import org.openstreetmap.josm.data.vector.VectorDataSet;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
import org.openstreetmap.josm.gui.layer.LayerManager;
import org.openstreetmap.josm.gui.layer.geoimage.IGeoImageLayer;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.plugins.mapillary.data.mapillary.ImageNavigation;
import org.openstreetmap.josm.plugins.mapillary.data.mapillary.MapillaryNode;
Expand All @@ -34,7 +36,7 @@
* Create a new image navigation dialog
*/
public class ImageNavigationDialog extends ToggleDialog
implements LayerManager.LayerChangeListener, BiConsumer<MapillaryLayer, MapillaryNode> {
implements LayerManager.LayerChangeListener, IGeoImageLayer.ImageChangeListener {
private static final Shortcut FORWARD = Shortcut.registerShortcut("mapillary:image_navigation:forward",
tr("Mapillary: Image Navigation: Forward"), Shortcut.NONE, KeyEvent.CHAR_UNDEFINED);
private static final Shortcut LEFT = Shortcut.registerShortcut("mapillary:image_navigation:left",
Expand Down Expand Up @@ -84,9 +86,17 @@ public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e) {
}

@Override
public void accept(MapillaryLayer layer, MapillaryNode node) {
if (node != null && layer != null && layer.getData() != null && node.getSequence() != null) {
this.imageNavigation = new ImageNavigation(layer.getData(), node);
public void imageChanged(IGeoImageLayer source, List<? extends IImageEntry<?>> oldImages,
List<? extends IImageEntry<?>> newImages) {
if (source instanceof MapillaryLayer
&& newImages.stream().filter(MapillaryNode.class::isInstance).count() == 1) {
MapillaryLayer layer = (MapillaryLayer) source;
MapillaryNode node = (MapillaryNode) newImages.get(0);
if (node != null && layer.getData() != null && node.getSequence() != null) {
this.imageNavigation = new ImageNavigation(layer.getData(), node);
} else {
this.imageNavigation = null;
}
} else {
this.imageNavigation = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.dialog;

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

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Optional;

import javax.annotation.Nullable;
import javax.json.Json;
Expand Down Expand Up @@ -74,7 +76,8 @@ static String latestMapillaryVersion() {
latestMapillary.setMaxAge(60L * 15); // 15 minutes
final JsonValue value = reader.read();
final JsonObject object = value.asJsonObject();
return object.getString("tag_name", null);
return Optional.ofNullable(object.getString("tag_name", null)).map(s -> s.replaceFirst("^v", ""))
.orElse(null);
} catch (IOException | JsonException | IllegalStateException e) {
Logging.error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
Expand All @@ -30,7 +31,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Lock;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -73,6 +73,7 @@
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.gui.layer.geoimage.IGeoImageLayer;
import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;
import org.openstreetmap.josm.gui.layer.imagery.MVTLayer;
import org.openstreetmap.josm.gui.mappaint.Range;
Expand All @@ -96,7 +97,6 @@
import org.openstreetmap.josm.plugins.mapillary.utils.MapillarySequenceUtils;
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
import org.openstreetmap.josm.plugins.mapillary.utils.OffsetUtils;
import org.openstreetmap.josm.plugins.mapillary.utils.ReflectionUtils;
import org.openstreetmap.josm.tools.ColorHelper;
import org.openstreetmap.josm.tools.Geometry;
import org.openstreetmap.josm.tools.I18n;
Expand All @@ -113,8 +113,9 @@
*
* @author nokutu
*/
public final class MapillaryLayer extends MVTLayer implements ActiveLayerChangeListener, LayerChangeListener,
UploadHook, VectorDataSelectionListener, AbstractProperty.ValueChangeListener<Boolean>, HighlightUpdateListener {
public final class MapillaryLayer extends MVTLayer
implements ActiveLayerChangeListener, LayerChangeListener, UploadHook, VectorDataSelectionListener,
AbstractProperty.ValueChangeListener<Boolean>, HighlightUpdateListener, IGeoImageLayer {

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

Expand All @@ -176,6 +177,9 @@ private MapillaryLayer() {
this.getData().addHighlightUpdateListener(this);
this.colorByCaptureDate = MapillaryProperties.COLOR_BY_CAPTURE_DATE.get();
MapillaryProperties.COLOR_BY_CAPTURE_DATE.addListener(this);
if (!GraphicsEnvironment.isHeadless() && !ImageViewerDialog.hasInstance()) {
ImageViewerDialog.getInstance();
}
}

/**
Expand Down Expand Up @@ -732,32 +736,31 @@ public void setCurrentImage(final MapillaryNode image) {
}
this.image = image;
this.invalidate();
if (ReflectionUtils.hasImageViewerDialog()) {
if (ImageViewerDialog.hasInstance()) {
if (image == null) {
GuiHelper.runInEDT(() -> ImageViewerDialog.getInstance().displayImage(null));
} else {
MapillaryImageEntry entry = MapillaryImageEntry.getCachedEntry(image);
if (Objects.equals(entry, ImageViewerDialog.getCurrentImage())) {
entry.reload();
} else {
IImageEntry<?> old = ImageViewerDialog.getCurrentImage();
GuiHelper.runInEDT(() -> ImageViewerDialog.getInstance().displayImage(entry));
MainApplication.worker.execute(() -> this.imageChangeListeners.fireEvent(f -> f.imageChanged(this,
old instanceof MapillaryImageEntry ? Collections.singletonList(old) : Collections.emptyList(),
Collections.singletonList(entry))));
}
}
}
MainApplication.worker.execute(() -> this.imageChangeListeners.fireEvent(f -> f.accept(this, image)));
}

public MapillaryNode getImage() {
return this.image;
}

/**
* Add an image change listener
* Get the currently visible image
*
* @param listener The listener to notify of image changes
* @return The image node
*/
public void addImageChangeListener(BiConsumer<MapillaryLayer, MapillaryNode> listener) {
this.imageChangeListeners.addWeakListener(listener);
public MapillaryNode getImage() {
return this.image;
}

@Override
Expand All @@ -766,8 +769,7 @@ public void selectionChanged(
final Collection<VectorNode> nodes = Utils.filteredCollection(event.getSelection(), VectorNode.class);
if (nodes.size() == 1) {
final VectorNode node = nodes.iterator().next();
final IImageEntry<?> displayImage = ReflectionUtils.hasImageViewerDialog()
? ImageViewerDialog.getCurrentImage()
final IImageEntry<?> displayImage = ImageViewerDialog.hasInstance() ? ImageViewerDialog.getCurrentImage()
: null;
final MapillaryNode currentImage = this.image;
if (currentImage != null && displayImage instanceof MapillaryImageEntry
Expand Down Expand Up @@ -818,4 +820,44 @@ public void valueChanged(AbstractProperty.ValueChangeEvent<? extends Boolean> e)
this.colorByCaptureDate = MapillaryProperties.COLOR_BY_CAPTURE_DATE.get();
}
}

@Override
public void clearSelection() {
this.setCurrentImage(null);
}

@Override
public List<? extends IImageEntry<?>> getSelection() {
if (this.image instanceof IImageEntry) {
return Collections.singletonList((IImageEntry<?>) this.image);
} else if (this.image != null) {
return Collections.singletonList(MapillaryImageEntry.getCachedEntry(this.image));
}
return Collections.emptyList();
}

@Override
public boolean containsImage(IImageEntry<?> imageEntry) {
if (!(imageEntry instanceof MapillaryImageEntry)) {
return false;
}
MapillaryImageEntry entry = (MapillaryImageEntry) imageEntry;
if (Objects.equals(entry.getImage(), this.image)) {
return true;
}
if (entry.getImage() instanceof VectorNode) {
return this.getData().containsNode((VectorNode) entry.getImage());
}
return this.getData().getPrimitiveById(entry.getImage().getPrimitiveId()) != null;
}

@Override
public void addImageChangeListener(ImageChangeListener listener) {
this.imageChangeListeners.addListener(listener);
}

@Override
public void removeImageChangeListener(ImageChangeListener listener) {
this.imageChangeListeners.removeListener(listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryKeys;
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryMapFeatureUtils;
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryProperties;
import org.openstreetmap.josm.plugins.mapillary.utils.ReflectionUtils;
import org.openstreetmap.josm.tools.GBC;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
Expand Down Expand Up @@ -308,7 +307,7 @@ private void paintAdditionalPanel(VectorPrimitive mapillaryObject, final MapView
removeButton.setToolTipText(removeAction.getToolTip());
addButton.setAction(addAction);
removeButton.setAction(removeAction);
displayedPanel = new AdditionalActionPanel(addButton/*, removeButton*/);
displayedPanel = new AdditionalActionPanel(addButton/* , removeButton */);
pTooltip = fixPanelSizeAndLocation(mv, displayedPanel, xl, xr, yt, yb);
displayedWindow.setAutoRequestFocus(false);
displayedWindow.add(displayedPanel);
Expand Down Expand Up @@ -457,8 +456,8 @@ public synchronized void destroy() {
super.destroy();
MainApplication.getMap().filterDialog.getFilterModel().removeTableModelListener(tableModelListener);
List<? extends PointObjectLayer> layers = MainApplication.getLayerManager().getLayersOfType(this.getClass());
if ((layers.isEmpty() || (layers.size() == 1 && this.equals(layers.get(0)))) &&
MapPaintStyles.getStyles().getStyleSources().contains(mapcss)) {
if ((layers.isEmpty() || (layers.size() == 1 && this.equals(layers.get(0))))
&& MapPaintStyles.getStyles().getStyleSources().contains(mapcss)) {
MapPaintStyles.removeStyle(mapcss);
}
VectorDataSet data = this.getData();
Expand Down Expand Up @@ -631,7 +630,7 @@ private void selectedMapFeatureChanged(
this.getData().setSelected(selection);
}
}
if (ReflectionUtils.hasImageViewerDialog()) {
if (ImageViewerDialog.hasInstance()) {
if (ImageViewerDialog.getInstance().hasImage()) {
IImageEntry<?> entry = ImageViewerDialog.getCurrentImage();
if (entry instanceof MapillaryImageEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,20 @@ public INode getImage() {
return this.image;
}

@Override
public int hashCode() {
return Objects.hashCode(this.image);
}

@Override
public boolean equals(Object obj) {
if (this.getClass().isInstance(obj)) {
MapillaryImageEntry other = this.getClass().cast(obj);
return Objects.equals(this.image, other.image);
}
return false;
}

private void updateImageEntry() {
// Clone this entry. Needed to ensure that the image display refreshes.
final MapillaryImageEntry temporaryImageEntry = new MapillaryImageEntry(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public MapillaryNodeDownloader(INode node, Consumer<MapillaryNode> onFinish) {
*/
public MapillaryNodeDownloader(long id, Consumer<MapillaryNode> onFinish) {
Objects.requireNonNull(onFinish);
if (id <= 0) {
throw new IllegalArgumentException("Mapillary Image ids must be positive");
}
downloadList.add(this);
this.node = id;
this.onFinish = onFinish;
Expand Down
Loading

0 comments on commit 387f089

Please sign in to comment.