pull/1/head
beata.tautan 2020-05-28 22:53:09 +03:00 zatwierdzone przez Taylor Smock
rodzic 50556cab86
commit 328f3b96b1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 66 dodań i 18 usunięć

Wyświetl plik

@ -3,12 +3,12 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
import static org.openstreetmap.josm.tools.I18n.marktr; import static org.openstreetmap.josm.tools.I18n.marktr;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import java.awt.Image; import java.awt.Image;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -17,13 +17,11 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.json.Json; import javax.json.Json;
import javax.json.JsonArray; import javax.json.JsonArray;
import javax.json.JsonObject; import javax.json.JsonObject;
import javax.json.stream.JsonParser; import javax.json.stream.JsonParser;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo; import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
@ -40,6 +38,7 @@ import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Utils; import org.openstreetmap.josm.tools.Utils;
public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithAIInfo>, Attributed { public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithAIInfo>, Attributed {
/** /**
* Type of MapWithAI entry * Type of MapWithAI entry
*/ */
@ -66,7 +65,8 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
} }
} }
public enum MapWithAICategory { public enum MapWithAICategory implements Comparable<MapWithAICategory> {
BUILDING("data/closedway", "buildings", marktr("Buildings")), BUILDING("data/closedway", "buildings", marktr("Buildings")),
HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")), HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")),
ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")), ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")),
@ -105,16 +105,26 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
return category; return category;
} }
} }
// Fuzzy match // fuzzy match
if (s != null && !s.trim().isEmpty()) { if (s != null && !s.trim().isEmpty()) {
s = s.toLowerCase();
for (MapWithAICategory type : MapWithAICategory.values()) { for (MapWithAICategory type : MapWithAICategory.values()) {
if (s.contains(type.getCategoryString()) || type.getCategoryString().contains(s)) { if (s.contains(type.getDescription().toLowerCase())
|| type.getDescription().toLowerCase().contains(s)) {
return type; return type;
} }
} }
} }
return null; return null;
} }
public static class DescriptionComparator implements Comparator<MapWithAICategory> {
@Override
public int compare(MapWithAICategory o1, MapWithAICategory o2) {
return (o1 == null || o2 == null) ? 1 : o1.getDescription().compareTo(o2.getDescription());
}
}
} }
/** /**
@ -191,6 +201,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
**/ **/
public static class MapWithAIPreferenceEntry { public static class MapWithAIPreferenceEntry {
@StructEntry @StructEntry
String name; String name;
@StructEntry @StructEntry
@ -313,6 +324,16 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
} }
} }
public static class MapWithAIInfoCategoryComparator implements Comparator<MapWithAIInfo> {
@Override
public int compare(MapWithAIInfo o1, MapWithAIInfo o2) {
return (Objects.nonNull(o1.getCategory()) || Objects.nonNull(o2.getCategory()) ? 1
: Objects.compare(o1.getCategory(), o2.getCategory(),
new MapWithAICategory.DescriptionComparator()));
}
}
public MapWithAIInfo() { public MapWithAIInfo() {
this((String) null); this((String) null);
} }
@ -529,6 +550,14 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
this.bounds = b; this.bounds = b;
} }
public void setCategory(MapWithAICategory category) {
this.category = category;
}
public void setDescription(String description) {
this.description = description;
}
/** /**
* Returns the imagery polygonial bounds. * Returns the imagery polygonial bounds.
* *
@ -876,5 +905,4 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
public void setConflationParameters(JsonArray parameters) { public void setConflationParameters(JsonArray parameters) {
this.conflationParameters = parameters; this.conflationParameters = parameters;
} }
} }

Wyświetl plik

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -19,15 +20,14 @@ import java.util.TreeSet;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.json.Json; import javax.json.Json;
import javax.json.JsonArray; import javax.json.JsonArray;
import javax.json.JsonNumber; import javax.json.JsonNumber;
import javax.json.JsonObject; import javax.json.JsonObject;
import javax.json.JsonReader; import javax.json.JsonReader;
import javax.json.JsonString;
import javax.json.JsonStructure; import javax.json.JsonStructure;
import javax.json.JsonValue; import javax.json.JsonValue;
import org.openstreetmap.josm.data.StructUtils; import org.openstreetmap.josm.data.StructUtils;
import org.openstreetmap.josm.data.imagery.ImageryInfo; import org.openstreetmap.josm.data.imagery.ImageryInfo;
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
@ -36,6 +36,7 @@ import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.io.CachedFile; import org.openstreetmap.josm.io.CachedFile;
import org.openstreetmap.josm.io.NetworkManager; import org.openstreetmap.josm.io.NetworkManager;
import org.openstreetmap.josm.io.imagery.ImageryReader; import org.openstreetmap.josm.io.imagery.ImageryReader;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry;
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.MapWithAISourceReader; import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.MapWithAISourceReader;
import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.spi.preferences.Config;
@ -216,8 +217,9 @@ public class MapWithAILayerInfo {
} }
} }
defaultLayerIds.clear(); defaultLayerIds.clear();
Collections.sort(defaultLayers);
Collections.sort(allDefaultLayers); Collections.sort(defaultLayers, new MapWithAIInfo.MapWithAIInfoCategoryComparator());
Collections.sort(allDefaultLayers, new MapWithAIInfo.MapWithAIInfoCategoryComparator());
buildIdMap(allDefaultLayers, defaultLayerIds); buildIdMap(allDefaultLayers, defaultLayerIds);
updateEntriesFromDefaults(!loadError); updateEntriesFromDefaults(!loadError);
buildIdMap(layers, layerIds); buildIdMap(layers, layerIds);
@ -282,8 +284,17 @@ public class MapWithAILayerInfo {
newInfo.setAttributionImageURL(url + "content/items/" + newInfo.getId() + "/info/" newInfo.setAttributionImageURL(url + "content/items/" + newInfo.getId() + "/info/"
+ feature.getString("thumbnail")); + feature.getString("thumbnail"));
} }
// TODO groupCategories // TODO: change this to streams
// TODO snippet/description MapWithAICategory category = null;
for (JsonString elem : feature.getJsonArray("groupCategories").getValuesAs(JsonString.class)) {
category = MapWithAICategory.fromString(elem.getString().replace("/Categories/", ""));
if (category != null) {
break;
}
}
newInfo.setCategory(category);
newInfo.setDescription(feature.getString("snippet"));
information.add(newInfo); information.add(newInfo);
} }
} }
@ -292,6 +303,16 @@ public class MapWithAILayerInfo {
next = "-1"; next = "-1";
} }
} }
Comparator<MapWithAIInfo> comparator = new Comparator<MapWithAIInfo>() {
@Override
public int compare(MapWithAIInfo o1, MapWithAIInfo o2) {
return o1.getCategory().getDescription().compareTo(o2.getCategory().getDescription());
}
};
if (information != null) {
information = information.stream().sorted(comparator).collect(Collectors.toSet());
}
return information; return information;
} }
@ -321,8 +342,8 @@ public class MapWithAILayerInfo {
JsonReader reader = Json.createReader(br)) { JsonReader reader = Json.createReader(br)) {
JsonObject info = reader.readObject(); JsonObject info = reader.readObject();
return info.getJsonArray("fields").getValuesAs(JsonObject.class).stream().collect(Collectors.toMap( return info.getJsonArray("fields").getValuesAs(JsonObject.class).stream()
o -> o.getString("name"), o -> o.getBoolean("editable", true) ? o.getString("alias", "") : "")); .collect(Collectors.toMap(o -> o.getString("name"), o -> o.getString("alias", null)));
} catch (IOException e) { } catch (IOException e) {
Logging.error(e); Logging.error(e);
} }
@ -569,6 +590,7 @@ public class MapWithAILayerInfo {
} }
public static interface FinishListener { public static interface FinishListener {
public void onFinish(); public void onFinish();
} }
} }

Wyświetl plik

@ -4,10 +4,8 @@ package org.openstreetmap.josm.plugins.mapwithai.gui.download;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.openstreetmap.josm.data.Bounds; import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.gui.bbox.JosmMapViewer; import org.openstreetmap.josm.gui.bbox.JosmMapViewer;
import org.openstreetmap.josm.gui.download.DownloadDialog; import org.openstreetmap.josm.gui.download.DownloadDialog;
@ -29,7 +27,7 @@ public class MapWithAIDownloadOptions extends JPanel implements DownloadSelectio
favorites.add(new JLabel("TODO: Favorites go here!")); // TODO favorites.add(new JLabel("TODO: Favorites go here!")); // TODO
optionPanel.add(favorites, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTH)); optionPanel.add(favorites, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTH));
mapwithaiProvidersPanel = new MapWithAIProvidersPanel(this, MapWithAILayerInfo.getInstance()); mapwithaiProvidersPanel = new MapWithAIProvidersPanel(this, MapWithAILayerInfo.getInstance());
optionPanel.add(mapwithaiProvidersPanel); optionPanel.add(mapwithaiProvidersPanel, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.CENTER));
} }
@Override @Override