From e06b824d98a2abf4419ba97567321927d22e8ab9 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Tue, 9 Jun 2020 09:40:54 -0600 Subject: [PATCH] Modify MapWithAIInfo to extend appropriate classes Signed-off-by: Taylor Smock --- gradle.properties | 4 +- .../data/mapwithai/MapWithAIInfo.java | 554 +++--------------- 2 files changed, 77 insertions(+), 481 deletions(-) diff --git a/gradle.properties b/gradle.properties index ce6620f..f90bf3c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ # The minimum JOSM version this plugin is compatible with (can be any numeric version -plugin.main.version = 16569 +plugin.main.version = 16584 # The JOSM version this plugin is currently compiled against # Please make sure this version is available at https://josm.openstreetmap.de/download # The special values "latest" and "tested" are also possible here, but not recommended. -plugin.compile.version = 16569 +plugin.compile.version = 16584 plugin.canloadatruntime = true plugin.author = Taylor Smock plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java index 6b9beba..5e502fa 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java @@ -4,10 +4,7 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai; import static org.openstreetmap.josm.tools.I18n.marktr; import static org.openstreetmap.josm.tools.I18n.tr; -import java.awt.Image; import java.io.StringReader; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.EnumMap; @@ -16,7 +13,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.TreeSet; import java.util.stream.Collectors; import javax.json.Json; @@ -25,27 +21,28 @@ import javax.json.JsonObject; import javax.json.stream.JsonParser; import javax.swing.ImageIcon; -import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; -import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; -import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo; import org.openstreetmap.josm.data.StructUtils.StructEntry; import org.openstreetmap.josm.data.imagery.ImageryInfo; import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; import org.openstreetmap.josm.data.imagery.Shape; +import org.openstreetmap.josm.data.sources.ISourceCategory; +import org.openstreetmap.josm.data.sources.ISourceType; +import org.openstreetmap.josm.data.sources.SourceInfo; +import org.openstreetmap.josm.data.sources.SourcePreferenceEntry; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry; import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.tools.CheckParameterUtil; import org.openstreetmap.josm.tools.ImageProvider; import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; import org.openstreetmap.josm.tools.Logging; -import org.openstreetmap.josm.tools.Utils; -public class MapWithAIInfo extends TileSourceInfo implements Comparable, Attributed { +public class MapWithAIInfo extends + SourceInfo { /** * Type of MapWithAI entry */ - public enum MapWithAIType { + public enum MapWithAIType implements ISourceType { FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER("esriFeatureServer"); private final String typeString; @@ -54,6 +51,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable { + public enum MapWithAICategory implements ISourceCategory { BUILDING("data/closedway", "buildings", marktr("Buildings")), HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")), @@ -88,14 +96,17 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable Collections.synchronizedMap(new EnumMap<>(MapWithAICategory.class))) @@ -128,65 +139,18 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable customHttpHeaders = Collections.emptyMap(); - /** category of the service */ - private MapWithAICategory category; - private MapWithAIType type; private JsonArray parameters; private Map replacementTags; private boolean conflate; @@ -203,50 +167,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable { @StructEntry String parameters; @StructEntry @@ -272,23 +193,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable 0) { - shapesString.append(';'); - } - shapesString.append(s.encodeAsString(",")); - } - if (shapesString.length() > 0) { - shapes = shapesString.toString(); - } - } conflate = i.conflate; conflationUrl = i.conflationUrl; } @@ -351,10 +242,10 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable localizedCountriesCache = new HashMap<>(); static { localizedCountriesCache.put("", tr("Worldwide")); } - @Override - public String toString() { - // Used in preferences filtering, so must be efficient - return new StringBuilder(name).append('[').append(countryCode) - // appending the localized country in toString() allows us to filter imagery - // preferences table with it! - .append("] ('").append(ImageryInfo.getLocalizedCountry(countryCode)).append(')').append(" - ") - .append(url).append(" - ").append(type).toString(); - } - - @Override - public int compareTo(MapWithAIInfo in) { - int i = countryCode.compareTo(in.countryCode); - if (i == 0) { - i = name.toLowerCase(Locale.ENGLISH).compareTo(in.name.toLowerCase(Locale.ENGLISH)); - } - if (i == 0) { - i = url.compareTo(in.url); - } - return i; - } - - public boolean equalsBaseValues(MapWithAIInfo in) { - return url.equals(in.url); - } - - private static String intern(String string) { - return string == null ? null : string.intern(); - } - - /** - * Sets the imagery polygonial bounds. - * - * @param b The imagery bounds (non-rectangular) - */ - public void setBounds(ImageryBounds b) { - this.bounds = b; - } - public void setCategory(MapWithAICategory category) { this.category = category; } @@ -561,228 +389,10 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable newAddedIds = new TreeSet<>( - Config.getPref().getList(MapWithAILayerInfo.CONFIG_PREFIX + "addedIds")); - newAddedIds.add(this.id); - Config.getPref().putList(MapWithAILayerInfo.CONFIG_PREFIX + "addedIds", new ArrayList<>(newAddedIds)); - } - setId(null); - } - public MapWithAICategory getCategory() { return category; } - public boolean isDefaultEntry() { - return defaultEntry; - } - - public void setDefaultEntry(boolean defaultEntry) { - this.defaultEntry = defaultEntry; - } - - public String getToolTipText() { - StringBuilder res = new StringBuilder(getName()); - boolean html = false; - if (category != null && category.getDescription() != null) { - res.append("
").append(tr("Imagery category: {0}", category.getDescription())); - html = true; - } - if (html) { - res.insert(0, "").append(""); - } - return res.toString(); - } - - public String getCountryCode() { - return countryCode; - } - - /** - * Returns custom HTTP headers that should be sent with request towards imagery - * provider - * - * @return headers - */ - public Map getCustomHttpHeaders() { - return customHttpHeaders; - } - - /** - * Sets custom HTTP headers that should be sent with request towards imagery - * provider - * - * @param customHttpHeaders http headers - */ - public void setCustomHttpHeaders(Map customHttpHeaders) { - this.customHttpHeaders = Utils.toUnmodifiableMap(customHttpHeaders); - } - public void setParameters(JsonArray parameters) { this.parameters = parameters; } @@ -845,7 +455,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable