Sync continuous download with JOSM download window

Signed-off-by: Taylor Smock <tsmock@meta.com>
pull/29/head
Taylor Smock 2023-07-20 15:22:22 -06:00
rodzic 390526525d
commit 21d43934d1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 233BB2E466604E27
2 zmienionych plików z 36 dodań i 22 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
import groovy.xml.XmlParser import groovy.xml.XmlParser
plugins { plugins {
id "com.diffplug.spotless" version "6.19.0" id "com.diffplug.spotless" version "6.20.0"
id "com.github.ben-manes.versions" version "0.47.0" id "com.github.ben-manes.versions" version "0.47.0"
id "com.github.spotbugs" version "5.0.14" id "com.github.spotbugs" version "5.0.14"
// id "de.aaschmid.cpd" version "3.3" // id "de.aaschmid.cpd" version "3.3"
@ -32,7 +32,7 @@ def versions = [
equalsverifier: "3.15", equalsverifier: "3.15",
errorprone: "2.20.0", errorprone: "2.20.0",
findsecbugs: "1.12.0", findsecbugs: "1.12.0",
jacoco: "0.8.7", jacoco: "0.8.10",
jmockit: "1.49.a", jmockit: "1.49.a",
josm: properties.get("plugin.compile.version"), josm: properties.get("plugin.compile.version"),
junit: "5.9.1", junit: "5.9.1",

Wyświetl plik

@ -16,6 +16,7 @@ import java.awt.Component;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
@ -55,6 +56,8 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.tools.BlacklistUtils; import org.openstreetmap.josm.plugins.mapwithai.tools.BlacklistUtils;
import org.openstreetmap.josm.plugins.mapwithai.tools.MapPaintUtils; import org.openstreetmap.josm.plugins.mapwithai.tools.MapPaintUtils;
import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
import org.openstreetmap.josm.tools.GBC; import org.openstreetmap.josm.tools.GBC;
import org.openstreetmap.josm.tools.ImageProvider; import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Utils; import org.openstreetmap.josm.tools.Utils;
@ -66,8 +69,8 @@ import org.openstreetmap.josm.tools.Utils;
* @author Taylor Smock * @author Taylor Smock
* *
*/ */
public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeListener { public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeListener, PreferenceChangedListener {
private static final Collection<String> COMPACT = Arrays.asList("esri"); private static final Collection<String> COMPACT = Collections.singleton("esri");
private Integer maximumAddition; private Integer maximumAddition;
private MapWithAIInfo url; private MapWithAIInfo url;
private Boolean switchLayers; private Boolean switchLayers;
@ -89,15 +92,15 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
lock = new MapLock(); lock = new MapLock();
MainApplication.getLayerManager().addActiveLayerChangeListener(this); MainApplication.getLayerManager().addActiveLayerChangeListener(this);
new ContinuousDownloadAction(this); // Initialize data source listeners new ContinuousDownloadAction(this); // Initialize data source listeners
Config.getPref().addKeyPreferenceChangeListener("download.mapwithai.data", this);
} }
@Override @Override
public String getChangesetSourceTag() { public String getChangesetSourceTag() {
if (MapWithAIDataUtils.getAddedObjects() > 0) { if (MapWithAIDataUtils.getAddedObjects() > 0) {
TreeSet<String> sources = new TreeSet<>( TreeSet<String> sources = MapWithAIDataUtils.getAddedObjectsSource().stream().filter(Objects::nonNull)
MapWithAIDataUtils.getAddedObjectsSource().stream().filter(Objects::nonNull)
.map(string -> COMPACT.stream().filter(string::contains).findAny().orElse(string)) .map(string -> COMPACT.stream().filter(string::contains).findAny().orElse(string))
.collect(Collectors.toSet())); .collect(Collectors.toCollection(TreeSet::new));
sources.add("MapWithAI"); sources.add("MapWithAI");
return String.join("; ", sources); return String.join("; ", sources);
} }
@ -131,18 +134,17 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
@Override @Override
public Object getInfoComponent() { public Object getInfoComponent() {
final Object p = super.getInfoComponent(); final Object p = super.getInfoComponent();
if (p instanceof JPanel) { if (p instanceof JPanel panel) {
final JPanel panel = (JPanel) p;
if (maximumAddition != null) { if (maximumAddition != null) {
panel.add(new JLabel(tr("Maximum Additions: {0}", maximumAddition), SwingConstants.HORIZONTAL), panel.add(new JLabel(tr("Maximum Additions: {0}", maximumAddition), SwingConstants.CENTER),
GBC.eop().insets(15, 0, 0, 0)); GBC.eop().insets(15, 0, 0, 0));
} }
if (url != null) { if (url != null) {
panel.add(new JLabel(tr("URL: {0}", url.getUrlExpanded()), SwingConstants.HORIZONTAL), panel.add(new JLabel(tr("URL: {0}", url.getUrlExpanded()), SwingConstants.CENTER),
GBC.eop().insets(15, 0, 0, 0)); GBC.eop().insets(15, 0, 0, 0));
} }
if (switchLayers != null) { if (switchLayers != null) {
panel.add(new JLabel(tr("Switch Layers: {0}", switchLayers), SwingConstants.HORIZONTAL), panel.add(new JLabel(tr("Switch Layers: {0}", switchLayers), SwingConstants.CENTER),
GBC.eop().insets(15, 0, 0, 0)); GBC.eop().insets(15, 0, 0, 0));
} }
} }
@ -154,7 +156,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
Collection<Class<? extends Action>> forbiddenActions = Arrays.asList(LayerSaveAction.class, Collection<Class<? extends Action>> forbiddenActions = Arrays.asList(LayerSaveAction.class,
LayerSaveAsAction.class, DuplicateAction.class, LayerGpxExportAction.class, LayerSaveAsAction.class, DuplicateAction.class, LayerGpxExportAction.class,
ConvertToGpxLayerAction.class); ConvertToGpxLayerAction.class);
final List<Action> actions = Arrays.asList(super.getMenuEntries()).stream() final List<Action> actions = Arrays.stream(super.getMenuEntries())
.filter(action -> forbiddenActions.stream().noneMatch(clazz -> clazz.isInstance(action))) .filter(action -> forbiddenActions.stream().noneMatch(clazz -> clazz.isInstance(action)))
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
if (actions.isEmpty()) { if (actions.isEmpty()) {
@ -169,7 +171,22 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
return lock; return lock;
} }
@Override
public void preferenceChanged(PreferenceChangeEvent e) {
if ("download.mapwithai.data".equals(e.getKey())) {
final Object value = e.getNewValue().getValue();
if (value instanceof Boolean bool) {
this.continuousDownload = bool;
} else if (value instanceof String str) {
this.continuousDownload = Boolean.parseBoolean(str);
} else {
this.continuousDownload = false;
}
}
}
private class MapLock extends ReentrantLock { private class MapLock extends ReentrantLock {
@Serial
private static final long serialVersionUID = 5441350396443132682L; private static final long serialVersionUID = 5441350396443132682L;
private boolean dataSetLocked; private boolean dataSetLocked;
@ -209,7 +226,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
private static boolean checkIfToggleLayer() { private static boolean checkIfToggleLayer() {
final List<String> keys = Config.getPref().getKeySet().parallelStream() final List<String> keys = Config.getPref().getKeySet().parallelStream()
.filter(string -> string.contains(MapWithAIPlugin.NAME) && string.contains("boolean:toggle_with_layer")) .filter(string -> string.contains(MapWithAIPlugin.NAME) && string.contains("boolean:toggle_with_layer"))
.collect(Collectors.toList()); .toList();
boolean toggle = false; boolean toggle = false;
if (keys.size() == 1) { if (keys.size() == 1) {
toggle = Config.getPref().getBoolean(keys.get(0), false); toggle = Config.getPref().getBoolean(keys.get(0), false);
@ -219,6 +236,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
@Override @Override
public synchronized void destroy() { public synchronized void destroy() {
Config.getPref().removeKeyPreferenceChangeListener("download.mapwithai.data", this);
super.destroy(); super.destroy();
MainApplication.getLayerManager().removeActiveLayerChangeListener(this); MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
} }
@ -295,13 +313,8 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
/** /**
* Compare OsmPrimitives in a custom manner * Compare OsmPrimitives in a custom manner
*/ */
private static class OsmComparator implements Comparator<OsmPrimitive>, Serializable { private record OsmComparator(
private static final long serialVersionUID = 594813918562412160L; Collection<OsmPrimitive> previousSelection) implements Comparator<OsmPrimitive>, Serializable {
final Collection<OsmPrimitive> previousSelection;
public OsmComparator(Collection<OsmPrimitive> previousSelection) {
this.previousSelection = previousSelection;
}
@Override @Override
public int compare(OsmPrimitive o1, OsmPrimitive o2) { public int compare(OsmPrimitive o1, OsmPrimitive o2) {
@ -338,6 +351,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis
* @author Taylor Smock * @author Taylor Smock
*/ */
public static class ContinuousDownloadAction extends AbstractAction implements LayerAction { public static class ContinuousDownloadAction extends AbstractAction implements LayerAction {
@Serial
private static final long serialVersionUID = -3528632887550700527L; private static final long serialVersionUID = -3528632887550700527L;
private final transient MapWithAILayer layer; private final transient MapWithAILayer layer;